< prev index next >
src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com
rev 58567 : [mq]: rename-isHidden
@@ -28,10 +28,11 @@
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.misc.VM;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
+import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.util.Set;
/**
@@ -634,10 +635,16 @@
* must preserve all bits of static field offsets.
* @see #getInt(Object, long)
*/
@ForceInline
public long objectFieldOffset(Field f) {
+ if (f == null) {
+ throw new NullPointerException();
+ }
+ if (f.getDeclaringClass().isHidden()) {
+ throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
+ }
return theInternalUnsafe.objectFieldOffset(f);
}
/**
* Reports the location of a given static field, in conjunction with {@link
@@ -656,10 +663,16 @@
* this method reports its result as a long value.
* @see #getInt(Object, long)
*/
@ForceInline
public long staticFieldOffset(Field f) {
+ if (f == null) {
+ throw new NullPointerException();
+ }
+ if (f.getDeclaringClass().isHidden()) {
+ throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f);
+ }
return theInternalUnsafe.staticFieldOffset(f);
}
/**
* Reports the location of a given static field, in conjunction with {@link
@@ -671,10 +684,16 @@
* not be used in any way except as argument to the get and put routines in
* this class.
*/
@ForceInline
public Object staticFieldBase(Field f) {
+ if (f == null) {
+ throw new NullPointerException();
+ }
+ if (f.getDeclaringClass().isHidden()) {
+ throw new UnsupportedOperationException("can't get base address on a hidden class: " + f);
+ }
return theInternalUnsafe.staticFieldBase(f);
}
/**
* Detects if the given class may need to be initialized. This is often
@@ -818,15 +837,20 @@
* <li>Utf8: a string (must have suitable syntax if used as signature or name)
* <li>Class: any java.lang.Class object
* <li>String: any object (not just a java.lang.String)
* <li>InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments
* </ul>
+ *
+ * @deprecated Use the {@link java.lang.invoke.MethodHandles.Lookup#defineHiddenClass(byte[], boolean, MethodHandles.Lookup.ClassOption...)}
+ * method.
+ *
* @param hostClass context for linkage, access control, protection domain, and class loader
* @param data bytes of a class file
* @param cpPatches where non-null entries exist, they replace corresponding CP entries in data
*/
@ForceInline
+ @Deprecated(since = "15", forRemoval = false)
public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {
return theInternalUnsafe.defineAnonymousClass(hostClass, data, cpPatches);
}
/**
< prev index next >