Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfrijters <jfrijters>2010-11-20 10:41:00 +0300
committerjfrijters <jfrijters>2010-11-20 10:41:00 +0300
commit1eeadb53331c1013870c15bda88a3caaa26645a9 (patch)
tree69aabf2cfb765d6fd6cc7c9d7ee03199b0756937
parentd22a8e25af558960ca4fd3cb08321a09d111e2ed (diff)
- Replaced reflection based implementation of isCCLOverridden() with an MSIL version that directly compares the method pointers.
- Always use isCCLOverridden() to determine if we need to call parent.getContextClassLoader(), this avoids resolving ClassLoader.DUMMY when we're creating a new thread.
-rw-r--r--openjdk/java/lang/Thread.java60
-rw-r--r--openjdk/map.xml16
2 files changed, 19 insertions, 57 deletions
diff --git a/openjdk/java/lang/Thread.java b/openjdk/java/lang/Thread.java
index 1d0eeffd..b07372d8 100644
--- a/openjdk/java/lang/Thread.java
+++ b/openjdk/java/lang/Thread.java
@@ -32,7 +32,6 @@ import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.concurrent.locks.LockSupport;
-import sun.misc.SoftCache;
import sun.nio.ch.Interruptible;
import sun.security.util.SecurityConstants;
@@ -451,7 +450,7 @@ class Thread implements Runnable {
* Do we have the required permissions?
*/
if (security != null) {
- if (isCCLOverridden(getClass())) {
+ if (isCCLOverridden(this)) {
security.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
}
}
@@ -463,7 +462,7 @@ class Thread implements Runnable {
this.daemon = parent.isDaemon();
this.priority = parent.getPriority();
this.name = name.toCharArray();
- if (security == null || isCCLOverridden(parent.getClass()))
+ if (isCCLOverridden(parent))
this.contextClassLoader = parent.getContextClassLoader();
else
this.contextClassLoader = parent.contextClassLoader;
@@ -1790,66 +1789,13 @@ class Thread implements Runnable {
private static final RuntimePermission SUBCLASS_IMPLEMENTATION_PERMISSION =
new RuntimePermission("enableContextClassLoaderOverride");
- /** cache of subclass security audit results */
- private static final SoftCache subclassAudits = new SoftCache(10);
-
-
/**
* Verifies that this (possibly subclass) instance can be constructed
* without violating security constraints: the subclass must not override
* security-sensitive non-final methods, or else the
* "enableContextClassLoaderOverride" RuntimePermission is checked.
*/
- private static boolean isCCLOverridden(Class cl) {
- if (cl == Thread.class)
- return false;
- Boolean result = null;
- synchronized (subclassAudits) {
- result = (Boolean) subclassAudits.get(cl);
- if (result == null) {
- /*
- * Note: only new Boolean instances (i.e., not Boolean.TRUE or
- * Boolean.FALSE) must be used as cache values, otherwise cache
- * entry will pin associated class.
- */
- result = new Boolean(auditSubclass(cl));
- subclassAudits.put(cl, result);
- }
- }
- return result.booleanValue();
- }
-
- /**
- * Performs reflective checks on given subclass to verify that it doesn't
- * override security-sensitive non-final methods. Returns true if the
- * subclass overrides any of the methods, false otherwise.
- */
- private static boolean auditSubclass(final Class subcl) {
- Boolean result = AccessController.doPrivileged(
- new PrivilegedAction<Boolean>() {
- public Boolean run() {
- for (Class cl = subcl;
- cl != Thread.class;
- cl = cl.getSuperclass())
- {
- try {
- cl.getDeclaredMethod("getContextClassLoader", new Class[0]);
- return Boolean.TRUE;
- } catch (NoSuchMethodException ex) {
- }
- try {
- Class[] params = {ClassLoader.class};
- cl.getDeclaredMethod("setContextClassLoader", params);
- return Boolean.TRUE;
- } catch (NoSuchMethodException ex) {
- }
- }
- return Boolean.FALSE;
- }
- }
- );
- return result.booleanValue();
- }
+ private static native boolean isCCLOverridden(Thread thread); // [IKVM] implemented in map.xml
private static StackTraceElement[][] dumpThreads(Thread[] threads) {
StackTraceElement[][] stacks = new StackTraceElement[threads.length][];
diff --git a/openjdk/map.xml b/openjdk/map.xml
index b46491df..237f844b 100644
--- a/openjdk/map.xml
+++ b/openjdk/map.xml
@@ -1390,6 +1390,22 @@
<class name="java.lang.Thread">
<field name="parkLock" sig="Ljava.lang.Object;" modifiers="" />
<field name="parkState" sig="I" modifiers="" />
+ <method name="isCCLOverridden" sig="(Ljava.lang.Thread;)Z">
+ <body>
+ <ldftn class="java.lang.Thread" name="getContextClassLoader" sig="()Ljava.lang.ClassLoader;" />
+ <ldarg_0 />
+ <ldvirtftn class="java.lang.Thread" name="getContextClassLoader" sig="()Ljava.lang.ClassLoader;" />
+ <ceq />
+ <ldftn class="java.lang.Thread" name="setContextClassLoader" sig="(Ljava.lang.ClassLoader;)V" />
+ <ldarg_0 />
+ <ldvirtftn class="java.lang.Thread" name="setContextClassLoader" sig="(Ljava.lang.ClassLoader;)V" />
+ <ceq />
+ <and />
+ <ldc_i4_0 />
+ <ceq />
+ <ret />
+ </body>
+ </method>
</class>
<class name="java.lang.ThreadGroup">
<method name="createRootGroup" sig="()Ljava.lang.ThreadGroup;" modifiers="static">