changeset 668:d690f489ca0b jdk9-b61

Merge
author lana
date Fri, 17 Apr 2015 10:25:35 -0700
parents 97575cd00636 (current diff) d0315150c39d (diff)
children d27f7e0a7aca
files
diffstat 11 files changed, 184 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/corba/RequestImpl.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/corba/RequestImpl.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -65,6 +65,7 @@
 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
@@ -255,7 +256,7 @@
     public synchronized void send_deferred()
     {
         AsynchInvoke invokeObject = new AsynchInvoke(_orb, this, false);
-        new Thread(invokeObject).start();
+        new ManagedLocalsThread(invokeObject).start();
     }
 
     public synchronized boolean poll_response()
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/io/IIOPInputStream.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/io/IIOPInputStream.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -1768,43 +1768,59 @@
             switch (field.getTypeCode()) {
                 case 'B':
                     byte byteValue = orbStream.read_octet();
-                    bridge.putByte( o, field.getFieldID(), byteValue ) ;
-                    //reflective code: field.getField().setByte( o, byteValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putByte( o, field.getFieldID(), byteValue ) ;
+                        //reflective code: field.getField().setByte( o, byteValue ) ;
+                    }
                     break;
                 case 'Z':
                     boolean booleanValue = orbStream.read_boolean();
-                    bridge.putBoolean( o, field.getFieldID(), booleanValue ) ;
-                    //reflective code: field.getField().setBoolean( o, booleanValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putBoolean( o, field.getFieldID(), booleanValue ) ;
+                        //reflective code: field.getField().setBoolean( o, booleanValue ) ;
+                    }
                     break;
                 case 'C':
                     char charValue = orbStream.read_wchar();
-                    bridge.putChar( o, field.getFieldID(), charValue ) ;
-                    //reflective code: field.getField().setChar( o, charValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putChar( o, field.getFieldID(), charValue ) ;
+                        //reflective code: field.getField().setChar( o, charValue ) ;
+                    }
                     break;
                 case 'S':
                     short shortValue = orbStream.read_short();
-                    bridge.putShort( o, field.getFieldID(), shortValue ) ;
-                    //reflective code: field.getField().setShort( o, shortValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putShort( o, field.getFieldID(), shortValue ) ;
+                        //reflective code: field.getField().setShort( o, shortValue ) ;
+                    }
                     break;
                 case 'I':
                     int intValue = orbStream.read_long();
-                    bridge.putInt( o, field.getFieldID(), intValue ) ;
-                    //reflective code: field.getField().setInt( o, intValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putInt( o, field.getFieldID(), intValue ) ;
+                        //reflective code: field.getField().setInt( o, intValue ) ;
+                    }
                     break;
                 case 'J':
                     long longValue = orbStream.read_longlong();
-                    bridge.putLong( o, field.getFieldID(), longValue ) ;
-                    //reflective code: field.getField().setLong( o, longValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putLong( o, field.getFieldID(), longValue ) ;
+                        //reflective code: field.getField().setLong( o, longValue ) ;
+                    }
                     break;
                 case 'F' :
                     float floatValue = orbStream.read_float();
-                    bridge.putFloat( o, field.getFieldID(), floatValue ) ;
-                    //reflective code: field.getField().setFloat( o, floatValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putFloat( o, field.getFieldID(), floatValue ) ;
+                        //reflective code: field.getField().setFloat( o, floatValue ) ;
+                    }
                     break;
                 case 'D' :
                     double doubleValue = orbStream.read_double();
-                    bridge.putDouble( o, field.getFieldID(), doubleValue ) ;
-                    //reflective code: field.getField().setDouble( o, doubleValue ) ;
+                    if (field.getField() != null) {
+                        bridge.putDouble( o, field.getFieldID(), doubleValue ) ;
+                        //reflective code: field.getField().setDouble( o, doubleValue ) ;
+                    }
                     break;
                 default:
                     // XXX I18N, logging needed.
@@ -2217,9 +2233,6 @@
 
         if (o != null) {
             for (int i = 0; i < primFields; ++i) {
-                if (fields[i].getField() == null)
-                    continue;
-
                 inputPrimitiveField(o, cl, fields[i]);
             }
         }
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/io/OutputStreamHook.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/io/OutputStreamHook.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -32,6 +32,7 @@
 package com.sun.corba.se.impl.io;
 
 import java.io.IOException;
+import java.io.NotActiveException;
 import java.io.OutputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectOutput;
@@ -154,7 +155,9 @@
 
     public ObjectOutputStream.PutField putFields()
         throws IOException {
-        putFields = new HookPutFields();
+        if (putFields == null) {
+            putFields = new HookPutFields();
+        }
         return putFields;
     }
 
@@ -175,8 +178,11 @@
         throws IOException {
 
         writeObjectState.defaultWriteObject(this);
-
-        putFields.write(this);
+        if (putFields != null) {
+            putFields.write(this);
+        } else {
+            throw new NotActiveException("no current PutField object");
+        }
     }
 
     abstract org.omg.CORBA_2_3.portable.OutputStream getOrbStream();
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -112,6 +112,8 @@
 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;
+
 
 /**
  * Provides utility methods that can be used by stubs and ties to
@@ -750,7 +752,7 @@
     }
 }
 
-class KeepAlive extends Thread
+class KeepAlive extends ManagedLocalsThread
 {
     boolean quit = false;
 
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAImpl.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAImpl.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -103,6 +103,7 @@
 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
@@ -516,7 +517,7 @@
 
     // Converted from anonymous class to local class
     // so that we can call performDestroy() directly.
-    static class DestroyThread extends Thread {
+    static class DestroyThread extends ManagedLocalsThread {
         private boolean wait ;
         private boolean etherealize ;
         private boolean debug ;
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAManagerImpl.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAManagerImpl.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -48,6 +48,7 @@
 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()
@@ -357,7 +358,7 @@
             if (wait_for_completion)
                 deactivator.run() ;
             else {
-                Thread thr = new Thread(deactivator) ;
+                Thread thr = new ManagedLocalsThread(deactivator) ;
                 thr.start() ;
             }
         } finally {
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorImpl_R_USM.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorImpl_R_USM.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -26,7 +26,6 @@
 package com.sun.corba.se.impl.oa.poa ;
 
 import java.util.Set ;
-
 import org.omg.CORBA.SystemException ;
 
 import org.omg.PortableServer.ServantActivator ;
@@ -50,6 +49,7 @@
 
 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,13 +303,14 @@
         throw new WrongPolicy();
     }
 
-    class Etherealizer extends Thread {
+    class Etherealizer extends ManagedLocalsThread {
         private POAPolicyMediatorImpl_R_USM mediator ;
         private ActiveObjectMap.Key key ;
         private AOMEntry entry ;
         private Servant servant ;
         private boolean debug ;
 
+
         public Etherealizer( POAPolicyMediatorImpl_R_USM mediator,
             ActiveObjectMap.Key key, AOMEntry entry, Servant servant,
             boolean debug )
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/orb/ORBImpl.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/orb/ORBImpl.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -165,6 +165,7 @@
 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.
@@ -691,7 +692,7 @@
         for (int i = 0; i < req.length; i++) {
             AsynchInvoke invokeObject = new AsynchInvoke( this,
                 (com.sun.corba.se.impl.corba.RequestImpl)req[i], true);
-            new Thread(invokeObject).start();
+            new ManagedLocalsThread(invokeObject).start();
         }
     }
 
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/orbutil/threadpool/ThreadPoolImpl.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/orbutil/threadpool/ThreadPoolImpl.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -54,6 +54,7 @@
 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
 {
@@ -459,7 +460,7 @@
     }
 
 
-    private class WorkerThread extends Thread implements Closeable
+    private class WorkerThread extends ManagedLocalsThread implements Closeable
     {
         private Work currentWork;
         private int threadId = 0; // unique id for the thread
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/transport/ManagedLocalsThread.java	Fri Apr 17 10:25:35 2015 -0700
@@ -0,0 +1,116 @@
+/*
+ * 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);
+        }
+    }
+}
--- a/src/java.corba/share/classes/com/sun/corba/se/impl/transport/SelectorImpl.java	Fri Apr 17 09:59:42 2015 -0700
+++ b/src/java.corba/share/classes/com/sun/corba/se/impl/transport/SelectorImpl.java	Fri Apr 17 10:25:35 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -57,7 +57,7 @@
  */
 class SelectorImpl
     extends
-        Thread
+        ManagedLocalsThread
     implements
         com.sun.corba.se.pept.transport.Selector
 {