Wed, 26 Nov 2014 10:32:21 -0800
8053995: Add method to WhiteBox to get vm pagesize.
Summary: Unsafe is not recommended and may deprecated in future. Added a WhiteBox API to get VM page size.
Reviewed-by: dholmes, ccheung, mseledtsov
Contributed-by: yumin.qi@oracle.com
1.1 --- a/src/share/vm/prims/whitebox.cpp Tue Jun 24 15:50:50 2014 +0200 1.2 +++ b/src/share/vm/prims/whitebox.cpp Wed Nov 26 10:32:21 2014 -0800 1.3 @@ -73,6 +73,9 @@ 1.4 return heapOopSize; 1.5 WB_END 1.6 1.7 +WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o)) 1.8 + return os::vm_page_size(); 1.9 +WB_END 1.10 1.11 class WBIsKlassAliveClosure : public KlassClosure { 1.12 Symbol* _name; 1.13 @@ -972,6 +975,7 @@ 1.14 {CC"getObjectSize", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, 1.15 {CC"isObjectInOldGen", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, 1.16 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, 1.17 + {CC"getVMPageSize", CC"()I", (void*)&WB_GetVMPageSize }, 1.18 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, 1.19 {CC"classKnownToNotExist", 1.20 CC"(Ljava/lang/ClassLoader;Ljava/lang/String;)Z",(void*)&WB_ClassKnownToNotExist},
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/runtime/memory/ReadVMPageSize.java Wed Nov 26 10:32:21 2014 -0800 2.3 @@ -0,0 +1,46 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @summary Using WhiteBox to get VM page size 2.30 + * @library /testlibrary /testlibrary/whitebox 2.31 + * @build ReadVMPageSize 2.32 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 2.33 + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ReadVMPageSize 2.34 + */ 2.35 + 2.36 +import com.oracle.java.testlibrary.*; 2.37 +import sun.hotspot.WhiteBox; 2.38 + 2.39 +public class ReadVMPageSize { 2.40 + public static void main(String args[]) throws Exception { 2.41 + WhiteBox wb = WhiteBox.getWhiteBox(); 2.42 + int pageSize = wb.getVMPageSize(); 2.43 + if (pageSize < 0) { 2.44 + throw new Exception("pageSize < 0"); 2.45 + } else { 2.46 + System.out.println("Page size = " + pageSize); 2.47 + } 2.48 + } 2.49 +}
3.1 --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Tue Jun 24 15:50:50 2014 +0200 3.2 +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Wed Nov 26 10:32:21 2014 -0800 3.3 @@ -75,6 +75,7 @@ 3.4 // Memory 3.5 public native long getObjectAddress(Object o); 3.6 public native int getHeapOopSize(); 3.7 + public native int getVMPageSize(); 3.8 public native boolean isObjectInOldGen(Object o); 3.9 public native long getObjectSize(Object o); 3.10