rt/emul/compact/src/main/java/java/lang/Thread.java
changeset 1260 fe3567c7b522
parent 1259 d257b7a37635
child 1403 8120793cc756
     1.1 --- a/rt/emul/compact/src/main/java/java/lang/Thread.java	Sat Sep 07 13:55:09 2013 +0200
     1.2 +++ b/rt/emul/compact/src/main/java/java/lang/Thread.java	Sat Sep 07 13:56:22 2013 +0200
     1.3 @@ -25,19 +25,7 @@
     1.4  
     1.5  package java.lang;
     1.6  
     1.7 -import java.lang.ref.Reference;
     1.8 -import java.lang.ref.ReferenceQueue;
     1.9 -import java.lang.ref.WeakReference;
    1.10 -import java.security.AccessController;
    1.11 -import java.security.AccessControlContext;
    1.12 -import java.security.PrivilegedAction;
    1.13  import java.util.Map;
    1.14 -import java.util.HashMap;
    1.15 -import java.util.concurrent.ConcurrentHashMap;
    1.16 -import java.util.concurrent.ConcurrentMap;
    1.17 -import java.util.concurrent.locks.LockSupport;
    1.18 -import sun.nio.ch.Interruptible;
    1.19 -import sun.security.util.SecurityConstants;
    1.20  
    1.21  
    1.22  /**
    1.23 @@ -137,107 +125,6 @@
    1.24   */
    1.25  public
    1.26  class Thread implements Runnable {
    1.27 -    /* Make sure registerNatives is the first thing <clinit> does. */
    1.28 -    private static native void registerNatives();
    1.29 -    static {
    1.30 -        registerNatives();
    1.31 -    }
    1.32 -
    1.33 -    private char        name[];
    1.34 -    private int         priority;
    1.35 -    private Thread      threadQ;
    1.36 -    private long        eetop;
    1.37 -
    1.38 -    /* Whether or not to single_step this thread. */
    1.39 -    private boolean     single_step;
    1.40 -
    1.41 -    /* Whether or not the thread is a daemon thread. */
    1.42 -    private boolean     daemon = false;
    1.43 -
    1.44 -    /* JVM state */
    1.45 -    private boolean     stillborn = false;
    1.46 -
    1.47 -    /* What will be run. */
    1.48 -    private Runnable target;
    1.49 -
    1.50 -    /* The group of this thread */
    1.51 -    private ThreadGroup group;
    1.52 -
    1.53 -    /* The context ClassLoader for this thread */
    1.54 -    private ClassLoader contextClassLoader;
    1.55 -
    1.56 -    /* The inherited AccessControlContext of this thread */
    1.57 -    private AccessControlContext inheritedAccessControlContext;
    1.58 -
    1.59 -    /* For autonumbering anonymous threads. */
    1.60 -    private static int threadInitNumber;
    1.61 -    private static synchronized int nextThreadNum() {
    1.62 -        return threadInitNumber++;
    1.63 -    }
    1.64 -
    1.65 -    /* ThreadLocal values pertaining to this thread. This map is maintained
    1.66 -     * by the ThreadLocal class. */
    1.67 -    ThreadLocal.ThreadLocalMap threadLocals = null;
    1.68 -
    1.69 -    /*
    1.70 -     * InheritableThreadLocal values pertaining to this thread. This map is
    1.71 -     * maintained by the InheritableThreadLocal class.
    1.72 -     */
    1.73 -    ThreadLocal.ThreadLocalMap inheritableThreadLocals = null;
    1.74 -
    1.75 -    /*
    1.76 -     * The requested stack size for this thread, or 0 if the creator did
    1.77 -     * not specify a stack size.  It is up to the VM to do whatever it
    1.78 -     * likes with this number; some VMs will ignore it.
    1.79 -     */
    1.80 -    private long stackSize;
    1.81 -
    1.82 -    /*
    1.83 -     * JVM-private state that persists after native thread termination.
    1.84 -     */
    1.85 -    private long nativeParkEventPointer;
    1.86 -
    1.87 -    /*
    1.88 -     * Thread ID
    1.89 -     */
    1.90 -    private long tid;
    1.91 -
    1.92 -    /* For generating thread ID */
    1.93 -    private static long threadSeqNumber;
    1.94 -
    1.95 -    /* Java thread status for tools,
    1.96 -     * initialized to indicate thread 'not yet started'
    1.97 -     */
    1.98 -
    1.99 -    private volatile int threadStatus = 0;
   1.100 -
   1.101 -
   1.102 -    private static synchronized long nextThreadID() {
   1.103 -        return ++threadSeqNumber;
   1.104 -    }
   1.105 -
   1.106 -    /**
   1.107 -     * The argument supplied to the current call to
   1.108 -     * java.util.concurrent.locks.LockSupport.park.
   1.109 -     * Set by (private) java.util.concurrent.locks.LockSupport.setBlocker
   1.110 -     * Accessed using java.util.concurrent.locks.LockSupport.getBlocker
   1.111 -     */
   1.112 -    volatile Object parkBlocker;
   1.113 -
   1.114 -    /* The object in which this thread is blocked in an interruptible I/O
   1.115 -     * operation, if any.  The blocker's interrupt method should be invoked
   1.116 -     * after setting this thread's interrupt status.
   1.117 -     */
   1.118 -    private volatile Interruptible blocker;
   1.119 -    private final Object blockerLock = new Object();
   1.120 -
   1.121 -    /* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
   1.122 -     */
   1.123 -    void blockedOn(Interruptible b) {
   1.124 -        synchronized (blockerLock) {
   1.125 -            blocker = b;
   1.126 -        }
   1.127 -    }
   1.128  
   1.129      /**
   1.130       * The minimum priority that a thread can have.
   1.131 @@ -254,12 +141,15 @@
   1.132       */
   1.133      public final static int MAX_PRIORITY = 10;
   1.134  
   1.135 +    private static final Thread ONE = new Thread("main");
   1.136      /**
   1.137       * Returns a reference to the currently executing thread object.
   1.138       *
   1.139       * @return  the currently executing thread.
   1.140       */
   1.141 -    public static native Thread currentThread();
   1.142 +    public static Thread currentThread() {
   1.143 +        return ONE;
   1.144 +    }
   1.145  
   1.146      /**
   1.147       * A hint to the scheduler that the current thread is willing to yield
   1.148 @@ -277,7 +167,8 @@
   1.149       * concurrency control constructs such as the ones in the
   1.150       * {@link java.util.concurrent.locks} package.
   1.151       */
   1.152 -    public static native void yield();
   1.153 +    public static void yield() {
   1.154 +    }
   1.155  
   1.156      /**
   1.157       * Causes the currently executing thread to sleep (temporarily cease
   1.158 @@ -337,75 +228,8 @@
   1.159  
   1.160          sleep(millis);
   1.161      }
   1.162 -
   1.163 -    /**
   1.164 -     * Initializes a Thread.
   1.165 -     *
   1.166 -     * @param g the Thread group
   1.167 -     * @param target the object whose run() method gets called
   1.168 -     * @param name the name of the new Thread
   1.169 -     * @param stackSize the desired stack size for the new thread, or
   1.170 -     *        zero to indicate that this parameter is to be ignored.
   1.171 -     */
   1.172 -    private void init(ThreadGroup g, Runnable target, String name,
   1.173 -                      long stackSize) {
   1.174 -        if (name == null) {
   1.175 -            throw new NullPointerException("name cannot be null");
   1.176 -        }
   1.177 -
   1.178 -        Thread parent = currentThread();
   1.179 -        SecurityManager security = System.getSecurityManager();
   1.180 -        if (g == null) {
   1.181 -            /* Determine if it's an applet or not */
   1.182 -
   1.183 -            /* If there is a security manager, ask the security manager
   1.184 -               what to do. */
   1.185 -            if (security != null) {
   1.186 -                g = security.getThreadGroup();
   1.187 -            }
   1.188 -
   1.189 -            /* If the security doesn't have a strong opinion of the matter
   1.190 -               use the parent thread group. */
   1.191 -            if (g == null) {
   1.192 -                g = parent.getThreadGroup();
   1.193 -            }
   1.194 -        }
   1.195 -
   1.196 -        /* checkAccess regardless of whether or not threadgroup is
   1.197 -           explicitly passed in. */
   1.198 -        g.checkAccess();
   1.199 -
   1.200 -        /*
   1.201 -         * Do we have the required permissions?
   1.202 -         */
   1.203 -        if (security != null) {
   1.204 -            if (isCCLOverridden(getClass())) {
   1.205 -                security.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
   1.206 -            }
   1.207 -        }
   1.208 -
   1.209 -        g.addUnstarted();
   1.210 -
   1.211 -        this.group = g;
   1.212 -        this.daemon = parent.isDaemon();
   1.213 -        this.priority = parent.getPriority();
   1.214 -        this.name = name.toCharArray();
   1.215 -        if (security == null || isCCLOverridden(parent.getClass()))
   1.216 -            this.contextClassLoader = parent.getContextClassLoader();
   1.217 -        else
   1.218 -            this.contextClassLoader = parent.contextClassLoader;
   1.219 -        this.inheritedAccessControlContext = AccessController.getContext();
   1.220 -        this.target = target;
   1.221 -        setPriority(priority);
   1.222 -        if (parent.inheritableThreadLocals != null)
   1.223 -            this.inheritableThreadLocals =
   1.224 -                ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);
   1.225 -        /* Stash the specified stack size in case the VM cares */
   1.226 -        this.stackSize = stackSize;
   1.227 -
   1.228 -        /* Set thread ID */
   1.229 -        tid = nextThreadID();
   1.230 -    }
   1.231 +    private Runnable target;
   1.232 +    private String name;
   1.233  
   1.234      /**
   1.235       * Throws CloneNotSupportedException as a Thread can not be meaningfully
   1.236 @@ -429,6 +253,10 @@
   1.237      public Thread() {
   1.238          init(null, null, "Thread-" + nextThreadNum(), 0);
   1.239      }
   1.240 +    
   1.241 +    private static int nextThreadNum() {
   1.242 +        return -1;
   1.243 +    }
   1.244  
   1.245      /**
   1.246       * Allocates a new {@code Thread} object. This constructor has the same
   1.247 @@ -469,9 +297,9 @@
   1.248       *          if the current thread cannot create a thread in the specified
   1.249       *          thread group
   1.250       */
   1.251 -    public Thread(ThreadGroup group, Runnable target) {
   1.252 -        init(group, target, "Thread-" + nextThreadNum(), 0);
   1.253 -    }
   1.254 +//    public Thread(ThreadGroup group, Runnable target) {
   1.255 +//        init(group, target, "Thread-" + nextThreadNum(), 0);
   1.256 +//    }
   1.257  
   1.258      /**
   1.259       * Allocates a new {@code Thread} object. This constructor has the same
   1.260 @@ -484,6 +312,11 @@
   1.261      public Thread(String name) {
   1.262          init(null, null, name, 0);
   1.263      }
   1.264 +    
   1.265 +    private void init(Object o1, Runnable trgt, String nm, int i4) {
   1.266 +        this.target = trgt;
   1.267 +        this.name = nm;
   1.268 +    }
   1.269  
   1.270      /**
   1.271       * Allocates a new {@code Thread} object. This constructor has the same
   1.272 @@ -505,9 +338,9 @@
   1.273       *          if the current thread cannot create a thread in the specified
   1.274       *          thread group
   1.275       */
   1.276 -    public Thread(ThreadGroup group, String name) {
   1.277 -        init(group, null, name, 0);
   1.278 -    }
   1.279 +//    public Thread(ThreadGroup group, String name) {
   1.280 +//        init(group, null, name, 0);
   1.281 +//    }
   1.282  
   1.283      /**
   1.284       * Allocates a new {@code Thread} object. This constructor has the same
   1.285 @@ -569,9 +402,9 @@
   1.286       *          if the current thread cannot create a thread in the specified
   1.287       *          thread group or cannot override the context class loader methods.
   1.288       */
   1.289 -    public Thread(ThreadGroup group, Runnable target, String name) {
   1.290 -        init(group, target, name, 0);
   1.291 -    }
   1.292 +//    public Thread(ThreadGroup group, Runnable target, String name) {
   1.293 +//        init(group, target, name, 0);
   1.294 +//    }
   1.295  
   1.296      /**
   1.297       * Allocates a new {@code Thread} object so that it has {@code target}
   1.298 @@ -647,10 +480,10 @@
   1.299       *
   1.300       * @since 1.4
   1.301       */
   1.302 -    public Thread(ThreadGroup group, Runnable target, String name,
   1.303 -                  long stackSize) {
   1.304 -        init(group, target, name, stackSize);
   1.305 -    }
   1.306 +//    public Thread(ThreadGroup group, Runnable target, String name,
   1.307 +//                  long stackSize) {
   1.308 +//        init(group, target, name, stackSize);
   1.309 +//    }
   1.310  
   1.311      /**
   1.312       * Causes this thread to begin execution; the Java Virtual Machine
   1.313 @@ -670,40 +503,10 @@
   1.314       * @see        #run()
   1.315       * @see        #stop()
   1.316       */
   1.317 -    public synchronized void start() {
   1.318 -        /**
   1.319 -         * This method is not invoked for the main method thread or "system"
   1.320 -         * group threads created/set up by the VM. Any new functionality added
   1.321 -         * to this method in the future may have to also be added to the VM.
   1.322 -         *
   1.323 -         * A zero status value corresponds to state "NEW".
   1.324 -         */
   1.325 -        if (threadStatus != 0)
   1.326 -            throw new IllegalThreadStateException();
   1.327 -
   1.328 -        /* Notify the group that this thread is about to be started
   1.329 -         * so that it can be added to the group's list of threads
   1.330 -         * and the group's unstarted count can be decremented. */
   1.331 -        group.add(this);
   1.332 -
   1.333 -        boolean started = false;
   1.334 -        try {
   1.335 -            start0();
   1.336 -            started = true;
   1.337 -        } finally {
   1.338 -            try {
   1.339 -                if (!started) {
   1.340 -                    group.threadStartFailed(this);
   1.341 -                }
   1.342 -            } catch (Throwable ignore) {
   1.343 -                /* do nothing. If start0 threw a Throwable then
   1.344 -                  it will be passed up the call stack */
   1.345 -            }
   1.346 -        }
   1.347 +    public void start() {
   1.348 +        throw new SecurityException();
   1.349      }
   1.350  
   1.351 -    private native void start0();
   1.352 -
   1.353      /**
   1.354       * If this thread was constructed using a separate
   1.355       * <code>Runnable</code> run object, then that
   1.356 @@ -724,25 +527,6 @@
   1.357      }
   1.358  
   1.359      /**
   1.360 -     * This method is called by the system to give a Thread
   1.361 -     * a chance to clean up before it actually exits.
   1.362 -     */
   1.363 -    private void exit() {
   1.364 -        if (group != null) {
   1.365 -            group.threadTerminated(this);
   1.366 -            group = null;
   1.367 -        }
   1.368 -        /* Aggressively null out all reference fields: see bug 4006245 */
   1.369 -        target = null;
   1.370 -        /* Speed the release of some of these resources */
   1.371 -        threadLocals = null;
   1.372 -        inheritableThreadLocals = null;
   1.373 -        inheritedAccessControlContext = null;
   1.374 -        blocker = null;
   1.375 -        uncaughtExceptionHandler = null;
   1.376 -    }
   1.377 -
   1.378 -    /**
   1.379       * Forces the thread to stop executing.
   1.380       * <p>
   1.381       * If there is a security manager installed, its <code>checkAccess</code>
   1.382 @@ -810,7 +594,7 @@
   1.383       */
   1.384      @Deprecated
   1.385      public final void stop() {
   1.386 -        stop(new ThreadDeath());
   1.387 +        stop(null);
   1.388      }
   1.389  
   1.390      /**
   1.391 @@ -864,25 +648,7 @@
   1.392       */
   1.393      @Deprecated
   1.394      public final synchronized void stop(Throwable obj) {
   1.395 -        if (obj == null)
   1.396 -            throw new NullPointerException();
   1.397 -
   1.398 -        SecurityManager security = System.getSecurityManager();
   1.399 -        if (security != null) {
   1.400 -            checkAccess();
   1.401 -            if ((this != Thread.currentThread()) ||
   1.402 -                (!(obj instanceof ThreadDeath))) {
   1.403 -                security.checkPermission(SecurityConstants.STOP_THREAD_PERMISSION);
   1.404 -            }
   1.405 -        }
   1.406 -        // A zero status value corresponds to "NEW", it can't change to
   1.407 -        // not-NEW because we hold the lock.
   1.408 -        if (threadStatus != 0) {
   1.409 -            resume(); // Wake up thread if it was suspended; no-op otherwise
   1.410 -        }
   1.411 -
   1.412 -        // The VM can handle all thread states
   1.413 -        stop0(obj);
   1.414 +        throw new SecurityException();
   1.415      }
   1.416  
   1.417      /**
   1.418 @@ -925,18 +691,7 @@
   1.419       * @spec JSR-51
   1.420       */
   1.421      public void interrupt() {
   1.422 -        if (this != Thread.currentThread())
   1.423 -            checkAccess();
   1.424 -
   1.425 -        synchronized (blockerLock) {
   1.426 -            Interruptible b = blocker;
   1.427 -            if (b != null) {
   1.428 -                interrupt0();           // Just to set the interrupt flag
   1.429 -                b.interrupt(this);
   1.430 -                return;
   1.431 -            }
   1.432 -        }
   1.433 -        interrupt0();
   1.434 +        throw new SecurityException();
   1.435      }
   1.436  
   1.437      /**
   1.438 @@ -957,7 +712,7 @@
   1.439       * @revised 6.0
   1.440       */
   1.441      public static boolean interrupted() {
   1.442 -        return currentThread().isInterrupted(true);
   1.443 +        return currentThread().isInterrupted();
   1.444      }
   1.445  
   1.446      /**
   1.447 @@ -974,17 +729,10 @@
   1.448       * @revised 6.0
   1.449       */
   1.450      public boolean isInterrupted() {
   1.451 -        return isInterrupted(false);
   1.452 +        return false;
   1.453      }
   1.454  
   1.455      /**
   1.456 -     * Tests if some Thread has been interrupted.  The interrupted state
   1.457 -     * is reset or not based on the value of ClearInterrupted that is
   1.458 -     * passed.
   1.459 -     */
   1.460 -    private native boolean isInterrupted(boolean ClearInterrupted);
   1.461 -
   1.462 -    /**
   1.463       * Throws {@link NoSuchMethodError}.
   1.464       *
   1.465       * @deprecated This method was originally designed to destroy this
   1.466 @@ -1003,7 +751,7 @@
   1.467       */
   1.468      @Deprecated
   1.469      public void destroy() {
   1.470 -        throw new NoSuchMethodError();
   1.471 +        throw new SecurityException();
   1.472      }
   1.473  
   1.474      /**
   1.475 @@ -1013,7 +761,9 @@
   1.476       * @return  <code>true</code> if this thread is alive;
   1.477       *          <code>false</code> otherwise.
   1.478       */
   1.479 -    public final native boolean isAlive();
   1.480 +    public final boolean isAlive() {
   1.481 +        return true;
   1.482 +    }
   1.483  
   1.484      /**
   1.485       * Suspends this thread.
   1.486 @@ -1042,7 +792,6 @@
   1.487      @Deprecated
   1.488      public final void suspend() {
   1.489          checkAccess();
   1.490 -        suspend0();
   1.491      }
   1.492  
   1.493      /**
   1.494 @@ -1068,7 +817,6 @@
   1.495      @Deprecated
   1.496      public final void resume() {
   1.497          checkAccess();
   1.498 -        resume0();
   1.499      }
   1.500  
   1.501      /**
   1.502 @@ -1096,17 +844,7 @@
   1.503       * @see        ThreadGroup#getMaxPriority()
   1.504       */
   1.505      public final void setPriority(int newPriority) {
   1.506 -        ThreadGroup g;
   1.507 -        checkAccess();
   1.508 -        if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) {
   1.509 -            throw new IllegalArgumentException();
   1.510 -        }
   1.511 -        if((g = getThreadGroup()) != null) {
   1.512 -            if (newPriority > g.getMaxPriority()) {
   1.513 -                newPriority = g.getMaxPriority();
   1.514 -            }
   1.515 -            setPriority0(priority = newPriority);
   1.516 -        }
   1.517 +        throw new SecurityException();
   1.518      }
   1.519  
   1.520      /**
   1.521 @@ -1116,7 +854,7 @@
   1.522       * @see     #setPriority
   1.523       */
   1.524      public final int getPriority() {
   1.525 -        return priority;
   1.526 +        return Thread.NORM_PRIORITY;
   1.527      }
   1.528  
   1.529      /**
   1.530 @@ -1134,8 +872,7 @@
   1.531       * @see        #checkAccess()
   1.532       */
   1.533      public final void setName(String name) {
   1.534 -        checkAccess();
   1.535 -        this.name = name.toCharArray();
   1.536 +        throw new SecurityException();
   1.537      }
   1.538  
   1.539      /**
   1.540 @@ -1155,9 +892,9 @@
   1.541       *
   1.542       * @return  this thread's thread group.
   1.543       */
   1.544 -    public final ThreadGroup getThreadGroup() {
   1.545 -        return group;
   1.546 -    }
   1.547 +//    public final ThreadGroup getThreadGroup() {
   1.548 +//        return group;
   1.549 +//    }
   1.550  
   1.551      /**
   1.552       * Returns an estimate of the number of active threads in the current
   1.553 @@ -1176,7 +913,7 @@
   1.554       *          has the current thread's thread group as an ancestor
   1.555       */
   1.556      public static int activeCount() {
   1.557 -        return currentThread().getThreadGroup().activeCount();
   1.558 +        return 1;
   1.559      }
   1.560  
   1.561      /**
   1.562 @@ -1206,7 +943,7 @@
   1.563       *          the current thread cannot access its thread group
   1.564       */
   1.565      public static int enumerate(Thread tarray[]) {
   1.566 -        return currentThread().getThreadGroup().enumerate(tarray);
   1.567 +        throw new SecurityException();
   1.568      }
   1.569  
   1.570      /**
   1.571 @@ -1360,11 +1097,7 @@
   1.572       *          thread cannot modify this thread
   1.573       */
   1.574      public final void setDaemon(boolean on) {
   1.575 -        checkAccess();
   1.576 -        if (isAlive()) {
   1.577 -            throw new IllegalThreadStateException();
   1.578 -        }
   1.579 -        daemon = on;
   1.580 +        throw new SecurityException();
   1.581      }
   1.582  
   1.583      /**
   1.584 @@ -1375,7 +1108,7 @@
   1.585       * @see     #setDaemon(boolean)
   1.586       */
   1.587      public final boolean isDaemon() {
   1.588 -        return daemon;
   1.589 +        return false;
   1.590      }
   1.591  
   1.592      /**
   1.593 @@ -1391,10 +1124,7 @@
   1.594       * @see        SecurityManager#checkAccess(Thread)
   1.595       */
   1.596      public final void checkAccess() {
   1.597 -        SecurityManager security = System.getSecurityManager();
   1.598 -        if (security != null) {
   1.599 -            security.checkAccess(this);
   1.600 -        }
   1.601 +        throw new SecurityException();
   1.602      }
   1.603  
   1.604      /**
   1.605 @@ -1404,14 +1134,8 @@
   1.606       * @return  a string representation of this thread.
   1.607       */
   1.608      public String toString() {
   1.609 -        ThreadGroup group = getThreadGroup();
   1.610 -        if (group != null) {
   1.611 -            return "Thread[" + getName() + "," + getPriority() + "," +
   1.612 -                           group.getName() + "]";
   1.613 -        } else {
   1.614 -            return "Thread[" + getName() + "," + getPriority() + "," +
   1.615 -                            "" + "]";
   1.616 -        }
   1.617 +        return "Thread[" + getName() + "," + getPriority() + "," +
   1.618 +                        "" + "]";
   1.619      }
   1.620  
   1.621      /**
   1.622 @@ -1441,17 +1165,7 @@
   1.623       * @since 1.2
   1.624       */
   1.625      public ClassLoader getContextClassLoader() {
   1.626 -        if (contextClassLoader == null)
   1.627 -            return null;
   1.628 -        SecurityManager sm = System.getSecurityManager();
   1.629 -        if (sm != null) {
   1.630 -            ClassLoader ccl = ClassLoader.getCallerClassLoader();
   1.631 -            if (ccl != null && ccl != contextClassLoader &&
   1.632 -                    !contextClassLoader.isAncestor(ccl)) {
   1.633 -                sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
   1.634 -            }
   1.635 -        }
   1.636 -        return contextClassLoader;
   1.637 +        return null;
   1.638      }
   1.639  
   1.640      /**
   1.641 @@ -1477,11 +1191,7 @@
   1.642       * @since 1.2
   1.643       */
   1.644      public void setContextClassLoader(ClassLoader cl) {
   1.645 -        SecurityManager sm = System.getSecurityManager();
   1.646 -        if (sm != null) {
   1.647 -            sm.checkPermission(new RuntimePermission("setContextClassLoader"));
   1.648 -        }
   1.649 -        contextClassLoader = cl;
   1.650 +        throw new SecurityException();
   1.651      }
   1.652  
   1.653      /**
   1.654 @@ -1500,10 +1210,9 @@
   1.655       *         the specified object.
   1.656       * @since 1.4
   1.657       */
   1.658 -    public static native boolean holdsLock(Object obj);
   1.659 -
   1.660 -    private static final StackTraceElement[] EMPTY_STACK_TRACE
   1.661 -        = new StackTraceElement[0];
   1.662 +    public static boolean holdsLock(Object obj) {
   1.663 +        return true;
   1.664 +    }
   1.665  
   1.666      /**
   1.667       * Returns an array of stack trace elements representing the stack dump
   1.668 @@ -1542,30 +1251,7 @@
   1.669       * @since 1.5
   1.670       */
   1.671      public StackTraceElement[] getStackTrace() {
   1.672 -        if (this != Thread.currentThread()) {
   1.673 -            // check for getStackTrace permission
   1.674 -            SecurityManager security = System.getSecurityManager();
   1.675 -            if (security != null) {
   1.676 -                security.checkPermission(
   1.677 -                    SecurityConstants.GET_STACK_TRACE_PERMISSION);
   1.678 -            }
   1.679 -            // optimization so we do not call into the vm for threads that
   1.680 -            // have not yet started or have terminated
   1.681 -            if (!isAlive()) {
   1.682 -                return EMPTY_STACK_TRACE;
   1.683 -            }
   1.684 -            StackTraceElement[][] stackTraceArray = dumpThreads(new Thread[] {this});
   1.685 -            StackTraceElement[] stackTrace = stackTraceArray[0];
   1.686 -            // a thread that was alive during the previous isAlive call may have
   1.687 -            // since terminated, therefore not having a stacktrace.
   1.688 -            if (stackTrace == null) {
   1.689 -                stackTrace = EMPTY_STACK_TRACE;
   1.690 -            }
   1.691 -            return stackTrace;
   1.692 -        } else {
   1.693 -            // Don't need JVM help for current thread
   1.694 -            return (new Exception()).getStackTrace();
   1.695 -        }
   1.696 +        throw new SecurityException();
   1.697      }
   1.698  
   1.699      /**
   1.700 @@ -1604,102 +1290,9 @@
   1.701       * @since 1.5
   1.702       */
   1.703      public static Map<Thread, StackTraceElement[]> getAllStackTraces() {
   1.704 -        // check for getStackTrace permission
   1.705 -        SecurityManager security = System.getSecurityManager();
   1.706 -        if (security != null) {
   1.707 -            security.checkPermission(
   1.708 -                SecurityConstants.GET_STACK_TRACE_PERMISSION);
   1.709 -            security.checkPermission(
   1.710 -                SecurityConstants.MODIFY_THREADGROUP_PERMISSION);
   1.711 -        }
   1.712 -
   1.713 -        // Get a snapshot of the list of all threads
   1.714 -        Thread[] threads = getThreads();
   1.715 -        StackTraceElement[][] traces = dumpThreads(threads);
   1.716 -        Map<Thread, StackTraceElement[]> m = new HashMap<>(threads.length);
   1.717 -        for (int i = 0; i < threads.length; i++) {
   1.718 -            StackTraceElement[] stackTrace = traces[i];
   1.719 -            if (stackTrace != null) {
   1.720 -                m.put(threads[i], stackTrace);
   1.721 -            }
   1.722 -            // else terminated so we don't put it in the map
   1.723 -        }
   1.724 -        return m;
   1.725 +        throw new SecurityException();
   1.726      }
   1.727  
   1.728 -
   1.729 -    private static final RuntimePermission SUBCLASS_IMPLEMENTATION_PERMISSION =
   1.730 -                    new RuntimePermission("enableContextClassLoaderOverride");
   1.731 -
   1.732 -    /** cache of subclass security audit results */
   1.733 -    /* Replace with ConcurrentReferenceHashMap when/if it appears in a future
   1.734 -     * release */
   1.735 -    private static class Caches {
   1.736 -        /** cache of subclass security audit results */
   1.737 -        static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
   1.738 -            new ConcurrentHashMap<>();
   1.739 -
   1.740 -        /** queue for WeakReferences to audited subclasses */
   1.741 -        static final ReferenceQueue<Class<?>> subclassAuditsQueue =
   1.742 -            new ReferenceQueue<>();
   1.743 -    }
   1.744 -
   1.745 -    /**
   1.746 -     * Verifies that this (possibly subclass) instance can be constructed
   1.747 -     * without violating security constraints: the subclass must not override
   1.748 -     * security-sensitive non-final methods, or else the
   1.749 -     * "enableContextClassLoaderOverride" RuntimePermission is checked.
   1.750 -     */
   1.751 -    private static boolean isCCLOverridden(Class cl) {
   1.752 -        if (cl == Thread.class)
   1.753 -            return false;
   1.754 -
   1.755 -        processQueue(Caches.subclassAuditsQueue, Caches.subclassAudits);
   1.756 -        WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue);
   1.757 -        Boolean result = Caches.subclassAudits.get(key);
   1.758 -        if (result == null) {
   1.759 -            result = Boolean.valueOf(auditSubclass(cl));
   1.760 -            Caches.subclassAudits.putIfAbsent(key, result);
   1.761 -        }
   1.762 -
   1.763 -        return result.booleanValue();
   1.764 -    }
   1.765 -
   1.766 -    /**
   1.767 -     * Performs reflective checks on given subclass to verify that it doesn't
   1.768 -     * override security-sensitive non-final methods.  Returns true if the
   1.769 -     * subclass overrides any of the methods, false otherwise.
   1.770 -     */
   1.771 -    private static boolean auditSubclass(final Class subcl) {
   1.772 -        Boolean result = AccessController.doPrivileged(
   1.773 -            new PrivilegedAction<Boolean>() {
   1.774 -                public Boolean run() {
   1.775 -                    for (Class cl = subcl;
   1.776 -                         cl != Thread.class;
   1.777 -                         cl = cl.getSuperclass())
   1.778 -                    {
   1.779 -                        try {
   1.780 -                            cl.getDeclaredMethod("getContextClassLoader", new Class[0]);
   1.781 -                            return Boolean.TRUE;
   1.782 -                        } catch (NoSuchMethodException ex) {
   1.783 -                        }
   1.784 -                        try {
   1.785 -                            Class[] params = {ClassLoader.class};
   1.786 -                            cl.getDeclaredMethod("setContextClassLoader", params);
   1.787 -                            return Boolean.TRUE;
   1.788 -                        } catch (NoSuchMethodException ex) {
   1.789 -                        }
   1.790 -                    }
   1.791 -                    return Boolean.FALSE;
   1.792 -                }
   1.793 -            }
   1.794 -        );
   1.795 -        return result.booleanValue();
   1.796 -    }
   1.797 -
   1.798 -    private native static StackTraceElement[][] dumpThreads(Thread[] threads);
   1.799 -    private native static Thread[] getThreads();
   1.800 -
   1.801      /**
   1.802       * Returns the identifier of this Thread.  The thread ID is a positive
   1.803       * <tt>long</tt> number generated when this thread was created.
   1.804 @@ -1710,7 +1303,7 @@
   1.805       * @since 1.5
   1.806       */
   1.807      public long getId() {
   1.808 -        return tid;
   1.809 +        return 0;
   1.810      }
   1.811  
   1.812      /**
   1.813 @@ -1822,7 +1415,7 @@
   1.814       */
   1.815      public State getState() {
   1.816          // get current thread state
   1.817 -        return sun.misc.VM.toThreadState(threadStatus);
   1.818 +        return State.RUNNABLE;
   1.819      }
   1.820  
   1.821      // Added in JSR-166
   1.822 @@ -1902,15 +1495,8 @@
   1.823       * @since 1.5
   1.824       */
   1.825      public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh) {
   1.826 -        SecurityManager sm = System.getSecurityManager();
   1.827 -        if (sm != null) {
   1.828 -            sm.checkPermission(
   1.829 -                new RuntimePermission("setDefaultUncaughtExceptionHandler")
   1.830 -                    );
   1.831 -        }
   1.832 -
   1.833 -         defaultUncaughtExceptionHandler = eh;
   1.834 -     }
   1.835 +        throw new SecurityException();
   1.836 +    }
   1.837  
   1.838      /**
   1.839       * Returns the default handler invoked when a thread abruptly terminates
   1.840 @@ -1933,7 +1519,7 @@
   1.841       */
   1.842      public UncaughtExceptionHandler getUncaughtExceptionHandler() {
   1.843          return uncaughtExceptionHandler != null ?
   1.844 -            uncaughtExceptionHandler : group;
   1.845 +            uncaughtExceptionHandler : null;
   1.846      }
   1.847  
   1.848      /**
   1.849 @@ -1955,81 +1541,4 @@
   1.850          checkAccess();
   1.851          uncaughtExceptionHandler = eh;
   1.852      }
   1.853 -
   1.854 -    /**
   1.855 -     * Dispatch an uncaught exception to the handler. This method is
   1.856 -     * intended to be called only by the JVM.
   1.857 -     */
   1.858 -    private void dispatchUncaughtException(Throwable e) {
   1.859 -        getUncaughtExceptionHandler().uncaughtException(this, e);
   1.860 -    }
   1.861 -
   1.862 -    /**
   1.863 -     * Removes from the specified map any keys that have been enqueued
   1.864 -     * on the specified reference queue.
   1.865 -     */
   1.866 -    static void processQueue(ReferenceQueue<Class<?>> queue,
   1.867 -                             ConcurrentMap<? extends
   1.868 -                             WeakReference<Class<?>>, ?> map)
   1.869 -    {
   1.870 -        Reference<? extends Class<?>> ref;
   1.871 -        while((ref = queue.poll()) != null) {
   1.872 -            map.remove(ref);
   1.873 -        }
   1.874 -    }
   1.875 -
   1.876 -    /**
   1.877 -     *  Weak key for Class objects.
   1.878 -     **/
   1.879 -    static class WeakClassKey extends WeakReference<Class<?>> {
   1.880 -        /**
   1.881 -         * saved value of the referent's identity hash code, to maintain
   1.882 -         * a consistent hash code after the referent has been cleared
   1.883 -         */
   1.884 -        private final int hash;
   1.885 -
   1.886 -        /**
   1.887 -         * Create a new WeakClassKey to the given object, registered
   1.888 -         * with a queue.
   1.889 -         */
   1.890 -        WeakClassKey(Class<?> cl, ReferenceQueue<Class<?>> refQueue) {
   1.891 -            super(cl, refQueue);
   1.892 -            hash = System.identityHashCode(cl);
   1.893 -        }
   1.894 -
   1.895 -        /**
   1.896 -         * Returns the identity hash code of the original referent.
   1.897 -         */
   1.898 -        @Override
   1.899 -        public int hashCode() {
   1.900 -            return hash;
   1.901 -        }
   1.902 -
   1.903 -        /**
   1.904 -         * Returns true if the given object is this identical
   1.905 -         * WeakClassKey instance, or, if this object's referent has not
   1.906 -         * been cleared, if the given object is another WeakClassKey
   1.907 -         * instance with the identical non-null referent as this one.
   1.908 -         */
   1.909 -        @Override
   1.910 -        public boolean equals(Object obj) {
   1.911 -            if (obj == this)
   1.912 -                return true;
   1.913 -
   1.914 -            if (obj instanceof WeakClassKey) {
   1.915 -                Object referent = get();
   1.916 -                return (referent != null) &&
   1.917 -                       (referent == ((WeakClassKey) obj).get());
   1.918 -            } else {
   1.919 -                return false;
   1.920 -            }
   1.921 -        }
   1.922 -    }
   1.923 -
   1.924 -    /* Some private helper methods */
   1.925 -    private native void setPriority0(int newPriority);
   1.926 -    private native void stop0(Object o);
   1.927 -    private native void suspend0();
   1.928 -    private native void resume0();
   1.929 -    private native void interrupt0();
   1.930  }