< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/TrufflePEATest.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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 package org.graalvm.compiler.core.test.ea;
  24 


  25 import org.graalvm.compiler.core.common.GraalOptions;
  26 import org.graalvm.compiler.core.test.GraalCompilerTest;
  27 import org.graalvm.compiler.nodes.StructuredGraph;
  28 import org.graalvm.compiler.nodes.extended.RawLoadNode;
  29 import org.graalvm.compiler.nodes.extended.RawStoreNode;
  30 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
  31 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  32 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  33 import org.graalvm.compiler.phases.tiers.HighTierContext;
  34 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
  35 import org.junit.Test;
  36 import sun.misc.Unsafe;
  37 
  38 import java.lang.reflect.Field;
  39 
  40 public class TrufflePEATest extends GraalCompilerTest {
  41 
  42     /**
  43      * This class mimics the behavior of {@code FrameWithoutBoxing}.
  44      */
  45     static class Frame {
  46         long[] primitiveLocals;
  47 
  48         Frame(int size) {
  49             primitiveLocals = new long[size];
  50         }
  51     }
  52 
  53     /**
  54      * This class mimics the behavior of {@code DynamicObjectL6I6}.
  55      */
  56     static class DynamicObject {
  57         int primitiveField0;
  58         int primitiveField1;

  59     }
  60 
  61     private static final long offsetLong1 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 1;
  62     private static final long offsetLong2 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 2;
  63 
  64     private static final long primitiveField0Offset;
  65 
  66     static {
  67         try {
  68             Field primitiveField0 = DynamicObject.class.getDeclaredField("primitiveField0");
  69             primitiveField0Offset = UNSAFE.objectFieldOffset(primitiveField0);








  70         } catch (NoSuchFieldException | SecurityException e) {
  71             throw new AssertionError(e);
  72         }
  73     }
  74 
  75     public static int unsafeAccessToLongArray(int v, Frame frame) {
  76         long[] array = frame.primitiveLocals;
  77         int s = UNSAFE.getInt(array, offsetLong1);
  78         UNSAFE.putInt(array, offsetLong1, v);
  79         UNSAFE.putInt(array, offsetLong2, v);
  80         return s + UNSAFE.getInt(array, offsetLong1) + UNSAFE.getInt(array, offsetLong2);
  81     }
  82 
  83     @Test
  84     public void testUnsafeAccessToLongArray() {
  85         StructuredGraph graph = processMethod("unsafeAccessToLongArray");
  86         assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count());
  87     }
  88 
  89     /**




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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 package org.graalvm.compiler.core.test.ea;
  24 
  25 import java.lang.reflect.Field;
  26 
  27 import org.graalvm.compiler.core.common.GraalOptions;
  28 import org.graalvm.compiler.core.test.GraalCompilerTest;
  29 import org.graalvm.compiler.nodes.StructuredGraph;
  30 import org.graalvm.compiler.nodes.extended.RawLoadNode;
  31 import org.graalvm.compiler.nodes.extended.RawStoreNode;
  32 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
  33 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  34 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  35 import org.graalvm.compiler.phases.tiers.HighTierContext;
  36 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
  37 import org.junit.Test;

  38 
  39 import sun.misc.Unsafe;
  40 
  41 public class TrufflePEATest extends GraalCompilerTest {
  42 
  43     /**
  44      * This class mimics the behavior of {@code FrameWithoutBoxing}.
  45      */
  46     static class Frame {
  47         long[] primitiveLocals;
  48 
  49         Frame(int size) {
  50             primitiveLocals = new long[size];
  51         }
  52     }
  53 
  54     /**
  55      * This class mimics the behavior of {@code DynamicObjectL6I6}.
  56      */
  57     static class DynamicObject {
  58         int primitiveField0;
  59         int primitiveField1;
  60         int primitiveField2;
  61     }
  62 
  63     private static final long offsetLong1 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 1;
  64     private static final long offsetLong2 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 2;
  65 
  66     private static final long primitiveField0Offset;
  67 
  68     static {
  69         try {
  70             Field primitiveField0 = DynamicObject.class.getDeclaredField("primitiveField0");
  71             long offset = UNSAFE.objectFieldOffset(primitiveField0);
  72             if (offset % 8 == 0) {
  73                 primitiveField0Offset = offset;
  74             } else {
  75                 Field primitiveField1 = DynamicObject.class.getDeclaredField("primitiveField1");
  76                 offset = UNSAFE.objectFieldOffset(primitiveField1);
  77                 assert offset % 8 == 0;
  78                 primitiveField0Offset = offset;
  79             }
  80         } catch (NoSuchFieldException | SecurityException e) {
  81             throw new AssertionError(e);
  82         }
  83     }
  84 
  85     public static int unsafeAccessToLongArray(int v, Frame frame) {
  86         long[] array = frame.primitiveLocals;
  87         int s = UNSAFE.getInt(array, offsetLong1);
  88         UNSAFE.putInt(array, offsetLong1, v);
  89         UNSAFE.putInt(array, offsetLong2, v);
  90         return s + UNSAFE.getInt(array, offsetLong1) + UNSAFE.getInt(array, offsetLong2);
  91     }
  92 
  93     @Test
  94     public void testUnsafeAccessToLongArray() {
  95         StructuredGraph graph = processMethod("unsafeAccessToLongArray");
  96         assertDeepEquals(1, graph.getNodes().filter(RawLoadNode.class).count());
  97     }
  98 
  99     /**


< prev index next >