diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java @ 19309:c386ace07981

Truffle: move unsafe access methods out of CompilerDirectives
author Andreas Woess <andreas.woess@oracle.com>
date Wed, 11 Feb 2015 18:19:40 +0100
parents f7375de5eaa0
children 9c4168877444
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java	Wed Feb 11 15:47:14 2015 +0100
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java	Wed Feb 11 18:19:40 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -25,11 +25,8 @@
 package com.oracle.truffle.api;
 
 import java.lang.annotation.*;
-import java.lang.reflect.*;
 import java.util.concurrent.*;
 
-import sun.misc.*;
-
 /**
  * Directives that influence the optimizations of the Truffle compiler. All of the operations have
  * no effect when executed in the Truffle interpreter.
@@ -42,22 +39,6 @@
     public static final double SLOWPATH_PROBABILITY = 0.0001;
     public static final double FASTPATH_PROBABILITY = 1.0 - SLOWPATH_PROBABILITY;
 
-    private static final Unsafe UNSAFE = getUnsafe();
-
-    private static Unsafe getUnsafe() {
-        try {
-            return Unsafe.getUnsafe();
-        } catch (SecurityException e) {
-        }
-        try {
-            Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe");
-            theUnsafeInstance.setAccessible(true);
-            return (Unsafe) theUnsafeInstance.get(Unsafe.class);
-        } catch (Exception e) {
-            throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", e);
-        }
-    }
-
     /**
      * Directive for the compiler to discontinue compilation at this code position and instead
      * insert a transfer to the interpreter.
@@ -203,464 +184,6 @@
     }
 
     /**
-     * Casts the given value to the value of the given type without any checks. The class must
-     * evaluate to a constant. The condition parameter gives a hint to the compiler under which
-     * circumstances this cast can be moved to an earlier location in the program.
-     *
-     * @param value the value that is known to have the specified type
-     * @param type the specified new type of the value
-     * @param condition the condition that makes this cast safe also at an earlier location of the
-     *            program
-     * @return the value to be casted to the new type
-     */
-    @Deprecated
-    public static <T> T unsafeCast(Object value, Class<T> type, boolean condition) {
-        return unsafeCast(value, type, condition, false);
-    }
-
-    /**
-     * Casts the given value to the value of the given type without any checks. The class must
-     * evaluate to a constant. The condition parameter gives a hint to the compiler under which
-     * circumstances this cast can be moved to an earlier location in the program.
-     *
-     * @param value the value that is known to have the specified type
-     * @param type the specified new type of the value
-     * @param condition the condition that makes this cast safe also at an earlier location of the
-     *            program
-     * @param nonNull whether value is known to never be null
-     * @return the value to be casted to the new type
-     */
-    @Deprecated
-    @SuppressWarnings("unchecked")
-    public static <T> T unsafeCast(Object value, Class<T> type, boolean condition, boolean nonNull) {
-        return (T) value;
-    }
-
-    /**
-     * Unsafe access to a boolean value within an object. The condition parameter gives a hint to
-     * the compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static boolean unsafeGetBoolean(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getBoolean(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a byte value within an object. The condition parameter gives a hint to the
-     * compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static byte unsafeGetByte(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getByte(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a short value within an object. The condition parameter gives a hint to the
-     * compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static short unsafeGetShort(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getShort(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to an int value within an object. The condition parameter gives a hint to the
-     * compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static int unsafeGetInt(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getInt(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a long value within an object. The condition parameter gives a hint to the
-     * compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static long unsafeGetLong(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getLong(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a float value within an object. The condition parameter gives a hint to the
-     * compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static float unsafeGetFloat(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getFloat(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a double value within an object. The condition parameter gives a hint to the
-     * compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static double unsafeGetDouble(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getDouble(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to an Object value within an object. The condition parameter gives a hint to
-     * the compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static Object unsafeGetObject(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getObject(receiver, offset);
-    }
-
-    /**
-     * Write a boolean value within an object. The location identity gives a hint to the compiler
-     * for improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutBoolean(Object receiver, long offset, boolean value, Object locationIdentity) {
-        UNSAFE.putBoolean(receiver, offset, value);
-    }
-
-    /**
-     * Write a byte value within an object. The location identity gives a hint to the compiler for
-     * improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutByte(Object receiver, long offset, byte value, Object locationIdentity) {
-        UNSAFE.putByte(receiver, offset, value);
-    }
-
-    /**
-     * Write a short value within an object. The location identity gives a hint to the compiler for
-     * improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutShort(Object receiver, long offset, short value, Object locationIdentity) {
-        UNSAFE.putShort(receiver, offset, value);
-    }
-
-    /**
-     * Write an int value within an object. The location identity gives a hint to the compiler for
-     * improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutInt(Object receiver, long offset, int value, Object locationIdentity) {
-        UNSAFE.putInt(receiver, offset, value);
-    }
-
-    /**
-     * Write a long value within an object. The location identity gives a hint to the compiler for
-     * improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutLong(Object receiver, long offset, long value, Object locationIdentity) {
-        UNSAFE.putLong(receiver, offset, value);
-    }
-
-    /**
-     * Write a float value within an object. The location identity gives a hint to the compiler for
-     * improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutFloat(Object receiver, long offset, float value, Object locationIdentity) {
-        UNSAFE.putFloat(receiver, offset, value);
-    }
-
-    /**
-     * Write a double value within an object. The location identity gives a hint to the compiler for
-     * improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutDouble(Object receiver, long offset, double value, Object locationIdentity) {
-        UNSAFE.putDouble(receiver, offset, value);
-    }
-
-    /**
-     * Write an Object value within an object. The location identity gives a hint to the compiler
-     * for improved global value numbering.
-     *
-     * @param receiver the object that is written to
-     * @param offset the offset at which to write to the object in bytes
-     * @param value the value to be written
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     */
-    @Deprecated
-    public static void unsafePutObject(Object receiver, long offset, Object value, Object locationIdentity) {
-        UNSAFE.putObject(receiver, offset, value);
-    }
-
-    /**
-     * Unsafe access to a final boolean value within an object. The condition parameter gives a hint
-     * to the compiler under which circumstances this access can be moved to an earlier location in
-     * the program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static boolean unsafeGetFinalBoolean(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getBoolean(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final byte value within an object. The condition parameter gives a hint to
-     * the compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static byte unsafeGetFinalByte(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getByte(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final short value within an object. The condition parameter gives a hint
-     * to the compiler under which circumstances this access can be moved to an earlier location in
-     * the program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static short unsafeGetFinalShort(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getShort(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final int value within an object. The condition parameter gives a hint to
-     * the compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static int unsafeGetFinalInt(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getInt(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final long value within an object. The condition parameter gives a hint to
-     * the compiler under which circumstances this access can be moved to an earlier location in the
-     * program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static long unsafeGetFinalLong(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getLong(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final float value within an object. The condition parameter gives a hint
-     * to the compiler under which circumstances this access can be moved to an earlier location in
-     * the program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static float unsafeGetFinalFloat(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getFloat(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final double value within an object. The condition parameter gives a hint
-     * to the compiler under which circumstances this access can be moved to an earlier location in
-     * the program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static double unsafeGetFinalDouble(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getDouble(receiver, offset);
-    }
-
-    /**
-     * Unsafe access to a final Object value within an object. The condition parameter gives a hint
-     * to the compiler under which circumstances this access can be moved to an earlier location in
-     * the program. The location identity gives a hint to the compiler for improved global value
-     * numbering.
-     *
-     * @param receiver the object that is accessed
-     * @param offset the offset at which to access the object in bytes
-     * @param condition the condition that makes this access safe also at an earlier location in the
-     *            program
-     * @param locationIdentity the location identity token that can be used for improved global
-     *            value numbering or null
-     * @return the accessed value
-     */
-    @Deprecated
-    public static Object unsafeGetFinalObject(Object receiver, long offset, boolean condition, Object locationIdentity) {
-        return UNSAFE.getObject(receiver, offset);
-    }
-
-    /**
      * Marks a method that it is considered as a boundary for Truffle partial evaluation.
      */
     @Retention(RetentionPolicy.RUNTIME)