Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 64230 Details for
Bug 179685
JREContainerInitializer average initialization time
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
further work in progress
179685.patch (text/plain), 14.83 KB, created by
Michael Rennie
on 2007-04-18 16:31:26 EDT
(
hide
)
Description:
further work in progress
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2007-04-18 16:31:26 EDT
Size:
14.83 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.launching >Index: launching/org/eclipse/jdt/internal/launching/JREContainer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainer.java,v >retrieving revision 1.24 >diff -u -r1.24 JREContainer.java >--- launching/org/eclipse/jdt/internal/launching/JREContainer.java 13 Dec 2006 21:46:12 -0000 1.24 >+++ launching/org/eclipse/jdt/internal/launching/JREContainer.java 18 Apr 2007 20:25:46 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 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 >@@ -14,6 +14,7 @@ > import java.net.URL; > import java.util.ArrayList; > import java.util.HashMap; >+import java.util.Iterator; > import java.util.List; > import java.util.Map; > >@@ -59,30 +60,181 @@ > */ > private static Map fgClasspathEntries = new HashMap(10); > >+ /** >+ * Variable to return an empty array of <code>IAccessRule</code>s >+ */ > private static IAccessRule[] EMPTY_RULES = new IAccessRule[0]; > > // debug flags > public static boolean DEBUG_JRE_CONTAINER = false; > > /** >+ * Map of {IVMInstall -> Map of {{IExeuctionEnvironment, IAccessRule[][]} -> {IClasspathEntry[]}} >+ */ >+ private static Map fgClasspathEntriesWithRules = new HashMap(10); >+ >+ /** >+ * A single key entry for the cache of access rules and classpath entries >+ * A rule key is made up of an <code>IVMInstall</code> and an execution environment id >+ * @since 3.3 >+ */ >+ static class RuleKey { >+ private String fEnvironmentId = null; >+ private IVMInstall fInstall = null; >+ >+ /** >+ * Constructor >+ * @param install >+ * @param environmentId >+ */ >+ public RuleKey(IVMInstall install, String environmentId) { >+ fInstall = install; >+ fEnvironmentId = environmentId; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+ public boolean equals(Object obj) { >+ if (obj instanceof RuleKey) { >+ RuleKey key = (RuleKey) obj; >+ return fEnvironmentId.equals(key.fEnvironmentId) && fInstall.equals(key.fInstall); >+ } >+ return false; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#hashCode() >+ */ >+ public int hashCode() { >+ return fEnvironmentId.hashCode() + fInstall.hashCode(); >+ } >+ } >+ >+ /** >+ * Holds an entry for the cache of access rules/classpath entries. >+ * An entry is made up of an array of classpath entries and the collection of access rules. >+ * @since 3.3 >+ */ >+ static class RuleEntry { >+ private IAccessRule[][] fRules = null; >+ private IClasspathEntry[] fEntries = null; >+ >+ /** >+ * Constructor >+ * @param rules >+ * @param entries >+ */ >+ public RuleEntry(IAccessRule[][] rules, IClasspathEntry[] entries) { >+ fRules = rules; >+ fEntries = entries; >+ } >+ >+ /** >+ * Returns the collection oof classpath entries for this RuleEntry >+ * @return the cached aray of classpath entries >+ */ >+ public IClasspathEntry[] getClasspathEntries() { >+ return fEntries; >+ } >+ >+ /* (non-Javadoc) >+ * @see java.lang.Object#equals(java.lang.Object) >+ */ >+ public boolean equals(Object obj) { >+ IAccessRule[][] rules = null; >+ if(obj instanceof RuleEntry) { >+ rules = ((RuleEntry)obj).fRules; >+ } >+ if(obj instanceof IAccessRule[][]) { >+ rules = (IAccessRule[][]) obj; >+ } >+ if(rules != null) { >+ if (fRules == rules) { >+ return true; >+ } >+ if (fRules.length == rules.length) { >+ boolean equal = true; >+ IAccessRule[] originalrule, comparerule = null; >+ for (int i = 0; i < fRules.length; i++) { >+ originalrule = fRules[i]; >+ comparerule = rules[i]; >+ equal &= (originalrule == comparerule); >+ if(!equal) { >+ if (originalrule.length == comparerule.length) { >+ for (int j = 0; j < originalrule.length; j++) { >+ if (!originalrule[j].equals(comparerule[j])) { >+ return false; >+ } >+ } >+ return true; >+ } >+ else { >+ return false; >+ } >+ } >+ } >+ return equal; >+ } >+ } >+ return false; >+ } >+ } >+ >+ /** > * Add a vm changed listener to clear cached values when a VM changes or is removed > */ > static { > IVMInstallChangedListener listener = new IVMInstallChangedListener() { >- public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) { >- } > >+ /* (non-Javadoc) >+ * @see org.eclipse.jdt.launching.IVMInstallChangedListener#defaultVMInstallChanged(org.eclipse.jdt.launching.IVMInstall, org.eclipse.jdt.launching.IVMInstall) >+ */ >+ public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {} >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jdt.launching.IVMInstallChangedListener#vmAdded(org.eclipse.jdt.launching.IVMInstall) >+ */ >+ public void vmAdded(IVMInstall newVm) {} >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jdt.launching.IVMInstallChangedListener#vmChanged(org.eclipse.jdt.launching.PropertyChangeEvent) >+ */ > public void vmChanged(PropertyChangeEvent event) { > if (event.getSource() != null) { > fgClasspathEntries.remove(event.getSource()); >+ removeRuleEntry(event.getSource()); > } > } > >- public void vmAdded(IVMInstall newVm) { >- } >- >+ /* (non-Javadoc) >+ * @see org.eclipse.jdt.launching.IVMInstallChangedListener#vmRemoved(org.eclipse.jdt.launching.IVMInstall) >+ */ > public void vmRemoved(IVMInstall removedVm) { > fgClasspathEntries.remove(removedVm); >+ removeRuleEntry(removedVm); >+ } >+ >+ /** >+ * Removes all occurances of the given vm found as part key members in the current >+ * cache for classpath entries >+ * @param obj an object which should be castable to IVMInstall >+ */ >+ private void removeRuleEntry(Object obj) { >+ if(obj instanceof IVMInstall) { >+ IVMInstall install = (IVMInstall) obj; >+ RuleKey key = null; >+ ArrayList list = new ArrayList(); >+ for(Iterator iter = fgClasspathEntriesWithRules.keySet().iterator(); iter.hasNext();) { >+ key = (RuleKey) iter.next(); >+ if(key.fInstall.equals(install)) { >+ list.add(key); >+ } >+ } >+ for(int i = 0; i < list.size(); i++) { >+ fgClasspathEntriesWithRules.remove(list.get(i)); >+ } >+ } > } > }; > JavaRuntime.addVMInstallChangedListener(listener); >@@ -149,6 +301,14 @@ > rules = environment.getAccessRules(vm, libs, project); > } > } >+ RuleKey key = null; >+ if (vm != null && rules != null && environmentId != null) { >+ key = new RuleKey(vm, environmentId); >+ RuleEntry entry = (RuleEntry) fgClasspathEntriesWithRules.get(key); >+ if(entry != null && entry.equals(rules)) { >+ return entry.getClasspathEntries(); >+ } >+ } > List entries = new ArrayList(libs.length); > for (int i = 0; i < libs.length; i++) { > if (!libs[i].getSystemLibraryPath().isEmpty()) { >@@ -179,9 +339,13 @@ > entries.add(JavaCore.newLibraryEntry(libs[i].getSystemLibraryPath(), sourcePath, rootPath, libRules, attributes, false)); > } > } >- return (IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]); >+ IClasspathEntry[] cpEntries = (IClasspathEntry[])entries.toArray(new IClasspathEntry[entries.size()]); >+ if (key != null && rules != null) { >+ fgClasspathEntriesWithRules.put(key, new RuleEntry(rules, cpEntries)); >+ } >+ return cpEntries; > } >- >+ > /** > * Constructs a JRE classpath container on the given VM install > * >@@ -207,9 +371,6 @@ > IClasspathEntry[] entries = getClasspathEntries(fVMInstall, getPath(), fProject); > if (DEBUG_JRE_CONTAINER) { > System.out.println("\tResolved " + entries.length + " entries:"); //$NON-NLS-1$//$NON-NLS-2$ >-// for (int i = 0; i < entries.length; i++) { >-// System.out.println("\t\t" + entries[i].getPath().toString() + " +[" + entries[i].getAccessRules().length + " access rules]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >-// } > } > return entries; > } >Index: launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java,v >retrieving revision 1.10 >diff -u -r1.10 ExecutionEnvironment.java >--- launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java 1 Dec 2006 16:37:42 -0000 1.10 >+++ launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java 18 Apr 2007 20:25:46 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005, 2007 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 >@@ -11,8 +11,10 @@ > package org.eclipse.jdt.internal.launching.environments; > > import java.util.ArrayList; >+import java.util.HashMap; > import java.util.HashSet; > import java.util.List; >+import java.util.Map; > import java.util.Set; > > import org.eclipse.core.resources.ResourcesPlugin; >@@ -66,6 +68,24 @@ > private IVMInstall fDefault = null; > > /** >+ * Cache of access rule participants to consider for this environment. >+ */ >+ private IAccessRuleParticipant[] fParticipants = null; >+ >+ /** >+ * Map of {IVMInstall -> Map of {participant -> IAccessRule[][]}}. >+ * Caches access rules returned by each participant for a given VM. >+ */ >+ private Map fParticipantMap = new HashMap(); >+ >+ /** >+ * Cache of VM -> IAccessRule[][] based on the current state of the participant >+ * map. These are the union of the latest rules generated by the participants >+ * for a specific VM. >+ */ >+ private Map fRuleCache = new HashMap(); >+ >+ /** > * Wild card pattern matching all files > */ > private static final IPath ALL_PATTERN = new Path("**/*"); //$NON-NLS-1$ >@@ -195,29 +215,77 @@ > * @see org.eclipse.jdt.launching.environments.IExecutionEnvironment#getAccessRules(org.eclipse.jdt.launching.IVMInstall, org.eclipse.jdt.launching.LibraryLocation[], org.eclipse.jdt.core.IJavaProject) > */ > public IAccessRule[][] getAccessRules(IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) { >- List[] libLists = new List[libraries.length]; // array of lists of access rules >- for (int i = 0; i < libLists.length; i++) { >- libLists[i] = new ArrayList(); >- } >- // check participants first >- IAccessRuleParticipant[] participants = EnvironmentsManager.getDefault().getAccessRuleParticipants(); >- for (int i = 0; i < participants.length; i++) { >- processParticipant(participants[i], libLists, vm, libraries, project); >+ IAccessRuleParticipant[] participants = getParticipants(); >+ Map rulesByParticipant = collectRulesByParticipant(participants, vm, libraries, project); >+ synchronized (this) { >+ Map cachedRules = (Map) fParticipantMap.get(vm); >+ if (cachedRules == null || !cachedRules.equals(rulesByParticipant)) { >+ List[] libLists = new List[libraries.length]; // array of lists of access rules >+ for (int i = 0; i < libLists.length; i++) { >+ libLists[i] = new ArrayList(); >+ } >+ for (int i = 0; i < participants.length; i++) { >+ IAccessRuleParticipant participant = participants[i]; >+ addRules((IAccessRule[][]) rulesByParticipant.get(participant), libLists); >+ } >+ IAccessRule[][] allRules = new IAccessRule[libraries.length][]; >+ for (int i = 0; i < libLists.length; i++) { >+ allRules[i] = (IAccessRule[]) libLists[i].toArray(new IAccessRule[libLists[i].size()]); >+ } >+ fParticipantMap.put(vm, rulesByParticipant); >+ fRuleCache.put(vm, allRules); >+ return allRules; >+ } else { >+ return (IAccessRule[][]) fRuleCache.get(vm); >+ } > } >- // check default provider last >- if (fRuleParticipant != null) { >- processParticipant(fRuleParticipant, libLists, vm, libraries, project); >+ } >+ >+ /** >+ * Returns all access rule participants to consider for this environment. >+ * Includes any participant contributed with this environment and all other >+ * stand alone participants. >+ * >+ * @return access rule participants to consider for this environment >+ */ >+ private synchronized IAccessRuleParticipant[] getParticipants() { >+ if (fParticipants == null) { >+ // check participants first >+ IAccessRuleParticipant[] participants = EnvironmentsManager.getDefault().getAccessRuleParticipants(); >+ if (fRuleParticipant != null) { >+ // check default provider last >+ IAccessRuleParticipant[] copy = new IAccessRuleParticipant[participants.length + 1]; >+ System.arraycopy(participants, 0, copy, 0, participants.length); >+ copy[participants.length] = fRuleParticipant; >+ participants = copy; >+ } >+ fParticipants = participants; > } >- IAccessRule[][] allRules = new IAccessRule[libraries.length][]; >- for (int i = 0; i < libLists.length; i++) { >- allRules[i] = (IAccessRule[]) libLists[i].toArray(new IAccessRule[libLists[i].size()]); >+ return fParticipants; >+ } >+ >+ /** >+ * Returns a map of participant to the access rules for that participant for the given >+ * vm, libraries, and project. >+ * >+ * @param participants >+ * @return >+ */ >+ private Map collectRulesByParticipant(IAccessRuleParticipant[] participants, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) { >+ Map map = new HashMap(); >+ for (int i = 0; i < participants.length; i++) { >+ IAccessRuleParticipant participant = participants[i]; >+ // TODO: use safe runnable >+ map.put(participant, participant.getAccessRules(this, vm, libraries, project)); > } >- return allRules; >+ return map; > } > >- private void processParticipant(IAccessRuleParticipant participant, List[] collect, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) { >- // TODO: use safe runnables >- IAccessRule[][] accessRules = participant.getAccessRules(this, vm, libraries, project); >+ /** >+ * Adds the access rules to each list in the given collection. If the last rule in a >+ * given collection is the wild card pattern then no more rules are added to that collection. >+ */ >+ private void addRules(IAccessRule[][] accessRules, List[] collect) { > for (int i = 0; i < accessRules.length; i++) { > IAccessRule[] libRules = accessRules[i]; > List list = collect[i]; >@@ -233,4 +301,5 @@ > } > } > } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 179685
:
63099
|
64105
| 64230 |
64232