8072369: [TESTBUG] Remove potentially insecure class cast in some hotspot tests

Reviewed-by: twisti, kvn, iignatyev, tpivovarova
This commit is contained in:
Konstantin Shefov 2015-10-15 18:00:00 +03:00
parent 888def5147
commit a4cb6b3eb4
6 changed files with 63 additions and 28 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
* @test * @test
* @bug 5057225 * @bug 5057225
* @summary Remove useless I2L conversions * @summary Remove useless I2L conversions
* * @library /testlibrary
* @run main/othervm -Xcomp -XX:CompileOnly=Test5057225.doload Test5057225 * @run main/othervm -Xcomp -XX:CompileOnly=Test5057225.doload Test5057225
*/ */
import java.net.URLClassLoader; import jdk.test.lib.Utils;
public class Test5057225 { public class Test5057225 {
static byte[] ba = new byte[] { -1 }; static byte[] ba = new byte[] { -1 };
@ -89,8 +89,9 @@ public class Test5057225 {
static void loadAndRunClass(String classname) throws Exception { static void loadAndRunClass(String classname) throws Exception {
Class cl = Class.forName(classname); Class cl = Class.forName(classname);
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader(); ClassLoader apploader = cl.getClassLoader();
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent()); ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass(classname); Class c = loader.loadClass(classname);
Runnable r = (Runnable) c.newInstance(); Runnable r = (Runnable) c.newInstance();
r.run(); r.run();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @test * @test
* @bug 6603011 * @bug 6603011
* @summary long/int division by constant * @summary long/int division by constant
* * @library /testlibrary
* @run main/othervm -Xcomp -Xbatch -XX:-Inline Test * @run main/othervm -Xcomp -Xbatch -XX:-Inline Test
*/ */
@ -36,7 +36,7 @@
// dividend and divisor combinations are tested // dividend and divisor combinations are tested
// //
import java.net.*; import jdk.test.lib.Utils;
class s { class s {
static int divi(int dividend, int divisor) { return dividend / divisor; } static int divi(int dividend, int divisor) { return dividend / divisor; }
@ -189,10 +189,10 @@ public class Test implements Runnable {
// This allows the JIT to see q.DIVISOR as a final constant, and change // This allows the JIT to see q.DIVISOR as a final constant, and change
// any divisions or mod operations into multiplies. // any divisions or mod operations into multiplies.
public static void test_divisor(int divisor, public static void test_divisor(int divisor,
URLClassLoader apploader) throws Exception { ClassLoader apploader) throws Exception {
System.setProperty("divisor", "" + divisor); System.setProperty("divisor", "" + divisor);
ClassLoader loader = new URLClassLoader(apploader.getURLs(), ClassLoader loader
apploader.getParent()); = Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass("Test"); Class c = loader.loadClass("Test");
Runnable r = (Runnable)c.newInstance(); Runnable r = (Runnable)c.newInstance();
r.run(); r.run();
@ -200,7 +200,7 @@ public class Test implements Runnable {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Class cl = Class.forName("Test"); Class cl = Class.forName("Test");
URLClassLoader apploader = (URLClassLoader)cl.getClassLoader(); ClassLoader apploader = cl.getClassLoader();
// Test every divisor between -100 and 100. // Test every divisor between -100 and 100.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
* @test * @test
* @bug 6800154 * @bug 6800154
* @summary Add comments to long_by_long_mulhi() for better understandability * @summary Add comments to long_by_long_mulhi() for better understandability
* * @library /testlibrary
* @run main/othervm -Xcomp -XX:CompileOnly=Test6800154.divcomp Test6800154 * @run main/othervm -Xcomp -XX:CompileOnly=Test6800154.divcomp Test6800154
*/ */
import java.net.URLClassLoader; import jdk.test.lib.Utils;
public class Test6800154 implements Runnable { public class Test6800154 implements Runnable {
static final long[] DIVIDENDS = { static final long[] DIVIDENDS = {
@ -78,12 +78,13 @@ public class Test6800154 implements Runnable {
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
Class cl = Class.forName("Test6800154"); Class cl = Class.forName("Test6800154");
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader(); ClassLoader apploader = cl.getClassLoader();
// Iterate over all divisors. // Iterate over all divisors.
for (int i = 0; i < DIVISORS.length; i++) { for (int i = 0; i < DIVISORS.length; i++) {
System.setProperty("divisor", "" + DIVISORS[i]); System.setProperty("divisor", "" + DIVISORS[i]);
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent()); ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass("Test6800154"); Class c = loader.loadClass("Test6800154");
Runnable r = (Runnable) c.newInstance(); Runnable r = (Runnable) c.newInstance();
r.run(); r.run();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,12 +24,13 @@
/** /**
* @test * @test
* @bug 6805724 * @bug 6805724
* @summary ModLNode::Ideal() generates functionally incorrect graph when divisor is any (2^k-1) constant. * @summary ModLNode::Ideal() generates functionally incorrect graph
* * when divisor is any (2^k-1) constant.
* @library /testlibrary
* @run main/othervm -Xcomp -XX:CompileOnly=Test6805724.fcomp Test6805724 * @run main/othervm -Xcomp -XX:CompileOnly=Test6805724.fcomp Test6805724
*/ */
import java.net.URLClassLoader; import jdk.test.lib.Utils;
public class Test6805724 implements Runnable { public class Test6805724 implements Runnable {
// Initialize DIVISOR so that it is final in this class. // Initialize DIVISOR so that it is final in this class.
@ -65,13 +66,14 @@ public class Test6805724 implements Runnable {
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
Class cl = Class.forName("Test6805724"); Class cl = Class.forName("Test6805724");
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader(); ClassLoader apploader = cl.getClassLoader();
// Iterate over all 2^k-1 divisors. // Iterate over all 2^k-1 divisors.
for (int k = 1; k < Long.SIZE; k++) { for (int k = 1; k < Long.SIZE; k++) {
long divisor = (1L << k) - 1; long divisor = (1L << k) - 1;
System.setProperty("divisor", "" + divisor); System.setProperty("divisor", "" + divisor);
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent()); ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass("Test6805724"); Class c = loader.loadClass("Test6805724");
Runnable r = (Runnable) c.newInstance(); Runnable r = (Runnable) c.newInstance();
r.run(); r.run();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
* @test * @test
* @bug 6823354 * @bug 6823354
* @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions. * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
* * @library /testlibrary
* @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354 * @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354
*/ */
import java.net.URLClassLoader; import jdk.test.lib.Utils;
public class Test6823354 { public class Test6823354 {
// Arrays of corner case values. // Arrays of corner case values.
@ -197,8 +197,9 @@ public class Test6823354 {
static void loadandrunclass(String classname) throws Exception { static void loadandrunclass(String classname) throws Exception {
Class cl = Class.forName(classname); Class cl = Class.forName(classname);
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader(); ClassLoader apploader = cl.getClassLoader();
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent()); ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass(classname); Class c = loader.loadClass(classname);
Runnable r = (Runnable) c.newInstance(); Runnable r = (Runnable) c.newInstance();
r.run(); r.run();

View File

@ -23,11 +23,15 @@
package jdk.test.lib; package jdk.test.lib;
import java.io.File;
import static jdk.test.lib.Asserts.assertTrue; import static jdk.test.lib.Asserts.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -51,6 +55,11 @@ import sun.misc.Unsafe;
*/ */
public final class Utils { public final class Utils {
/**
* Returns the value of 'test.class.path' system property.
*/
public static final String TEST_CLASS_PATH = System.getProperty("test.class.path", ".");
/** /**
* Returns the sequence used by operating system to separate lines. * Returns the sequence used by operating system to separate lines.
*/ */
@ -473,6 +482,27 @@ public final class Utils {
throw new Error("Class not found", e); throw new Error("Class not found", e);
} }
} }
/**
* @param parent a class loader to be the parent for the returned one
* @return an UrlClassLoader with urls made of the 'test.class.path' jtreg
* property and with the given parent
*/
public static URLClassLoader getTestClassPathURLClassLoader(ClassLoader parent) {
URL[] urls = Arrays.stream(TEST_CLASS_PATH.split(File.pathSeparator))
.map(Paths::get)
.map(Path::toUri)
.map(x -> {
try {
return x.toURL();
} catch (MalformedURLException ex) {
throw new Error("Test issue. JTREG property"
+ " 'test.class.path'"
+ " is not defined correctly", ex);
}
}).toArray(URL[]::new);
return new URLClassLoader(urls, parent);
}
/** /**
* Runs runnable and checks that it throws expected exception. If exceptionException is null it means * Runs runnable and checks that it throws expected exception. If exceptionException is null it means
* that we expect no exception to be thrown. * that we expect no exception to be thrown.