Path: blob/master/test/lib-test/sun/hotspot/whitebox/MismatchedWhiteBox/WhiteBox.java
41153 views
/*1* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test WhiteBox25* @bug 801167526* @summary verify that whitebox can be used even if not all functions are declared in java-part27* @author [email protected]28* @modules java.base/jdk.internal.misc29* @library /test/lib30* @compile WhiteBox.java31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-CheckIntrinsics sun.hotspot.WhiteBox33*/3435package sun.hotspot;3637public class WhiteBox {38@SuppressWarnings("serial")39public static class WhiteBoxPermission extends java.security.BasicPermission {40// ClassFileInstaller is hard-coded to copy WhiteBox$WhiteBoxPermission, so let's41// make a fake one here as well.42public WhiteBoxPermission(String s) {43super(s);44}45}4647private static native void registerNatives();48static { registerNatives(); }49public native int notExistedMethod();50public native int getHeapOopSize();51public static void main(String[] args) {52WhiteBox wb = new WhiteBox();53if (wb.getHeapOopSize() < 0) {54throw new Error("wb.getHeapOopSize() < 0");55}56boolean catched = false;57try {58wb.notExistedMethod();59} catch (UnsatisfiedLinkError e) {60catched = true;61}62if (!catched) {63throw new Error("wb.notExistedMethod() was invoked");64}65}66}676869