Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8265423: [lworld] Provide experimental support for generating a single class file per primitive class #394

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2021, 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 8265423
* @summary Experimental support for generating a single class file per primitive class
* @modules jdk.compiler/com.sun.tools.javac.util jdk.jdeps/com.sun.tools.javap
* @compile SplitPrimitiveClassBytecodeTest.java
* @run main SplitPrimitiveClassBytecodeTest
* @modules jdk.compiler
*/

import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Paths;

public class SplitPrimitiveClassBytecodeTest {

public primitive class X {

X.ref xr = null;

public void foo(X.ref[] xra, X[] xa) {
xa = new X[10];
xra = new X.ref[10];
xra[0] = xa[0];
xa[1] = xra[0];
Class<?> c = X.class;
c = X.ref.class;
}
}

public static void main(String[] args) {
new SplitPrimitiveClassBytecodeTest().run();
}

void run() {
String [] params = new String [] { "-v",
Paths.get(System.getProperty("test.classes"),
"SplitPrimitiveClassBytecodeTest$X.class").toString() };
runCheck(params, new String [] {

// check field
"final SplitPrimitiveClassBytecodeTest$X$ref xr;",
"descriptor: LSplitPrimitiveClassBytecodeTest$X$ref;",
"flags: (0x0010) ACC_FINAL",

// check method
"public void foo(SplitPrimitiveClassBytecodeTest$X$ref[], SplitPrimitiveClassBytecodeTest$X[]);",
"descriptor: ([LSplitPrimitiveClassBytecodeTest$X$ref;[QSplitPrimitiveClassBytecodeTest$X;)V",
" 0: bipush 10",
" 2: anewarray #11 // class \"QSplitPrimitiveClassBytecodeTest$X;\"",
" 5: astore_2",
" 6: bipush 10",
" 8: anewarray #13 // class SplitPrimitiveClassBytecodeTest$X$ref",
"11: astore_1",
"12: aload_1",
"13: iconst_0",
"14: aload_2",
"15: iconst_0",
"16: aaload",
"17: aastore",
"18: aload_2",
"19: iconst_1",
"20: aload_1",
"21: iconst_0",
"22: aaload",
"23: checkcast #11 // class \"QSplitPrimitiveClassBytecodeTest$X;\"",
"26: aastore",
"27: ldc #1 // class SplitPrimitiveClassBytecodeTest$X",
"29: astore_3",
"30: ldc #13 // class SplitPrimitiveClassBytecodeTest$X$ref",
"32: astore_3",
"33: return",
});
}

void runCheck(String [] params, String [] expectedOut) {
StringWriter s;
String out;

try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
com.sun.tools.javap.Main.run(params, pw);
out = s.toString();
}
int errors = 0;
for (String eo: expectedOut) {
if (!out.contains(eo)) {
System.err.println("Match not found for string: " + eo);
errors++;
}
}
if (errors > 0) {
throw new AssertionError("Unexpected javap output: " + out);
}
}
}
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2021, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 8265423
* @summary Experimental support for generating a single class file per primitive class
* @modules jdk.jdeps/com.sun.tools.classfile
* @run main SplitPrimitiveClassInnerClassesTest
*/

import com.sun.tools.classfile.*;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;

public class SplitPrimitiveClassInnerClassesTest {

primitive class V<T> implements java.io.Serializable {}

public static void main(String[] args) throws Exception {
ClassFile cls = ClassFile.read(SplitPrimitiveClassInnerClassesTest.class.getResourceAsStream("SplitPrimitiveClassInnerClassesTest.class"));

if (cls == null) {
throw new AssertionError("Could not locate the class files");
}

/* Check emission of inner class attribute */
InnerClasses_attribute inners = (InnerClasses_attribute) cls.attributes.get(Attribute.InnerClasses);
if (inners == null) {
throw new AssertionError("Missing inner class attribute");
}
boolean foundV = false, foundVref = false;
for (int i = 0; i < inners.number_of_classes; i++) {
String name = inners.classes[i].getInnerName(cls.constant_pool);
if (name.equals("V"))
foundV = true;
else if (name.equals("V$ref"))
foundVref = true;
}
if (!foundV || !foundVref) {
throw new AssertionError("Incorrect inner class attribute");
}

// Test signature attribute
cls = ClassFile.read(SplitPrimitiveClassInnerClassesTest.class.getResourceAsStream("SplitPrimitiveClassInnerClassesTest$V.class"));
Signature_attribute signature = (Signature_attribute)cls.attributes.get(Attribute.Signature);
String sign = signature.getSignature(cls.constant_pool);
if (sign == null || !sign.equals("<T:Ljava/lang/Object;>LSplitPrimitiveClassInnerClassesTest$V$ref<TT;>;")) {
throw new RuntimeException("Wrong signature " + sign);
}
}
}
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2021, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 8265423
* @summary Experimental support for generating a single class file per primitive class
* @compile SplitPrimitiveClassNestHostTest.java
* @run main SplitPrimitiveClassNestHostTest
*/

import java.util.Arrays;

public primitive class SplitPrimitiveClassNestHostTest implements java.io.Serializable {

primitive class Inner {}

public static void main(String [] args) {

// check wiring of super types.
Class<?> superClass = SplitPrimitiveClassNestHostTest.class.getSuperclass();
if (!superClass.equals(
SplitPrimitiveClassNestHostTest.class.referenceType().get()))
throw new AssertionError("Wrong superclass for SplitPrimitiveClassNestHostTest");

Class<?> [] superInterfaces = SplitPrimitiveClassNestHostTest.class.getInterfaces();
if (superInterfaces.length != 1)
throw new AssertionError("Wrong super interfaces for SplitPrimitiveClassNestHostTest");

if (!superInterfaces[0].equals(PrimitiveObject.class))
throw new AssertionError("Wrong super interfaces for SplitPrimitiveClassNestHostTest");

// check super types of ref.class
if (!superClass.getSuperclass().equals(Object.class))
throw new AssertionError("Wrong superclass for SplitPrimitiveClassNestHostTest.ref");
superInterfaces = superClass.getInterfaces();
if (superInterfaces.length != 1)
throw new AssertionError("Wrong super interfaces for SplitPrimitiveClassNestHostTest.ref");

if (!superInterfaces[0].equals(java.io.Serializable.class))
throw new AssertionError("Wrong super interfaces for SplitPrimitiveClassNestHostTest.ref");


Class<?> nestHost = SplitPrimitiveClassNestHostTest.class.getNestHost();
if (!nestHost.equals(SplitPrimitiveClassNestHostTest.class.referenceType().get()))
throw new AssertionError("Wrong nest host: " + nestHost);

Class<?> [] members = nestHost.getNestMembers();
if (members.length != 4)
throw new AssertionError("Wrong member count: " + members.length);

if (!members[0].equals(nestHost))
throw new AssertionError("Wrong initial member: " + members[0]);

if (!members[1].equals(SplitPrimitiveClassNestHostTest.class))
throw new AssertionError("Wrong member[1]: " + members[1]);

if (!members[1].getNestHost().equals(nestHost))
throw new AssertionError("Wrong nest host for member[1]: " + members[1]);

if (!Arrays.equals(members[1].getNestMembers(), members))
throw new AssertionError("Wrong nest members for member[1]: " + members[1]);

if (!members[2].equals(Inner.class))
throw new AssertionError("Wrong member[2]: " + members[2]);

if (!members[2].getNestHost().equals(nestHost))
throw new AssertionError("Wrong nest host for member[2]: " + members[2]);

if (!Arrays.equals(members[2].getNestMembers(), members))
throw new AssertionError("Wrong nest members for member[2]: " + members[2]);

if (!members[3].equals(Inner.class.referenceType().get()))
throw new AssertionError("Wrong member[3]: " + members[3]);

if (!members[3].getNestHost().equals(nestHost))
throw new AssertionError("Wrong nest host for member[3]: " + members[3]);

if (!Arrays.equals(members[3].getNestMembers(), members))
throw new AssertionError("Wrong nest members for member[3]: " + members[3]);
}
}