Index: .settings/org.eclipse.jdt.core.prefs =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.performance/.settings/org.eclipse.jdt.core.prefs,v retrieving revision 1.7 diff -u -r1.7 org.eclipse.jdt.core.prefs --- .settings/org.eclipse.jdt.core.prefs 18 May 2005 21:32:40 -0000 1.7 +++ .settings/org.eclipse.jdt.core.prefs 5 Aug 2005 15:18:05 -0000 @@ -1,4 +1,4 @@ -#Wed May 18 23:25:13 CEST 2005 +#Fri Aug 05 14:45:22 CEST 2005 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -32,7 +32,7 @@ org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled -org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning Index: src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java,v retrieving revision 1.13 diff -u -r1.13 AllPerformanceTests.java --- src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java 9 May 2005 15:38:43 -0000 1.13 +++ src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java 5 Aug 2005 15:18:05 -0000 @@ -33,7 +33,8 @@ FullSourceWorkspaceBuildTests.class, FullSourceWorkspaceASTTests.class, FullSourceWorkspaceTypeHierarchyTests.class, - NameLookupTests2.class + FullSourceWorkspaceCompletionTests.class, + FullSourceWorkspaceModelTests.class }; } @@ -58,7 +59,6 @@ */ public static Class[] getAdditionalTestClasses() { return new Class[] { - FullSourceWorkspaceCompletionTests.class }; } Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java,v retrieving revision 1.18 diff -u -r1.18 FullSourceWorkspaceTests.java --- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 9 May 2005 15:38:43 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 5 Aug 2005 15:18:06 -0000 @@ -30,6 +30,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.search.indexing.IndexManager; import org.eclipse.jdt.internal.core.search.processing.IJob; import org.eclipse.test.performance.Dimension; @@ -51,6 +52,8 @@ // Workspace variables protected static TestingEnvironment ENV = null; protected static IJavaProject[] ALL_PROJECTS; + protected static IJavaProject JDT_CORE_PROJECT; + // Index variables protected static IndexManager INDEX_MANAGER = JavaModelManager.getJavaModelManager().getIndexManager(); @@ -68,6 +71,10 @@ StringBuffer scenarioComment; static Map SCENARII_COMMENT = new HashMap(); + // Project + final static String BIG_PROJECT_NAME = "BigProject"; + static JavaProject BIG_PROJECT; + /** * Variable used for log files. * Log files are used in conjonction with {@link JdtCorePerformanceMeter} class. @@ -208,7 +215,7 @@ free = Runtime.getRuntime().freeMemory(); System.gc(); delta = Runtime.getRuntime().freeMemory() - free; - if (DEBUG) System.out.println("Loop gc "+ ++iterations + " (free="+free+", delta="+delta+")"); +// if (DEBUG) System.out.println("Loop gc "+ ++iterations + " (free="+free+", delta="+delta+")"); try { Thread.sleep(TIME_GC); } catch (InterruptedException e) { @@ -353,6 +360,12 @@ // Increment test position TEST_POSITION++; + + // Print test name while debugging + if (DEBUG) { + System.out.println("--------------------------------------------------------------------------------"); + System.out.println("Running "+getName()+"..."); + } } /** * @deprecated Use {@link #tagAsGlobalSummary(String,Dimension,boolean)} instead @@ -462,6 +475,12 @@ ALL_PROJECTS = JavaCore.create(workspaceRoot).getJavaProjects(); int length = ALL_PROJECTS.length; for (int i = 0; i < length; i++) { + String projectName = ALL_PROJECTS[i].getElementName(); + if (JavaCore.PLUGIN_ID.equals(projectName)) { + JDT_CORE_PROJECT = ALL_PROJECTS[i]; + } else if (BIG_PROJECT_NAME.equals(projectName)) { + BIG_PROJECT = (JavaProject) ALL_PROJECTS[i]; + } ALL_PROJECTS[i].setRawClasspath(ALL_PROJECTS[i].getRawClasspath(), null); } if (DEBUG) System.out.println("done!"); Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java =================================================================== RCS file: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java diff -N src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,425 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.performance; + +import java.io.ByteArrayInputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.*; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.*; +import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.search.*; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.IJavaElementRequestor; +import org.eclipse.jdt.internal.core.JavaElement; +import org.eclipse.jdt.internal.core.JavaProject; +import org.eclipse.jdt.internal.core.NameLookup; + +/** + */ +public class FullSourceWorkspaceModelTests extends FullSourceWorkspaceTests implements IJavaSearchConstants { + + // Tests counters + private static int TESTS_COUNT = 0; + private final static int ITERATIONS_COUNT = 200; + private final static int LINUX_FOLDERS_COUNT = 200; + private final static int FOLDERS_COUNT = 100; + private final static int LINUX_PACKAGES_COUNT = 200; + private final static int PACKAGES_COUNT = 20; + + // Log file streams + private static PrintStream[] LOG_STREAMS = new PrintStream[LOG_TYPES.length]; + + // Search variables + IJavaSearchScope scope; + protected JavaSearchResultCollector resultCollector; + + // Type path + static IPath BIG_PROJECT_TYPE_PATH; + + /** + * @param name + */ + public FullSourceWorkspaceModelTests(String name) { + super(name); + } + + static { +// org.eclipse.jdt.internal.core.NameLookup.VERBOSE = true; +// TESTS_NAMES = new String[] { "testPerfSeekPackageFragments" }; + } + public static Test suite() { + Test suite = buildSuite(testClass()); + TESTS_COUNT = suite.countTestCases(); + createPrintStream(testClass().getName(), LOG_STREAMS, TESTS_COUNT, null); + return suite; + } + + private static Class testClass() { + return FullSourceWorkspaceModelTests.class; + } + + protected void setUp() throws Exception { + super.setUp(); + this.resultCollector = new JavaSearchResultCollector(); + this.scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { JDT_CORE_PROJECT }); + if (BIG_PROJECT == null) { + setUpBigProject(); + } + } + private void setUpBigProject() throws CoreException { + try { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot workspaceRoot = workspace.getRoot(); + long start = System.currentTimeMillis(); + boolean linux = "linux".equals(System.getProperty("osgi.os", "?")); + // setup projects with several source folders and several packages per source folder + final int rootLength = linux ? LINUX_FOLDERS_COUNT : FOLDERS_COUNT; + final String[] sourceFolders = new String[rootLength]; + for (int i = 0; i < rootLength; i++) { + sourceFolders[i] = "src" + i; + } + String path = workspaceRoot.getLocation().toString() + "/BigProject/src"; + int packLength = linux ? LINUX_PACKAGES_COUNT : PACKAGES_COUNT; + for (int i = 0; i < rootLength; i++) { + for (int j = 0; j < packLength; j++) { + new java.io.File(path + i + "/org/eclipse/jdt/core/tests" + i + "/performance" + j).mkdirs(); + } + } + ENV.addProject(BIG_PROJECT_NAME); + BIG_PROJECT = (JavaProject) createJavaProject("BigProject", sourceFolders, "bin", "1.4"); + if (DEBUG) { + System.out.println("Time to create big project = "+(System.currentTimeMillis()-start)); + } + BIG_PROJECT_TYPE_PATH = new Path("/BigProject/src" + (rootLength-1) + "/org/eclipse/jdt/core/tests" + (rootLength-1) + "/performance" + (packLength-1) + "/TestBigProject.java"); + IFile file = workspaceRoot.getFile(BIG_PROJECT_TYPE_PATH); + String content = "package org.eclipse.jdt.core.tests" + (rootLength-1) + ".performance" + (packLength-1) + ";\n" + + "public class TestBigProject {}\n"; + file.create(new ByteArrayInputStream(content.getBytes()), true, null); + } finally { + // do not delete project + } + + } + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + + // End of execution => one test less + TESTS_COUNT--; + + // Log perf result + if (LOG_DIR != null) { + logPerfResult(LOG_STREAMS, TESTS_COUNT); + } + + // Print statistics + if (TESTS_COUNT == 0) { +// System.out.println("-------------------------------------"); +// System.out.println("Search performance test statistics:"); +// NumberFormat intFormat = NumberFormat.getIntegerInstance(); +// System.out.println(" - "+intFormat.format(REFERENCES[0])+" type references found."); +// System.out.println(" - "+intFormat.format(REFERENCES[1])+" field references found."); +// System.out.println(" - "+intFormat.format(REFERENCES[2])+" method references found."); +// System.out.println(" - "+intFormat.format(REFERENCES[3])+" constructor references found."); +// System.out.println(" - "+intFormat.format(ALL_TYPES_NAMES)+" all types names."); +// System.out.println("-------------------------------------\n"); + } + super.tearDown(); + } + /** + * Simple search result collector: only count matches. + */ + class JavaSearchResultCollector extends SearchRequestor { + int count = 0; + public void acceptSearchMatch(SearchMatch match) throws CoreException { + this.count++; + } + } + + protected void search(String patternString, int searchFor, int limitTo) throws CoreException { + int matchMode = patternString.indexOf('*') != -1 || patternString.indexOf('?') != -1 + ? SearchPattern.R_PATTERN_MATCH + : SearchPattern.R_EXACT_MATCH; + SearchPattern pattern = SearchPattern.createPattern( + patternString, + searchFor, + limitTo, + matchMode | SearchPattern.R_CASE_SENSITIVE); + new SearchEngine().search( + pattern, + new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + this.scope, + this.resultCollector, + null); + } + + /** + * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#assertElementEquals(String, String, IJavaElement) + */ + protected void assertElementEquals(String message, String expected, IJavaElement element) { + String actual = element == null ? "" : ((JavaElement) element).toStringWithAncestors(false/*don't show key*/); + if (!expected.equals(actual)) { + System.out.println(getName()+" actual result is:"); + System.out.println(actual + ','); + } + assertEquals(message, expected, actual); + } + /** + * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#assertElementsEqual(String, String, IJavaElement[]) + */ + protected void assertElementsEqual(String message, String expected, IJavaElement[] elements) { + assertElementsEqual(message, expected, elements, false/*don't show key*/); + } + /** + * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#assertElementsEqual(String, String, IJavaElement[], boolean) + */ + protected void assertElementsEqual(String message, String expected, IJavaElement[] elements, boolean showResolvedInfo) { + StringBuffer buffer = new StringBuffer(); + if (elements != null) { + for (int i = 0, length = elements.length; i < length; i++){ + JavaElement element = (JavaElement)elements[i]; + if (element == null) { + buffer.append(""); + } else { + buffer.append(element.toStringWithAncestors(showResolvedInfo)); + } + if (i != length-1) buffer.append("\n"); + } + } else { + buffer.append(""); + } + String actual = buffer.toString(); + if (!expected.equals(actual)) { + System.out.println(getName()+" actual result is:"); + System.out.println(actual + ','); + } + assertEquals(message, expected, actual); + } + + /** + * Clean last category table cache + * @param type Tells whether previous search was a type search or not + */ + protected void cleanCategoryTableCache(boolean type) throws CoreException { + long time = System.currentTimeMillis(); + if (type) { + search("foo", FIELD, DECLARATIONS); + } else { + search("Foo", TYPE, DECLARATIONS); + } +// if (DEBUG) System.out.println("Time to clean category table cache: "+(System.currentTimeMillis()-time)); + } + + /** + * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#createJavaProject(String, String[], String[], String[][], String[][], String[], String[][], String[][], boolean[], String, String[], String[][], String[][], String) + */ + protected IJavaProject createJavaProject(final String projectName, final String[] sourceFolders, final String projectOutput, final String compliance) throws CoreException { + final IJavaProject[] result = new IJavaProject[1]; + IWorkspaceRunnable create = new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + + // create classpath entries + IProject project = ENV.getProject(projectName); + IPath projectPath = project.getFullPath(); + int sourceLength = sourceFolders == null ? 0 : sourceFolders.length; + IClasspathEntry[] entries = new IClasspathEntry[sourceLength]; + for (int i= 0; i < sourceLength; i++) { + IPath sourcePath = new Path(sourceFolders[i]); + int segmentCount = sourcePath.segmentCount(); + if (segmentCount > 0) { + // create folder and its parents + IContainer container = project; + for (int j = 0; j < segmentCount; j++) { + IFolder folder = container.getFolder(new Path(sourcePath.segment(j))); + if (!folder.exists()) { + folder.create(true, true, null); + } + container = folder; + } + } + // create source entry + entries[i] = + JavaCore.newSourceEntry( + projectPath.append(sourcePath), + new IPath[0], + new IPath[0], + null + ); + } + + // create project's output folder + IPath outputPath = new Path(projectOutput); + if (outputPath.segmentCount() > 0) { + IFolder output = project.getFolder(outputPath); + if (!output.exists()) { + output.create(true, true, null); + } + } + + // set classpath and output location + IJavaProject javaProject = ENV.getJavaProject(projectName); + javaProject.setRawClasspath(entries, projectPath.append(outputPath), null); + + // set compliance level options + if ("1.5".equals(compliance)) { + Map options = new HashMap(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + javaProject.setOptions(options); + } + + result[0] = javaProject; + } + }; + ResourcesPlugin.getWorkspace().run(create, null); + return result[0]; + } + private NameLookup getNameLookup(JavaProject project) throws JavaModelException { + return project.newNameLookup((WorkingCopyOwner)null); + } + + /** + * Performance tests for model: Find Unknown type. + * + * First wait that already started indexing jobs end before perform test. + * Perform one search before measure performance for warm-up. + */ + public void testProjectFindType() throws CoreException { + tagAsSummary("Model>Find Type", true); // put in fingerprint + + // Wait for indexing end + waitUntilIndexesReady(); + + // Warm up + String fullQualifiedName = BIG_PROJECT_TYPE_PATH.removeFileExtension().removeFirstSegments(2).toString(); + fullQualifiedName = fullQualifiedName.replace('/', '.'); + IType type = BIG_PROJECT.findType(fullQualifiedName); + assertNotNull("We should find "+BIG_PROJECT_NAME+" type!", type); + + // Clean memory + runGc(); + + // Measures + int iterations = 30; + for (int i=0; iFind Unknown Type", true); // put in fingerprint + + // Wait for indexing end + waitUntilIndexesReady(); + + // Warm up20 + IType type = BIG_PROJECT.findType("org.eclipse.jdt.core.tests10.performance10.Unknown"); + assertNull("We should not find an unknown type!", type); + + // Clean memory + runGc(); + + // Measures + int iterations = 10; + for (int i=0; i