|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2022 SAP SE. All rights reserved.ights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | + |
| 25 | +/* |
| 26 | + * @test MHIntrinsicAllocFailureTest |
| 27 | + * @bug 8295724 |
| 28 | + * @requires vm.compMode == "Xmixed" |
| 29 | + * @requires vm.opt.TieredCompilation == null | vm.opt.TieredCompilation == true |
| 30 | + * @requires vm.opt.TieredStopAtLevel == null | vm.opt.TieredStopAtLevel == 4 |
| 31 | + * @summary test allocation failure of method handle intrinsic in profiled/non-profiled space |
| 32 | + * @library /test/lib |
| 33 | + * @modules java.base/jdk.internal.misc |
| 34 | + * java.management |
| 35 | + * |
| 36 | + * @build jdk.test.whitebox.WhiteBox |
| 37 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox |
| 38 | + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
| 39 | + * -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::* |
| 40 | + * -XX:ReservedCodeCacheSize=16m -XX:+SegmentedCodeCache |
| 41 | + * compiler.codecache.MHIntrinsicAllocFailureTest |
| 42 | + */ |
| 43 | + |
| 44 | +package compiler.codecache; |
| 45 | + |
| 46 | +import jdk.test.lib.Asserts; |
| 47 | +import jdk.test.whitebox.WhiteBox; |
| 48 | +import jdk.test.whitebox.code.BlobType; |
| 49 | + |
| 50 | +import java.lang.management.MemoryPoolMXBean; |
| 51 | + |
| 52 | +public class MHIntrinsicAllocFailureTest { |
| 53 | + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
| 54 | + |
| 55 | + private interface TestInterface { |
| 56 | + int testMethod(int a, int b, Object c); |
| 57 | + } |
| 58 | + |
| 59 | + private static void fillCodeCacheSegment(BlobType type) { |
| 60 | + // Fill with large blobs. |
| 61 | + MemoryPoolMXBean bean = type.getMemoryPool(); |
| 62 | + int size = (int) (bean.getUsage().getMax() >> 7); |
| 63 | + while (WHITE_BOX.allocateCodeBlob(size, type.id) != 0) {} |
| 64 | + // Fill rest with minimal blobs. |
| 65 | + while (WHITE_BOX.allocateCodeBlob(1, type.id) != 0) {} |
| 66 | + } |
| 67 | + |
| 68 | + public static void main(String[] args) { |
| 69 | + // Lock compilation to be able to better control code cache space |
| 70 | + WHITE_BOX.lockCompilation(); |
| 71 | + fillCodeCacheSegment(BlobType.MethodNonProfiled); |
| 72 | + fillCodeCacheSegment(BlobType.MethodProfiled); |
| 73 | + // JIT compilers should be off, now. |
| 74 | + Asserts.assertNotEquals(WHITE_BOX.getCompilationActivityMode(), 1); |
| 75 | + System.out.println("Code cache segments for non-profiled and profiled nmethods are full."); |
| 76 | + // Generate and use a MH itrinsic. Should not trigger one of the following: |
| 77 | + // - VirtualMachineError: Out of space in CodeCache for method handle intrinsic |
| 78 | + // - InternalError: java.lang.NoSuchMethodException: no such method: |
| 79 | + // java.lang.invoke.MethodHandle.linkToStatic(int,int,Object,MemberName)int/invokeStatic |
| 80 | + TestInterface add2ints = (a, b, c) -> a + b; |
| 81 | + System.out.println("Result of lambda expression: " + add2ints.testMethod(1, 2, null)); |
| 82 | + // Let GC check the code cache. |
| 83 | + WHITE_BOX.unlockCompilation(); |
| 84 | + WHITE_BOX.fullGC(); |
| 85 | + } |
| 86 | +} |
0 commit comments