< prev index next >

test/runtime/Unsafe/GetPutObject.java

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @summary Verify behaviour of Unsafe.get/putObject
  27  * @library /testlibrary
  28  * @modules java.base/sun.misc
  29  *          java.management
  30  * @run main GetPutObject
  31  */
  32 
  33 import java.lang.reflect.Field;
  34 import com.oracle.java.testlibrary.*;
  35 import sun.misc.Unsafe;
  36 import static com.oracle.java.testlibrary.Asserts.*;
  37 
  38 public class GetPutObject {
  39     public static void main(String args[]) throws Exception {
  40         Unsafe unsafe = Utils.getUnsafe();
  41         Test t = new Test();
  42         Object o = new Object();
  43         Field field = Test.class.getField("o");
  44 
  45         long offset = unsafe.objectFieldOffset(field);
  46         assertEquals(t.o, unsafe.getObject(t, offset));
  47 
  48         unsafe.putObject(t, offset, o);
  49         assertEquals(o, unsafe.getObject(t, offset));
  50 
  51         Object arrayObject[] = { unsafe, null, new Object() };
  52         int scale = unsafe.arrayIndexScale(arrayObject.getClass());
  53         offset = unsafe.arrayBaseOffset(arrayObject.getClass());
  54         for (int i = 0; i < arrayObject.length; i++) {
  55             assertEquals(unsafe.getObject(arrayObject, offset), arrayObject[i]);
  56             offset += scale;


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @summary Verify behaviour of Unsafe.get/putObject
  27  * @library /testlibrary
  28  * @modules java.base/sun.misc
  29  *          java.management
  30  * @run main GetPutObject
  31  */
  32 
  33 import java.lang.reflect.Field;
  34 import jdk.test.lib.*;
  35 import sun.misc.Unsafe;
  36 import static jdk.test.lib.Asserts.*;
  37 
  38 public class GetPutObject {
  39     public static void main(String args[]) throws Exception {
  40         Unsafe unsafe = Utils.getUnsafe();
  41         Test t = new Test();
  42         Object o = new Object();
  43         Field field = Test.class.getField("o");
  44 
  45         long offset = unsafe.objectFieldOffset(field);
  46         assertEquals(t.o, unsafe.getObject(t, offset));
  47 
  48         unsafe.putObject(t, offset, o);
  49         assertEquals(o, unsafe.getObject(t, offset));
  50 
  51         Object arrayObject[] = { unsafe, null, new Object() };
  52         int scale = unsafe.arrayIndexScale(arrayObject.getClass());
  53         offset = unsafe.arrayBaseOffset(arrayObject.getClass());
  54         for (int i = 0; i < arrayObject.length; i++) {
  55             assertEquals(unsafe.getObject(arrayObject, offset), arrayObject[i]);
  56             offset += scale;
< prev index next >