Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
14cf04f
Initial and last commit of 2020
chhagedorn Dec 22, 2020
05620a9
Fix @Run and @Check, added more IR rules, refactorings, added more tests
chhagedorn Jan 15, 2021
48eb362
Refactor usage of TestFrameworkException
chhagedorn Jan 15, 2021
ef03008
Refactoring
chhagedorn Jan 18, 2021
3554ef2
Fix helper classes and add test for it
chhagedorn Jan 18, 2021
743b6f6
Fixing how scenarios are defined, run, checked and error reported
chhagedorn Jan 18, 2021
3c54689
Add @Run mode
chhagedorn Jan 19, 2021
9b4feae
Fix compilation level for @Test
chhagedorn Jan 20, 2021
4dc1877
Finishing counts rule for @IR and adding appropriate tests + fixing s…
chhagedorn Jan 25, 2021
56fcce0
Minor cleanups
chhagedorn Jan 25, 2021
2188a3e
Switch to bulk reporting for TestFormatExceptions instead of throwing…
chhagedorn Jan 26, 2021
b3bbd16
Fix @Warmup and @DontCompile, add compile commands tests and more Bad…
chhagedorn Jan 26, 2021
67f81a1
Add PRINT_GRAPH, Xcomp and UseCompile handling, fix public Framework …
chhagedorn Jan 27, 2021
1cc4690
Redesign TestFramework interface
chhagedorn Jan 29, 2021
595f7be
Rename ArgumentValue <-> Argument
chhagedorn Feb 1, 2021
cf1e4bd
Add MIN/MAX as possible Argument
chhagedorn Feb 3, 2021
fde418b
Insert Copyright headers and small clean ups
chhagedorn Feb 15, 2021
d8af462
Add more "bad" tests
chhagedorn Feb 15, 2021
dde6a7f
Add more compiler control tests
chhagedorn Feb 16, 2021
4e01c2d
Fix @DontCompile and @ForceCompile and add tests for it, fix TestBadF…
chhagedorn Feb 16, 2021
d0e1009
Update Copyright to 2021, rename INVOKE_ONCE to STANDALONE
chhagedorn Feb 16, 2021
5186713
Finish bad tests (check, run, IR), clean up some unused code
chhagedorn Feb 17, 2021
62b46f5
Fixing @DontCompile to only allow one option, start writing Javadocs
chhagedorn Feb 17, 2021
d22e559
Add more bad IR tests and doing some related small fixes and clean-ups
chhagedorn Feb 18, 2021
61f1af4
Adding more IR tests
chhagedorn Feb 19, 2021
db813b2
Add IR tests for trap, scope object, completely updated the format of…
chhagedorn Feb 24, 2021
b9ee1db
Added remaining IR nodes for mainline with tests for them
chhagedorn Feb 24, 2021
3256d80
Rename package into compiler.testframework
chhagedorn Feb 24, 2021
5a6a2e0
Rename and move project
chhagedorn Mar 1, 2021
16f15db
Move framework to /test/lib, add TestFrameworkDriver with example test
chhagedorn Mar 2, 2021
ebf09ba
add a packagefull version of ClassFileInstaller
iignatev Mar 3, 2021
433541e
simplify TestFrameworkDriver incantation
iignatev Mar 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

package valhallatests;

public class ValhallaIRNode {
private static final String START = "(\\d+(\\s){2}(";
private static final String MID = ".*)+(\\s){2}===.*";
private static final String END = ")";

public static final String CHECKCAST_ARRAY_INLINE = "(cmp.*precise klass \\[(L|Q)compiler/valhalla/inlinetypes/MyValue.*" + END;
public static final String ALLOCA = "(.*precise klass \\[(L|Q)compiler/valhalla/inlinetypes/MyValue.*\\R(.*(movl|xorl|nop|spill).*\\R)*.*_new_array_Java" + END;
public static final String STORE_INLINE_FIELDS = START + "CallStaticJava" + MID + "store_inline_type_fields" + END;
public static final String LOAD_UNKNOWN_INLINE = "(.*call_leaf,runtime load_unknown_inline.*" + END;
public static final String STORE_UNKNOWN_INLINE = "(.*call_leaf,runtime store_unknown_inline.*" + END;
public static final String INLINE_ARRAY_NULL_GUARD = "(.*call,static wrapper for: uncommon_trap.*reason='null_check' action='none'.*" + END;
public static final String INTRINSIC_SLOW_PATH = "(.*call,static wrapper for: uncommon_trap.*reason='intrinsic_or_type_checked_inlining'.*" + END;
public static final String CLONE_INTRINSIC_SLOW_PATH = "(.*call,static.*java.lang.Object::clone.*" + END;
public static final String JLONG_ARRAYCOPY = "(.*call_leaf_nofp,runtime jlong_disjoint_arraycopy.*" + END;
public static final String SUBSTITUTABILITY_TEST = START + "CallStaticJava" + MID + "java.lang.invoke.ValueBootstrapMethods::isSubstitutable" + END;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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
* @summary Example test to use the new test framework.
* @library /test/lib
* @run driver compiler.valhalla.testframework.TestSimpleExample
*/

package compiler.valhalla.testframework;

import testframework.*;

public class TestSimpleExample {

int iFld;

public static void main(String[] args) throws Exception {
TestFrameworkDriver.main(args);
}

// TestFramework will verify that this @IR rule works if it is called with a debug build.
// With a product build, it just executes this method without IR verification (Print flags
// for verification are only available in debug builds).
@Test
@IR(failOn = IRNode.LOOP, counts = {IRNode.STORE_I, "1"})
public void test() {
iFld = 42;
}
}
177 changes: 12 additions & 165 deletions test/lib/ClassFileInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import jdk.test.lib.util.ClassFileInstaller.Manifest;

/**
* Dump a class file for a class on the class path in the current directory, or
* in the specified JAR file. This class is usually used when you build a class
Expand Down Expand Up @@ -68,112 +70,13 @@
* @run driver ClassFileInstaller -jar myjar.jar sun.hotspot.WhiteBox
*/
public class ClassFileInstaller {
/**
* You can enable debug tracing of ClassFileInstaller by running JTREG with
* jtreg -DClassFileInstaller.debug=true ... <names of tests>
*/
public static boolean DEBUG = Boolean.getBoolean("ClassFileInstaller.debug");

/**
/**
* @param args The names of the classes to dump
* @throws Exception
* @deprecated use {@link jdk.test.lib.util.ClassFileInstaller} instead
*/
public static void main(String... args) throws Exception {
if (args.length > 1 && args[0].equals("-jar")) {
if (args.length < 2) {
throw new RuntimeException("Usage: ClassFileInstaller <options> <classes>\n" +
"where possible options include:\n" +
" -jar <path> Write to the JAR file <path>");
}
String jarFile = args[1];
String[] classes = addInnerClasses(args, 2);
writeJar_impl(jarFile, null, classes);
} else {
if (DEBUG) {
System.out.println("ClassFileInstaller: Writing to " + System.getProperty("user.dir"));
}
String[] classes = addInnerClasses(args, 0);
for (String cls : classes) {
writeClassToDisk(cls);
}
}
}

// Add commonly used inner classes that are often omitted by mistake. Currently
// we support only sun.hotspot.WhiteBox$WhiteBoxPermission. See JDK-8199290
private static String[] addInnerClasses(String[] classes, int startIdx) {
boolean seenWB = false;
boolean seenWBInner = false;
final String wb = "sun.hotspot.WhiteBox";
final String wbInner = "sun.hotspot.WhiteBox$WhiteBoxPermission";

ArrayList<String> list = new ArrayList<>();

for (int i = startIdx; i < classes.length; i++) {
String cls = classes[i];
list.add(cls);
switch (cls) {
case wb: seenWB = true; break;
case wbInner: seenWBInner = true; break;
}
}
if (seenWB && !seenWBInner) {
list.add(wbInner);
}

String[] array = new String[list.size()];
list.toArray(array);
return array;
}

public static class Manifest {
private InputStream in;

private Manifest(InputStream in) {
this.in = in;
}

static Manifest fromSourceFile(String fileName) throws Exception {
String pathName = System.getProperty("test.src") + File.separator + fileName;
return new Manifest(new FileInputStream(pathName));
}

// Example:
// String manifest = "Premain-Class: RedefineClassHelper\n" +
// "Can-Redefine-Classes: true\n";
// ClassFileInstaller.writeJar("redefineagent.jar",
// ClassFileInstaller.Manifest.fromString(manifest),
// "RedefineClassHelper");
static Manifest fromString(String manifest) throws Exception {
return new Manifest(new ByteArrayInputStream(manifest.getBytes()));
}

public InputStream getInputStream() {
return in;
}
}

private static void writeJar_impl(String jarFile, Manifest manifest, String classes[]) throws Exception {
if (DEBUG) {
System.out.println("ClassFileInstaller: Writing to " + getJarPath(jarFile));
}

(new File(jarFile)).delete();
FileOutputStream fos = new FileOutputStream(jarFile);
ZipOutputStream zos = new ZipOutputStream(fos);

// The manifest must be the first or second entry. See comments in JarInputStream
// constructor and JDK-5046178.
if (manifest != null) {
writeToDisk(zos, "META-INF/MANIFEST.MF", manifest.getInputStream());
}

for (String cls : classes) {
writeClassToDisk(zos, cls);
}

zos.close();
fos.close();
jdk.test.lib.util.ClassFileInstaller.main(args);
}

/*
Expand All @@ -188,15 +91,11 @@ private static void writeJar_impl(String jarFile, Manifest manifest, String clas
* @build ClassFileInstaller
*/
public static String writeJar(String jarFile, String... classes) throws Exception {
classes = addInnerClasses(classes, 0);
writeJar_impl(jarFile, null, classes);
return getJarPath(jarFile);
return jdk.test.lib.util.ClassFileInstaller.writeJar(jarFile, classes);
}

public static String writeJar(String jarFile, Manifest manifest, String... classes) throws Exception {
classes = addInnerClasses(classes, 0);
writeJar_impl(jarFile, manifest, classes);
return getJarPath(jarFile);
return jdk.test.lib.util.ClassFileInstaller.writeJar(jarFile, manifest, classes);
}

/**
Expand All @@ -217,74 +116,22 @@ public static String writeJar(String jarFile, Manifest manifest, String... class
*
*/
public static String getJarPath(String jarFileName) {
return new File(jarFileName).getAbsolutePath();
return jdk.test.lib.util.ClassFileInstaller.getJarPath(jarFileName);
}

public static void writeClassToDisk(String className) throws Exception {
writeClassToDisk((ZipOutputStream)null, className);
}
private static void writeClassToDisk(ZipOutputStream zos, String className) throws Exception {
writeClassToDisk(zos, className, "");
jdk.test.lib.util.ClassFileInstaller.writeClassToDisk(className);
}

public static void writeClassToDisk(String className, String prependPath) throws Exception {
writeClassToDisk(null, className, prependPath);
}
private static void writeClassToDisk(ZipOutputStream zos, String className, String prependPath) throws Exception {
ClassLoader cl = ClassFileInstaller.class.getClassLoader();

// Convert dotted class name to a path to a class file
String pathName = className.replace('.', '/').concat(".class");
InputStream is = cl.getResourceAsStream(pathName);
if (is == null) {
throw new RuntimeException("Failed to find " + pathName);
}
if (prependPath.length() > 0) {
pathName = prependPath + "/" + pathName;
}
writeToDisk(zos, pathName, is);
jdk.test.lib.util.ClassFileInstaller.writeClassToDisk(className, prependPath);
}

public static void writeClassToDisk(String className, byte[] bytecode) throws Exception {
writeClassToDisk(null, className, bytecode);
}
private static void writeClassToDisk(ZipOutputStream zos, String className, byte[] bytecode) throws Exception {
writeClassToDisk(zos, className, bytecode, "");
jdk.test.lib.util.ClassFileInstaller.writeClassToDisk(className, bytecode);
}

public static void writeClassToDisk(String className, byte[] bytecode, String prependPath) throws Exception {
writeClassToDisk(null, className, bytecode, prependPath);
}
private static void writeClassToDisk(ZipOutputStream zos, String className, byte[] bytecode, String prependPath) throws Exception {
// Convert dotted class name to a path to a class file
String pathName = className.replace('.', '/').concat(".class");
if (prependPath.length() > 0) {
pathName = prependPath + "/" + pathName;
}
writeToDisk(zos, pathName, new ByteArrayInputStream(bytecode));
}

private static void writeToDisk(ZipOutputStream zos, String pathName, InputStream is) throws Exception {
if (DEBUG) {
System.out.println("ClassFileInstaller: Writing " + pathName);
}
if (zos != null) {
ZipEntry ze = new ZipEntry(pathName);
zos.putNextEntry(ze);
byte[] buf = new byte[1024];
int len;
while ((len = is.read(buf))>0){
zos.write(buf, 0, len);
}
} else {
// Create the class file's package directory
Path p = Paths.get(pathName);
if (pathName.contains("/")) {
Files.createDirectories(p.getParent());
}
// Create the class file
Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING);
}
is.close();
jdk.test.lib.util.ClassFileInstaller.writeClassToDisk(className, bytecode, prependPath);
}
}
11 changes: 11 additions & 0 deletions test/lib/jdk/test/lib/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public final class Utils {
*/
public static final String TEST_SRC = System.getProperty("test.src", "").trim();

/**
* Returns the value of 'test.src.path' system property
*/
public static final String TEST_SRC_PATH = System.getProperty("test.src.path", "").trim();

/**
* Returns the value of 'test.root' system property.
*/
Expand All @@ -120,11 +125,17 @@ public final class Utils {
*/
public static final String TEST_NAME = System.getProperty("test.name", ".");

/**
* Returns the value of 'test.file' system property
*/
public static final String TEST_FILE = System.getProperty("test.file", "").trim();

/**
* Returns the value of 'test.nativepath' system property
*/
public static final String TEST_NATIVE_PATH = System.getProperty("test.nativepath", ".");


/**
* Defines property name for seed value.
*/
Expand Down
Loading