1 #!/bin/sh 2 # 3 # Copyright (c) 2013, Oracle and/or its affiliates. All rights 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 ## 27 ## @test 28 ## @bug 8011675 29 ## @summary verify that whitebox can be used even if not all functions are declared in java-part 30 ## @author igor.ignatyev@oracle.com 31 ## @run shell WBRegisterNatives.sh 32 ## 33 34 if [ "${TESTSRC}" = "" ] 35 then 36 TESTSRC=${PWD} 37 echo "TESTSRC not set. Using "${TESTSRC}" as default" 38 fi 39 echo "TESTSRC=${TESTSRC}" 40 41 ## Adding common setup Variables for running shell tests. 42 . ${TESTSRC}/../test_env.sh 43 44 mkdir -p .${FS}sun${FS}hotspot 45 WHITEBOX_SRC=.${FS}sun${FS}hotspot${FS}WhiteBox.java 46 47 # creating sun.hotspot.WhiteBox class with only one existed method 48 cat << EOF > $WHITEBOX_SRC 49 package sun.hotspot; 50 51 public class WhiteBox { 52 private static native void registerNatives(); 53 static { registerNatives(); } 54 55 public native int notExistedMethod(); 56 public native int getHeapOopSize(); 57 58 public static void main(String[] args) { 59 WhiteBox wb = new WhiteBox(); 60 if (wb.getHeapOopSize() < 0) { 61 throw new Error("wb.getHeapOopSize() < 0"); 62 } 63 boolean catched = false; 64 try { 65 wb.notExistedMethod(); 66 } catch (UnsatisfiedLinkError e) { 67 catched = true; 68 } 69 if (!catched) { 70 throw new Error("wb.notExistedMethod() was invoked"); 71 } 72 } 73 } 74 EOF 75 76 ${COMPILEJAVA}${FS}bin${FS}javac ${TESTJAVACOPTS} -d . $WHITEBOX_SRC 77 ${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI sun.hotspot.WhiteBox 78