Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordwagelaar2015-05-22 07:25:24 -0400
committerdwagelaar2015-05-22 07:25:24 -0400
commita9ccd372e2f4e68330e7e1163aebc55cfa7d49b1 (patch)
treec60cc1c6e44ddad79eb447c93d691101b99be8bd /plugins/org.eclipse.m2m.atl.emftvm
parentffdcfb8605c70a51daafa363e22281151d92427e (diff)
downloadorg.eclipse.atl-a9ccd372e2f4e68330e7e1163aebc55cfa7d49b1.tar.gz
org.eclipse.atl-a9ccd372e2f4e68330e7e1163aebc55cfa7d49b1.tar.xz
org.eclipse.atl-a9ccd372e2f4e68330e7e1163aebc55cfa7d49b1.zip
Performance fixes for EMFTVMUtil.findRootMethod() and Tuple.
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm')
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java30
-rwxr-xr-xplugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java4
2 files changed, 30 insertions, 4 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
index 0a290f6c..8b640014 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011-2013 Dennis Wagelaar, Vrije Universiteit Brussel.
+ * Copyright (c) 2011-2015 Dennis Wagelaar, Vrije Universiteit Brussel.
* 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
@@ -24,6 +24,7 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -159,6 +160,16 @@ public final class EMFTVMUtil {
private static final Map<Class<?>, Map<Integer, Method>> METHOD_CACHE = new WeakHashMap<Class<?>, Map<Integer, Method>>();
/**
+ * Cache used to store the found root methods for native Java methods.
+ *
+ * @author <a href="mailto:frederic.jouault@univ-nantes.fr">Frederic Jouault</a>
+ * @author <a href="mailto:william.piers@obeo.fr">William Piers</a>
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ * @author <a href="mailto:dennis.wagelaar@vub.ac.be">Dennis Wagelaar</a>
+ */
+ private static final Map<Method, Method> ROOT_METHOD_CACHE = Collections.synchronizedMap(new WeakHashMap<Method, Method>());
+
+ /**
* Singleton {@link RegistryTypeSwitch} instance.
*/
private static final RegistryTypeSwitch REGISTRY_TYPE_SWITCH = new RegistryTypeSwitch();
@@ -2464,10 +2475,25 @@ public final class EMFTVMUtil {
* @param method the method for which to find the root declaration
* @return the root {@link Method}
*/
- public static Method findRootMethod(Method method) {
+ public static Method findRootMethod(final Method method) {
if (method == null) {
return null;
}
+ Method rootMethod = ROOT_METHOD_CACHE.get(method);
+ if (rootMethod != null) {
+ return rootMethod;
+ }
+ rootMethod = findRootMethodInner(method);
+ ROOT_METHOD_CACHE.put(method, rootMethod);
+ return rootMethod;
+ }
+
+ /**
+ * Finds the root {@link Class} declaration for the given <code>method</code>.
+ * @param method the method for which to find the root declaration
+ * @return the root {@link Method}
+ */
+ private static Method findRootMethodInner(Method method) {
final int methodModifiers = getRelevantModifiers(method);
Class<?> dc = method.getDeclaringClass();
java.util.Set<Class<?>> dis = new LinkedHashSet<Class<?>>(
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java
index d22e1fd9..e1fe1df3 100755
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/Tuple.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Vrije Universiteit Brussel.
+ * Copyright (c) 2011-2015 Dennis Wagelaar, Vrije Universiteit Brussel.
* 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
@@ -82,7 +82,7 @@ public final class Tuple {
* the map with tuple key-value pairs
*/
public Tuple(Map<String, Object> map) {
- values = Collections.unmodifiableMap(map);
+ values = map;
}
/**

Back to the top