+ * All of these permissions are required to obtain and correctly initialize + * the instance of Bridge. No security checks are performed on calls + * made to Bridge instance methods, so access to the Bridge instance + * must be protected. + *
+ * This class is a singleton (per ClassLoader of course). Access to the
+ * instance is obtained through the Bridge.get() method.
+ */
+public final class Bridge
+{
+ private static final Permission getBridgePermission =
+ new BridgePermission("getBridge");
+ private static Bridge bridge = null ;
+
+ /** Access to Unsafe to read/write fields. */
+ private static final Unsafe unsafe = AccessController.doPrivileged(
+ (PrivilegedAction
+ * The first two parameters are interpreted exactly as with
+ * {@link #getInt(Object, long)} to refer to a specific
+ * Java field. The given value is stored into that field.
+ *
+ * The field must be of the same type as the method
+ * parameter
+ *
+ * @return The singleton instance of the Bridge class
+ * @throws SecurityException if the caller does not have the
+ * required permissions and the caller has a non-null security manager.
+ */
+ public static final synchronized Bridge get()
+ {
+ SecurityManager sman = System.getSecurityManager() ;
+ if (sman != null)
+ sman.checkPermission( getBridgePermission ) ;
+
+ if (bridge == null) {
+ bridge = new Bridge() ;
+ }
+
+ return bridge ;
+ }
+
+ /** Returns true if the loader that loaded the frame's declaring class
+ * is a user loader (if it is not the platform class loader or one of
+ * its ancestor).
+ */
+ private boolean isUserLoader(StackFrame sf) {
+ ClassLoader cl = sf.getDeclaringClass().getClassLoader();
+ if (cl == null) return false;
+ ClassLoader p = ClassLoader.getPlatformClassLoader();
+ while (cl != p && p != null) p = p.getParent();
+ return cl != p;
+ }
+
+ private Optionalo
at the given offset.
+ * The result is undefined unless the offset was obtained from
+ * {@link #objectFieldOffset} on the {@link java.lang.reflect.Field}
+ * of some Java field and the object referred to by o
+ * is of a class compatible with that field's class.
+ * @param o Java heap object in which the field from which the offset
+ * was obtained resides
+ * @param offset indication of where the field resides in a Java heap
+ * object
+ * @return the value fetched from the indicated Java field
+ * @throws RuntimeException No defined exceptions are thrown, not even
+ * {@link NullPointerException}
+ */
+ public final int getInt(Object o, long offset)
+ {
+ return unsafe.getInt( o, offset ) ;
+ }
+
+ /**
+ * Stores a value into a given Java field.
+ * x
.
+ *
+ * @param o Java heap object in which the field resides, if any, else
+ * null
+ * @param offset indication of where the field resides in a Java heap
+ * object.
+ * @param x the value to store into the indicated Java field
+ * @throws RuntimeException No defined exceptions are thrown, not even
+ * {@link NullPointerException}
+ */
+ public final void putInt(Object o, long offset, int x)
+ {
+ unsafe.putInt( o, offset, x ) ;
+ }
+
+ /**
+ * @see #getInt(Object, long)
+ */
+ public final Object getObject(Object o, long offset)
+ {
+ return unsafe.getObject( o, offset ) ;
+ }
+
+ /**
+ * @see #putInt(Object, long, int)
+ */
+ public final void putObject(Object o, long offset, Object x)
+ {
+ unsafe.putObject( o, offset, x ) ;
+ }
+
+ /** @see #getInt(Object, long) */
+ public final boolean getBoolean(Object o, long offset)
+ {
+ return unsafe.getBoolean( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putBoolean(Object o, long offset, boolean x)
+ {
+ unsafe.putBoolean( o, offset, x ) ;
+ }
+ /** @see #getInt(Object, long) */
+ public final byte getByte(Object o, long offset)
+ {
+ return unsafe.getByte( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putByte(Object o, long offset, byte x)
+ {
+ unsafe.putByte( o, offset, x ) ;
+ }
+ /** @see #getInt(Object, long) */
+ public final short getShort(Object o, long offset)
+ {
+ return unsafe.getShort( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putShort(Object o, long offset, short x)
+ {
+ unsafe.putShort( o, offset, x ) ;
+ }
+ /** @see #getInt(Object, long) */
+ public final char getChar(Object o, long offset)
+ {
+ return unsafe.getChar( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putChar(Object o, long offset, char x)
+ {
+ unsafe.putChar( o, offset, x ) ;
+ }
+ /** @see #getInt(Object, long) */
+ public final long getLong(Object o, long offset)
+ {
+ return unsafe.getLong( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putLong(Object o, long offset, long x)
+ {
+ unsafe.putLong( o, offset, x ) ;
+ }
+ /** @see #getInt(Object, long) */
+ public final float getFloat(Object o, long offset)
+ {
+ return unsafe.getFloat( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putFloat(Object o, long offset, float x)
+ {
+ unsafe.putFloat( o, offset, x ) ;
+ }
+ /** @see #getInt(Object, long) */
+ public final double getDouble(Object o, long offset)
+ {
+ return unsafe.getDouble( o, offset ) ;
+ }
+ /** @see #putInt(Object, long, int) */
+ public final void putDouble(Object o, long offset, double x)
+ {
+ unsafe.putDouble( o, offset, x ) ;
+ }
+
+ /**
+ * This constant differs from all results that will ever be returned from
+ * {@link #objectFieldOffset}.
+ */
+ public static final long INVALID_FIELD_OFFSET = -1;
+
+ /**
+ * Returns the offset of a non-static field.
+ */
+ public final long objectFieldOffset(Field f)
+ {
+ return unsafe.objectFieldOffset( f ) ;
+ }
+
+ /**
+ * Returns the offset of a static field.
+ */
+ public final long staticFieldOffset(Field f)
+ {
+ return unsafe.staticFieldOffset( f ) ;
+ }
+
+ /**
+ + * Returns the location of a given static field.
+ + */
+ public final Object staticFieldBase(Field f) {
+ return unsafe.staticFieldBase(f);
+ }
+
+ /**
+ * Ensure that the class has been initalized.
+ * @param cl the class to ensure is initialized
+ */
+ public final void ensureClassInitialized(Class> cl) {
+ try {
+ MethodHandles.lookup().in(cl).ensureInitialized(cl);
+ } catch (IllegalAccessException ignored) {
+ // Class is accessible to this lookup
+ }
+ }
+
+
+ /** Throw the exception.
+ * The exception may be an undeclared checked exception.
+ */
+ public final void throwException(Throwable ee)
+ {
+ unsafe.throwException( ee ) ;
+ }
+
+ /**
+ * Obtain a constructor for Class cl.
+ * This is used to create a constructor for Serializable classes that
+ * construct an instance of the Serializable class using the
+ * no args constructor of the first non-Serializable superclass
+ * of the Serializable class.
+ */
+ public final Constructor> newConstructorForSerialization( Class> cl ) {
+ return reflectionFactory.newConstructorForSerialization( cl ) ;
+ }
+
+ public final Constructor> newConstructorForExternalization(Class> cl) {
+ return reflectionFactory.newConstructorForExternalization( cl ) ;
+ }
+
+ /**
+ * Returns true if the given class defines a static initializer method,
+ * false otherwise.
+ */
+ public final boolean hasStaticInitializerForSerialization(Class> cl) {
+ return reflectionFactory.hasStaticInitializerForSerialization(cl);
+ }
+
+ public final MethodHandle writeObjectForSerialization(Class> cl) {
+ return reflectionFactory.writeObjectForSerialization(cl);
+ }
+
+ public final MethodHandle readObjectForSerialization(Class> cl) {
+ return reflectionFactory.readObjectForSerialization(cl);
+ }
+
+ public final MethodHandle readObjectNoDataForSerialization(Class> cl) {
+ return reflectionFactory.readObjectNoDataForSerialization(cl);
+ }
+
+ public final MethodHandle readResolveForSerialization(Class> cl) {
+ return reflectionFactory.readResolveForSerialization(cl);
+ }
+
+ public final MethodHandle writeReplaceForSerialization(Class> cl) {
+ return reflectionFactory.writeReplaceForSerialization(cl);
+ }
+
+ /**
+ * Return a new OptionalDataException instance.
+ * @return a new OptionalDataException instance
+ */
+ public final OptionalDataException newOptionalDataExceptionForSerialization(boolean bool) {
+ return reflectionFactory.newOptionalDataExceptionForSerialization(bool);
+ }
+
+}
diff --git a/src/main/java17/sun/corba/SharedSecrets.java b/src/main/java17/sun/corba/SharedSecrets.java
new file mode 100644
index 00000000..507a7751
--- /dev/null
+++ b/src/main/java17/sun/corba/SharedSecrets.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012, 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 sun.corba;
+
+import java.lang.invoke.MethodHandles;
+
+import com.sun.corba.se.impl.io.ValueUtility;
+
+/** A repository of "shared secrets", which are a mechanism for
+ calling implementation-private methods in another package without
+ using reflection. A package-private class implements a public
+ interface and provides the ability to call package-private methods
+ within that package; the object implementing that interface is
+ provided through a third package to which access is restricted.
+ This framework avoids the primary disadvantage of using reflection
+ for this purpose, namely the loss of compile-time checking. */
+
+// SharedSecrets cloned in corba repo to avoid build issues
+public class SharedSecrets {
+
+ private static JavaCorbaAccess javaCorbaAccess;
+
+ public static JavaCorbaAccess getJavaCorbaAccess() {
+ if (javaCorbaAccess == null) {
+ // Ensure ValueUtility is initialized; we know that that class
+ // provides the shared secret
+ try {
+ MethodHandles.lookup().in(ValueUtility.class).ensureInitialized(ValueUtility.class);
+ } catch (IllegalAccessException ignored) {
+ // Class is accessible to this lookup
+ }
+ }
+ return javaCorbaAccess;
+ }
+
+ public static void setJavaCorbaAccess(JavaCorbaAccess access) {
+ javaCorbaAccess = access;
+ }
+
+}
diff --git a/src/share/classes/sun/corba/Bridge.java b/src/share/classes/sun/corba/Bridge.java
index 23521aea..f826d00f 100644
--- a/src/share/classes/sun/corba/Bridge.java
+++ b/src/share/classes/sun/corba/Bridge.java
@@ -320,7 +320,7 @@ public final Object staticFieldBase(Field f) {
* @param cl the class to ensure is initialized
*/
public final void ensureClassInitialized(Class> cl) {
- unsafe.ensureClassInitialized(cl);
+ unsafe.ensureClassInitialized(cl); // This method was deprecated in JDK15 and removed in JDK22 so it must be overriden by MR version of this class.
}
diff --git a/src/share/classes/sun/corba/SharedSecrets.java b/src/share/classes/sun/corba/SharedSecrets.java
index cd9078e1..16e41360 100644
--- a/src/share/classes/sun/corba/SharedSecrets.java
+++ b/src/share/classes/sun/corba/SharedSecrets.java
@@ -64,7 +64,7 @@ public static JavaCorbaAccess getJavaCorbaAccess() {
if (javaCorbaAccess == null) {
// Ensure ValueUtility is initialized; we know that that class
// provides the shared secret
- unsafe.ensureClassInitialized(ValueUtility.class);
+ unsafe.ensureClassInitialized(ValueUtility.class); // This method was deprecated in JDK15 and removed in JDK22 so it must be overriden by MR version of this class.
}
return javaCorbaAccess;
}