1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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.hotspot.lir.test; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.core.common.LIRKind; 28 import org.graalvm.compiler.hotspot.HotSpotBackend; 29 import org.graalvm.compiler.lir.framemap.FrameMapBuilder; 30 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 31 import org.graalvm.compiler.lir.jtt.LIRTest; 32 import org.graalvm.compiler.lir.jtt.LIRTestSpecification; 33 import org.graalvm.compiler.nodes.SafepointNode; 34 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 36 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 37 38 import jdk.vm.ci.code.BailoutException; 39 import jdk.vm.ci.meta.AllocatableValue; 40 import jdk.vm.ci.meta.JavaConstant; 41 import jdk.vm.ci.meta.ResolvedJavaMethod; 42 43 public class ExceedMaxOopMapStackOffset extends LIRTest { 44 45 /** 46 * Allocate lots of stacks slots and initialize them with a constant. 47 */ 48 private static class WriteStackSlotsSpec extends LIRTestSpecification { 49 private final JavaConstant constant; 50 51 WriteStackSlotsSpec(JavaConstant constant) { 52 this.constant = constant; 53 } 54 55 @Override 56 public void generate(LIRGeneratorTool gen) { 57 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 58 LIRKind lirKind = LIRKind.reference(gen.target().arch.getPlatformKind(constant.getJavaKind())); 59 // create slots 60 for (int i = 0; i < slots.length; i++) { 61 AllocatableValue src = gen.emitLoadConstant(lirKind, constant); 62 slots[i] = frameMapBuilder.allocateSpillSlot(lirKind); 63 gen.emitMove(slots[i], src); 64 } 65 } 66 } 67 68 /** 69 * Read stacks slots and move their content into a blackhole. 70 */ 71 private static class ReadStackSlotsSpec extends LIRTestSpecification { 72 73 ReadStackSlotsSpec() { 74 } 75 76 @Override 77 public void generate(LIRGeneratorTool gen) { 78 for (int i = 0; i < slots.length; i++) { 79 gen.emitBlackhole(gen.emitMove(slots[i])); 80 } 81 } 82 } 83 84 @Override 85 protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) { 86 InvocationPlugin safepointPlugin = new InvocationPlugin() { 87 @Override 88 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { 89 b.add(new SafepointNode()); 90 return true; 91 } 92 }; 93 conf.getPlugins().getInvocationPlugins().register(safepointPlugin, getClass(), "safepoint"); 94 return super.editGraphBuilderConfiguration(conf); 95 } 96 97 /* 98 * Safepoint Snippet 99 */ 100 private static void safepoint() { 101 } 102 103 private static AllocatableValue[] slots; 104 105 private static final LIRTestSpecification readStackObjects = new ReadStackSlotsSpec(); 106 107 @SuppressWarnings("unused") 108 @LIRIntrinsic 109 public static void instrinsic(LIRTestSpecification spec) { 110 } 111 112 private static final LIRTestSpecification writeStackObjects = new WriteStackSlotsSpec(JavaConstant.NULL_POINTER); 113 114 public void testStackObjects() { 115 instrinsic(writeStackObjects); 116 safepoint(); 117 instrinsic(readStackObjects); 118 } 119 120 @Test 121 public void runStackObjects() throws Throwable { 122 int max = ((HotSpotBackend) getBackend()).getRuntime().getVMConfig().maxOopMapStackOffset; 123 if (max == Integer.MAX_VALUE) { 124 max = 16 * 1024 - 64; 125 } 126 try { 127 int numSlots = (max / 8) + 1; 128 slots = new AllocatableValue[numSlots]; 129 runTest("testStackObjects"); 130 } catch (BailoutException e) { 131 return; 132 } 133 fail("Expected exception BailoutException wasn't thrown"); 134 } 135 }