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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
* @test
* @bug 5057225
* @summary Remove useless I2L conversions
*
* @library /testlibrary
* @run main/othervm -Xcomp -XX:CompileOnly=Test5057225.doload Test5057225
*/
import java.net.URLClassLoader;
import jdk.test.lib.Utils;
public class Test5057225 {
static byte[] ba = new byte[] { -1 };
@ -89,8 +89,9 @@ public class Test5057225 {
static void loadAndRunClass(String classname) throws Exception {
Class cl = Class.forName(classname);
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
ClassLoader apploader = cl.getClassLoader();
ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass(classname);
Runnable r = (Runnable) c.newInstance();
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
* @test
* @bug 6603011
* @summary long/int division by constant
*
* @library /testlibrary
* @run main/othervm -Xcomp -Xbatch -XX:-Inline Test
*/
@ -36,7 +36,7 @@
// dividend and divisor combinations are tested
//
import java.net.*;
import jdk.test.lib.Utils;
class s {
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
// any divisions or mod operations into multiplies.
public static void test_divisor(int divisor,
URLClassLoader apploader) throws Exception {
ClassLoader apploader) throws Exception {
System.setProperty("divisor", "" + divisor);
ClassLoader loader = new URLClassLoader(apploader.getURLs(),
apploader.getParent());
ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass("Test");
Runnable r = (Runnable)c.newInstance();
r.run();
@ -200,7 +200,7 @@ public class Test implements Runnable {
public static void main(String[] args) throws Exception {
Class cl = Class.forName("Test");
URLClassLoader apploader = (URLClassLoader)cl.getClassLoader();
ClassLoader apploader = cl.getClassLoader();
// 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
* @test
* @bug 6800154
* @summary Add comments to long_by_long_mulhi() for better understandability
*
* @library /testlibrary
* @run main/othervm -Xcomp -XX:CompileOnly=Test6800154.divcomp Test6800154
*/
import java.net.URLClassLoader;
import jdk.test.lib.Utils;
public class Test6800154 implements Runnable {
static final long[] DIVIDENDS = {
@ -78,12 +78,13 @@ public class Test6800154 implements Runnable {
public static void main(String[] args) throws Exception
{
Class cl = Class.forName("Test6800154");
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
ClassLoader apploader = cl.getClassLoader();
// Iterate over all divisors.
for (int i = 0; i < DIVISORS.length; 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");
Runnable r = (Runnable) c.newInstance();
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,12 +24,13 @@
/**
* @test
* @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
*/
import java.net.URLClassLoader;
import jdk.test.lib.Utils;
public class Test6805724 implements Runnable {
// 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 {
Class cl = Class.forName("Test6805724");
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
ClassLoader apploader = cl.getClassLoader();
// Iterate over all 2^k-1 divisors.
for (int k = 1; k < Long.SIZE; k++) {
long divisor = (1L << k) - 1;
System.setProperty("divisor", "" + divisor);
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass("Test6805724");
Runnable r = (Runnable) c.newInstance();
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
* @test
* @bug 6823354
* @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
*/
import java.net.URLClassLoader;
import jdk.test.lib.Utils;
public class Test6823354 {
// Arrays of corner case values.
@ -197,8 +197,9 @@ public class Test6823354 {
static void loadandrunclass(String classname) throws Exception {
Class cl = Class.forName(classname);
URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
ClassLoader apploader = cl.getClassLoader();
ClassLoader loader
= Utils.getTestClassPathURLClassLoader(apploader.getParent());
Class c = loader.loadClass(classname);
Runnable r = (Runnable) c.newInstance();
r.run();

View File

@ -23,11 +23,15 @@
package jdk.test.lib;
import java.io.File;
import static jdk.test.lib.Asserts.assertTrue;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
@ -51,6 +55,11 @@ import sun.misc.Unsafe;
*/
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.
*/
@ -473,6 +482,27 @@ public final class Utils {
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
* that we expect no exception to be thrown.