diff -r acaa256e3f7c src/share/classes/sun/misc/Unsafe.java --- a/src/share/classes/sun/misc/Unsafe.java Fri Aug 16 13:58:43 2013 -0400 +++ b/src/share/classes/sun/misc/Unsafe.java Fri Aug 16 16:12:14 2013 -0700 @@ -186,7 +186,7 @@ public final class Unsafe { *
* Unless the reference x
being stored is either null
* or matches the field type, the results are undefined.
- * If the reference o
is non-null, car marks or
+ * If the reference o
is non-null, card marks or
* other store barriers for that object (if the VM requires them)
* are updated.
* @see #putInt(Object, int, int)
@@ -434,6 +434,68 @@ public final class Unsafe {
public native void putDouble(long address, double x);
/**
+ * Possible storage modes for references.
+ *
+ * The {@link StorageMode#DEFAULT} storage mode uses the JVM's setting for the respective
+ * storage class.
+ */
+ public enum StorageMode {
+ DEFAULT,
+ UNCOMPRESSED_OOP,
+ COMPRESSED_OOP,
+ UNCOMPRESSED_KLASS,
+ COMPRESSED_KLASS;
+
+ static {
+ for (StorageMode mode : StorageMode.values()) {
+ setStorageModeConstant(mode.name(), mode.ordinal());
+ }
+ };
+ }
+
+ /**
+ * Tell the JVM about the storage mode values.
+ */
+ private static native void setStorageModeConstant(String name, int ordinal);
+
+ /**
+ * Fetches a reference value from a given Java variable using the given storage mode.
+ * @see #getInt(Object, long)
+ * @since 1.8
+ */
+ public native Object getObject(Object o, long offset, StorageMode mode);
+
+ /**
+ * Stores a reference value into a given Java variable using the given storage mode.
+ *
+ * Unless the reference x
being stored is either null
+ * or matches the field type, the results are undefined.
+ * If the reference o
is non-null, card marks or
+ * other store barriers for that object (if the VM requires them)
+ * are updated.
+ * @see #putInt(Object, int, int)
+ * @since 1.8
+ */
+ public native void putObject(Object o, long offset, Object x, StorageMode mode);
+
+ /**
+ * Fetches a meta data reference value from a given Java variable using the given storage mode.
+ * @see #getInt(Object, long)
+ * @since 1.8
+ */
+ public native long getMetadata(Object o, long offset, StorageMode mode);
+
+ /**
+ * Stores a meta data reference value into a given Java variable using the given storage mode.
+ *
+ * Unless the reference x
being stored is either null
+ * or matches the field type, the results are undefined.
+ * @see #putInt(Object, int, int)
+ * @since 1.8
+ */
+ public native void putMetadata(Object o, long offset, long x, StorageMode mode);
+
+ /**
* Fetches a native pointer from a given memory address. If the address is
* zero, or does not point into a block obtained from {@link
* #allocateMemory}, the results are undefined.
diff -r acaa256e3f7c test/sun/misc/Unsafe/UnsafeMemoryAccessWithStorageMode.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/misc/Unsafe/UnsafeMemoryAccessWithStorageMode.java Fri Aug 16 16:12:14 2013 -0700
@@ -0,0 +1,218 @@
+/*
+ * Copyright (c) 2013, 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.
+ *
+ * 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.
+ */
+
+/* @test
+ * @bug 8022853
+ * @summary test that we can read and write uncompressed and compressed oops and Klass pointers
+ *
+ * @compile -XDignore.symbol.file UnsafeMemoryAccessWithStorageMode.java
+ *
+ * @run junit/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedKlassPointers UnsafeMemoryAccessWithStorageMode
+ * @run junit/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:-UseCompressedKlassPointers UnsafeMemoryAccessWithStorageMode
+ * @run junit/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:+UseCompressedKlassPointers UnsafeMemoryAccessWithStorageMode
+ * @run junit/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedKlassPointers UnsafeMemoryAccessWithStorageMode
+ */
+
+import org.junit.*;
+
+import static org.junit.Assert.*;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.reflect.*;
+import java.util.*;
+
+import sun.misc.Unsafe;
+import sun.misc.Unsafe.*;
+
+import com.sun.management.HotSpotDiagnosticMXBean;
+
+import sun.management.ManagementFactoryHelper;
+
+public class UnsafeMemoryAccessWithStorageMode {
+
+ private final HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();
+ private final boolean useCompressedOops;
+ private final boolean useCompressedKlassPointers;
+
+ private final List