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.replacements.test; 24 25 import java.util.Objects; 26 27 import org.graalvm.compiler.api.directives.GraalDirectives; 28 import org.graalvm.compiler.debug.Debug; 29 import org.graalvm.compiler.debug.DebugConfigScope; 30 import org.graalvm.compiler.debug.GraalError; 31 import org.graalvm.compiler.nodes.StructuredGraph; 32 import org.graalvm.compiler.nodes.ValueNode; 33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 34 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 35 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 36 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; 37 import org.graalvm.compiler.replacements.Snippets; 38 import org.graalvm.compiler.replacements.classfile.ClassfileBytecodeProvider; 39 import org.graalvm.compiler.word.Word; 40 import org.graalvm.compiler.word.WordCastNode; 41 import org.junit.Assert; 42 import org.junit.Rule; 43 import org.junit.Test; 44 import org.junit.rules.ExpectedException; 45 46 import jdk.vm.ci.meta.ResolvedJavaMethod; 47 48 /** 49 * Tests for derived oops in reference maps. 130 131 obj.beforeGC.basePointer = getRawPointer(obj); 132 obj.beforeGC.internalPointer = internalPointer; 133 134 System.gc(); 135 136 obj.afterGC.basePointer = getRawPointer(obj); 137 obj.afterGC.internalPointer = internalPointer; 138 139 return obj; 140 } 141 142 @Rule public final ExpectedException thrown = ExpectedException.none(); 143 private static final String UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG = "should not reach here: unknown reference alive across safepoint"; 144 145 @Test 146 @SuppressWarnings("try") 147 public void testFieldOffsetMergeNonLiveBasePointer() { 148 thrown.expect(GraalError.class); 149 thrown.expectMessage(UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG); 150 try (DebugConfigScope s = Debug.setConfig(Debug.silentConfig())) { 151 // Run a couple times to encourage objects to move 152 for (int i = 0; i < 4; i++) { 153 Result r = new Result(); 154 test("fieldOffsetMergeSnippet01", r, 8L, 16L); 155 Assert.assertEquals(r.beforeGC.delta(), r.afterGC.delta()); 156 } 157 } 158 } 159 160 @Test 161 public void testFieldOffsetMergeNonLiveBasePointerNotAccrossSafepoint() { 162 // Run a couple times to encourage objects to move 163 for (int i = 0; i < 4; i++) { 164 Result r = new Result(); 165 test("fieldOffsetMergeSnippet02", r, 8L, 16L); 166 } 167 } 168 169 @Test 170 @SuppressWarnings("try") 171 public void testFieldOffsetMergeLiveBasePointer() { 172 thrown.expect(GraalError.class); 173 thrown.expectMessage(UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG); 174 try (DebugConfigScope s = Debug.setConfig(Debug.silentConfig())) { 175 // Run a couple times to encourage objects to move 176 for (int i = 0; i < 4; i++) { 177 Result r = new Result(); 178 test("fieldOffsetMergeSnippet03", r, new Result(), new Result(), 8L, 16L); 179 Assert.assertEquals(r.beforeGC.delta(), r.afterGC.delta()); 180 } 181 } 182 } 183 184 public static boolean SideEffectB; 185 public static long SideEffect1 = 16; 186 public static long SideEffect2 = 16; 187 public static Object o1 = new Result(); 188 public static Object o2 = o1; 189 190 public static Result fieldOffsetMergeSnippet01(Result objResult, long offsetA, long offsetB) { 191 long internalPointer; 192 if (SideEffectB) { 193 internalPointer = getRawPointer(o1) + offsetA; 194 SideEffect1 = internalPointer; | 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.replacements.test; 24 25 import java.util.Objects; 26 27 import org.graalvm.compiler.api.directives.GraalDirectives; 28 import org.graalvm.compiler.debug.DebugContext; 29 import org.graalvm.compiler.debug.DebugContext.Scope; 30 import org.graalvm.compiler.debug.GraalError; 31 import org.graalvm.compiler.nodes.StructuredGraph; 32 import org.graalvm.compiler.nodes.ValueNode; 33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 34 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 35 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 36 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; 37 import org.graalvm.compiler.replacements.Snippets; 38 import org.graalvm.compiler.replacements.classfile.ClassfileBytecodeProvider; 39 import org.graalvm.compiler.word.Word; 40 import org.graalvm.compiler.word.WordCastNode; 41 import org.junit.Assert; 42 import org.junit.Rule; 43 import org.junit.Test; 44 import org.junit.rules.ExpectedException; 45 46 import jdk.vm.ci.meta.ResolvedJavaMethod; 47 48 /** 49 * Tests for derived oops in reference maps. 130 131 obj.beforeGC.basePointer = getRawPointer(obj); 132 obj.beforeGC.internalPointer = internalPointer; 133 134 System.gc(); 135 136 obj.afterGC.basePointer = getRawPointer(obj); 137 obj.afterGC.internalPointer = internalPointer; 138 139 return obj; 140 } 141 142 @Rule public final ExpectedException thrown = ExpectedException.none(); 143 private static final String UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG = "should not reach here: unknown reference alive across safepoint"; 144 145 @Test 146 @SuppressWarnings("try") 147 public void testFieldOffsetMergeNonLiveBasePointer() { 148 thrown.expect(GraalError.class); 149 thrown.expectMessage(UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG); 150 DebugContext debug = getDebugContext(); 151 try (Scope s = debug.disable()) { 152 // Run a couple times to encourage objects to move 153 for (int i = 0; i < 4; i++) { 154 Result r = new Result(); 155 test("fieldOffsetMergeSnippet01", r, 8L, 16L); 156 Assert.assertEquals(r.beforeGC.delta(), r.afterGC.delta()); 157 } 158 } 159 } 160 161 @Test 162 public void testFieldOffsetMergeNonLiveBasePointerNotAccrossSafepoint() { 163 // Run a couple times to encourage objects to move 164 for (int i = 0; i < 4; i++) { 165 Result r = new Result(); 166 test("fieldOffsetMergeSnippet02", r, 8L, 16L); 167 } 168 } 169 170 @Test 171 @SuppressWarnings("try") 172 public void testFieldOffsetMergeLiveBasePointer() { 173 thrown.expect(GraalError.class); 174 thrown.expectMessage(UNKNOWN_REFERENCE_AT_SAFEPOINT_MSG); 175 DebugContext debug = getDebugContext(); 176 try (Scope s = debug.disable()) { 177 // Run a couple times to encourage objects to move 178 for (int i = 0; i < 4; i++) { 179 Result r = new Result(); 180 test("fieldOffsetMergeSnippet03", r, new Result(), new Result(), 8L, 16L); 181 Assert.assertEquals(r.beforeGC.delta(), r.afterGC.delta()); 182 } 183 } 184 } 185 186 public static boolean SideEffectB; 187 public static long SideEffect1 = 16; 188 public static long SideEffect2 = 16; 189 public static Object o1 = new Result(); 190 public static Object o2 = o1; 191 192 public static Result fieldOffsetMergeSnippet01(Result objResult, long offsetA, long offsetB) { 193 long internalPointer; 194 if (SideEffectB) { 195 internalPointer = getRawPointer(o1) + offsetA; 196 SideEffect1 = internalPointer; |