-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8291360: Create entry points to expose low-level class file information
Reviewed-by: dholmes, rriggs
- Loading branch information
Harold Seigel
committed
Aug 4, 2022
1 parent
ce61eb6
commit a3040fc
Showing
9 changed files
with
812 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
test/hotspot/jtreg/runtime/ClassFile/ClassAccessFlagsRawTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
/** | ||
* @test | ||
* @bug 8291360 | ||
* @summary Test getting a class's raw access flags using java.lang.Class API | ||
* @modules java.base/java.lang:open | ||
* @compile classAccessFlagsRaw.jcod | ||
* @run main/othervm ClassAccessFlagsRawTest | ||
*/ | ||
|
||
import java.lang.reflect.*; | ||
|
||
public class ClassAccessFlagsRawTest { | ||
|
||
static Method m; | ||
|
||
public static void testIt(String className, int expectedResult) throws Exception { | ||
Class<?> testClass = Class.forName(className); | ||
int flags = (int)m.invoke(testClass); | ||
if (flags != expectedResult) { | ||
throw new RuntimeException( | ||
"expected 0x" + Integer.toHexString(expectedResult) + ", got 0x" + Integer.toHexString(flags) + " for class " + className); | ||
} | ||
} | ||
|
||
public static void main(String argv[]) throws Throwable { | ||
Class<?> cl = java.lang.Class.class; | ||
m = cl.getDeclaredMethod("getClassAccessFlagsRaw", new Class[0]); | ||
m.setAccessible(true); | ||
|
||
testIt("SUPERset", 0x21); // ACC_SUPER 0x20 + ACC_PUBLIC 0x1 | ||
testIt("SUPERnotset", Modifier.PUBLIC); | ||
|
||
// test primitive array. should return ACC_ABSTRACT | ACC_FINAL | ACC_PUBLIC. | ||
int flags = (int)m.invoke((new int[3]).getClass()); | ||
if (flags != (Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC)) { | ||
throw new RuntimeException( | ||
"expected 0x411, got 0x" + Integer.toHexString(flags) + " for primitive array"); | ||
} | ||
|
||
// test object array. should return flags of component. | ||
flags = (int)m.invoke((new SUPERnotset[2]).getClass()); | ||
if (flags != Modifier.PUBLIC) { | ||
throw new RuntimeException( | ||
"expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array"); | ||
} | ||
|
||
// test multi-dimensional object array. should return flags of component. | ||
flags = (int)m.invoke((new SUPERnotset[4][2]).getClass()); | ||
if (flags != Modifier.PUBLIC) { | ||
throw new RuntimeException( | ||
"expected 0x1, got 0x" + Integer.toHexString(flags) + " for object array"); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
test/hotspot/jtreg/runtime/ClassFile/ClassFileVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
/** | ||
* @test | ||
* @bug 8291360 | ||
* @summary Test getting the class file version for java.lang.Class API | ||
* @modules java.base/java.lang:open | ||
* @compile classFileVersions.jcod | ||
* @run main/othervm --enable-preview ClassFileVersionTest | ||
*/ | ||
|
||
import java.lang.reflect.*; | ||
|
||
public class ClassFileVersionTest { | ||
|
||
static Method m; | ||
|
||
public static void testIt(String className, int expectedResult) throws Exception { | ||
Class<?> testClass = Class.forName(className); | ||
int ver = (int)m.invoke(testClass); | ||
if (ver != expectedResult) { | ||
int exp_minor = (expectedResult >> 16) & 0x0000FFFF; | ||
int exp_major = expectedResult & 0x0000FFFF; | ||
int got_minor = (ver >> 16) & 0x0000FFFF; | ||
int got_major = ver & 0x0000FFFF; | ||
throw new RuntimeException( | ||
"Expected " + exp_minor + ":" + exp_major + " but got " + got_minor + ":" + got_major); | ||
} | ||
} | ||
|
||
public static void main(String argv[]) throws Throwable { | ||
Class<?> cl = java.lang.Class.class; | ||
m = cl.getDeclaredMethod("getClassFileVersion", new Class[0]); | ||
m.setAccessible(true); | ||
|
||
testIt("Version64", 64); | ||
testIt("Version59", 59); | ||
testIt("Version45_3", 0x3002D); // 3:45 | ||
// test minor version of 65535. | ||
testIt("Version64_65535", 0xFFFF0040); // 0xFFFF0040 = 65535:64 | ||
|
||
// test primitive array. should return latest version. | ||
int ver = (int)m.invoke((new int[3]).getClass()); | ||
if (ver != 64) { | ||
int got_minor = (ver >> 16) & 0x0000FFFF; | ||
int got_major = ver & 0x0000FFFF; | ||
throw new RuntimeException( | ||
"Expected 0:64, but got " + got_minor + ":" + got_major + " for primitive array"); | ||
} | ||
|
||
// test object array. should return class file version of component. | ||
ver = (int)m.invoke((new Version59[2]).getClass()); | ||
if (ver != 59) { | ||
int got_minor = (ver >> 16) & 0x0000FFFF; | ||
int got_major = ver & 0x0000FFFF; | ||
throw new RuntimeException( | ||
"Expected 0:59, but got " + got_minor + ":" + got_major + " for object array"); | ||
} | ||
|
||
// test multi-dimensional object array. should return class file version of component. | ||
ver = (int)m.invoke((new Version59[3][2]).getClass()); | ||
if (ver != 59) { | ||
int got_minor = (ver >> 16) & 0x0000FFFF; | ||
int got_major = ver & 0x0000FFFF; | ||
throw new RuntimeException( | ||
"Expected 0:59, but got " + got_minor + ":" + got_major + " for object array"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
a3040fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues