8140606: Update library code to use internal Unsafe

Reviewed-by: alanb, mchung, psandoz, weijun
This commit is contained in:
Chris Hegarty 2015-11-11 11:31:21 +00:00
parent ce4153b48f
commit f9c17f72ba
11 changed files with 12 additions and 135 deletions

View File

@ -65,7 +65,6 @@ import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
import com.sun.corba.se.spi.logging.CORBALogDomains;
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
import com.sun.corba.se.impl.corba.AsynchInvoke;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
public class RequestImpl
extends Request
@ -256,7 +255,7 @@ public class RequestImpl
public synchronized void send_deferred()
{
AsynchInvoke invokeObject = new AsynchInvoke(_orb, this, false);
new ManagedLocalsThread(invokeObject).start();
new sun.misc.ManagedLocalsThread(invokeObject).start();
}
public synchronized boolean poll_response()

View File

@ -112,7 +112,6 @@ import com.sun.corba.se.impl.util.JDKBridge;
import com.sun.corba.se.impl.logging.UtilSystemException;
import com.sun.corba.se.spi.logging.CORBALogDomains;
import sun.corba.SharedSecrets;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
/**
@ -752,7 +751,7 @@ public class Util implements javax.rmi.CORBA.UtilDelegate
}
}
class KeepAlive extends ManagedLocalsThread
class KeepAlive extends sun.misc.ManagedLocalsThread
{
boolean quit = false;

View File

@ -103,7 +103,6 @@ import com.sun.corba.se.impl.orbutil.concurrent.Sync ;
import com.sun.corba.se.impl.orbutil.concurrent.SyncUtil ;
import com.sun.corba.se.impl.orbutil.concurrent.ReentrantMutex ;
import com.sun.corba.se.impl.orbutil.concurrent.CondVar ;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
/**
* POAImpl is the implementation of the Portable Object Adapter. It
@ -517,7 +516,7 @@ public class POAImpl extends ObjectAdapterBase implements POA
// Converted from anonymous class to local class
// so that we can call performDestroy() directly.
static class DestroyThread extends ManagedLocalsThread {
static class DestroyThread extends sun.misc.ManagedLocalsThread {
private boolean wait ;
private boolean etherealize ;
private boolean debug ;

View File

@ -48,7 +48,6 @@ import com.sun.corba.se.spi.protocol.PIHandler ;
import com.sun.corba.se.impl.logging.POASystemException ;
import com.sun.corba.se.impl.orbutil.ORBUtility ;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
/** POAManagerImpl is the implementation of the POAManager interface.
* Its public methods are activate(), hold_requests(), discard_requests()
@ -358,7 +357,7 @@ public class POAManagerImpl extends org.omg.CORBA.LocalObject implements
if (wait_for_completion)
deactivator.run() ;
else {
Thread thr = new ManagedLocalsThread(deactivator) ;
Thread thr = new sun.misc.ManagedLocalsThread(deactivator) ;
thr.start() ;
}
} finally {

View File

@ -49,7 +49,6 @@ import com.sun.corba.se.impl.javax.rmi.CORBA.Util ;
import com.sun.corba.se.spi.oa.OAInvocationInfo ;
import com.sun.corba.se.spi.oa.NullServant ;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
/** Implementation of POARequesHandler that provides policy specific
* operations on the POA.
@ -303,7 +302,7 @@ public class POAPolicyMediatorImpl_R_USM extends POAPolicyMediatorBase_R {
throw new WrongPolicy();
}
class Etherealizer extends ManagedLocalsThread {
class Etherealizer extends sun.misc.ManagedLocalsThread {
private POAPolicyMediatorImpl_R_USM mediator ;
private ActiveObjectMap.Key key ;
private AOMEntry entry ;

View File

@ -165,7 +165,6 @@ import com.sun.corba.se.impl.util.Utility;
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
import com.sun.corba.se.impl.copyobject.CopierManagerImpl;
import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
/**
* The JavaIDL ORB implementation.
@ -692,7 +691,7 @@ public class ORBImpl extends com.sun.corba.se.spi.orb.ORB
for (int i = 0; i < req.length; i++) {
AsynchInvoke invokeObject = new AsynchInvoke( this,
(com.sun.corba.se.impl.corba.RequestImpl)req[i], true);
new ManagedLocalsThread(invokeObject).start();
new sun.misc.ManagedLocalsThread(invokeObject).start();
}
}

View File

@ -54,7 +54,6 @@ import com.sun.corba.se.spi.monitoring.LongMonitoredAttributeBase;
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
import com.sun.corba.se.impl.orbutil.ORBConstants;
import com.sun.corba.se.spi.logging.CORBALogDomains;
import com.sun.corba.se.impl.transport.ManagedLocalsThread;
public class ThreadPoolImpl implements ThreadPool
{
@ -460,7 +459,7 @@ public class ThreadPoolImpl implements ThreadPool
}
private class WorkerThread extends ManagedLocalsThread implements Closeable
private class WorkerThread extends sun.misc.ManagedLocalsThread implements Closeable
{
private Work currentWork;
private int threadId = 0; // unique id for the thread

View File

@ -1,116 +0,0 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.corba.se.impl.transport;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* A thread that has it's thread locals, and inheritable thread
* locals erased on construction.
*/
public class ManagedLocalsThread extends Thread {
private static final Unsafe UNSAFE;
private static final long THREAD_LOCALS;
private static final long INHERITABLE_THREAD_LOCALS;
public ManagedLocalsThread () {
super();
}
public ManagedLocalsThread(String name) {
super(name);
eraseThreadLocals();
}
public ManagedLocalsThread(Runnable target) {
super(target);
eraseThreadLocals();
}
public ManagedLocalsThread(Runnable target, String name) {
super(target, name);
eraseThreadLocals();
}
public ManagedLocalsThread(ThreadGroup group, Runnable target, String name) {
super(group, target, name);
eraseThreadLocals();
}
public ManagedLocalsThread(ThreadGroup group, String name) {
super(group, name);
eraseThreadLocals();
}
/**
* Drops all thread locals (and inherited thread locals).
*/
public final void eraseThreadLocals() {
UNSAFE.putObject(this, THREAD_LOCALS, null);
UNSAFE.putObject(this, INHERITABLE_THREAD_LOCALS, null);
}
private static Unsafe getUnsafe() {
PrivilegedAction<Unsafe> pa = () -> {
Class<?> unsafeClass = sun.misc.Unsafe.class;
try {
Field f = unsafeClass.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
} catch (Exception e) {
throw new Error(e);
}
};
return AccessController.doPrivileged(pa);
}
private static long getThreadFieldOffset(String fieldName) {
PrivilegedAction<Long> pa = () -> {
Class<?> t = Thread.class;
long fieldOffset;
try {
fieldOffset = UNSAFE.objectFieldOffset(t
.getDeclaredField("inheritableThreadLocals"));
} catch (Exception e) {
throw new Error(e);
}
return fieldOffset;
};
return AccessController.doPrivileged(pa);
}
static {
UNSAFE = getUnsafe();
try {
THREAD_LOCALS = getThreadFieldOffset("threadLocals");
INHERITABLE_THREAD_LOCALS = getThreadFieldOffset("inheritableThreadLocals");
} catch (Exception e) {
throw new Error(e);
}
}
}

View File

@ -57,7 +57,7 @@ import com.sun.corba.se.impl.orbutil.ORBUtility;
*/
class SelectorImpl
extends
ManagedLocalsThread
sun.misc.ManagedLocalsThread
implements
com.sun.corba.se.pept.transport.Selector
{

View File

@ -36,7 +36,7 @@ import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;
import sun.misc.Unsafe ;
import jdk.internal.misc.Unsafe ;
import sun.reflect.ReflectionFactory ;
/** This class provides the methods for fundamental JVM operations
@ -120,7 +120,7 @@ public final class Bridge
Field fld = null ;
try {
Class unsafeClass = sun.misc.Unsafe.class ;
Class unsafeClass = jdk.internal.misc.Unsafe.class ;
fld = unsafeClass.getDeclaredField( "theUnsafe" ) ;
fld.setAccessible( true ) ;
return fld ;

View File

@ -26,7 +26,7 @@
package sun.corba;
import com.sun.corba.se.impl.io.ValueUtility;
import sun.misc.Unsafe;
import jdk.internal.misc.Unsafe;
import java.lang.reflect.Field;
import java.security.AccessController;
@ -48,7 +48,7 @@ public class SharedSecrets {
private static Unsafe getUnsafe() {
PrivilegedAction<Unsafe> pa = () -> {
Class<?> unsafeClass = sun.misc.Unsafe.class ;
Class<?> unsafeClass = jdk.internal.misc.Unsafe.class ;
try {
Field f = unsafeClass.getDeclaredField("theUnsafe");
f.setAccessible(true);