This commit is contained in:
Alejandro Murillo 2016-01-28 16:30:39 -08:00
commit b8e0f8aa93
14 changed files with 3374 additions and 84 deletions

View File

@ -250,6 +250,7 @@ SUNWprivate_1.1 {
Java_sun_misc_Signal_raise0;
Java_sun_reflect_ConstantPool_getClassAt0;
Java_sun_reflect_ConstantPool_getClassAtIfLoaded0;
Java_sun_reflect_ConstantPool_getClassRefIndexAt0;
Java_sun_reflect_ConstantPool_getDoubleAt0;
Java_sun_reflect_ConstantPool_getFieldAt0;
Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0;
@ -259,8 +260,11 @@ SUNWprivate_1.1 {
Java_sun_reflect_ConstantPool_getMemberRefInfoAt0;
Java_sun_reflect_ConstantPool_getMethodAt0;
Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0;
Java_sun_reflect_ConstantPool_getNameAndTypeRefIndexAt0;
Java_sun_reflect_ConstantPool_getNameAndTypeRefInfoAt0;
Java_sun_reflect_ConstantPool_getSize0;
Java_sun_reflect_ConstantPool_getStringAt0;
Java_sun_reflect_ConstantPool_getTagAt0;
Java_sun_reflect_ConstantPool_getUTF8At0;
Java_java_io_Console_istty;
Java_java_io_Console_encoding;

View File

@ -351,8 +351,8 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
*/
void encryptBlock(byte[] in, int inOffset,
byte[] out, int outOffset) {
cryptBlockCheck(in, inOffset);
cryptBlockCheck(out, outOffset);
Objects.checkFromIndexSize(inOffset, AES_BLOCK_SIZE, in.length);
Objects.checkFromIndexSize(outOffset, AES_BLOCK_SIZE, out.length);
implEncryptBlock(in, inOffset, out, outOffset);
}
@ -430,8 +430,8 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
*/
void decryptBlock(byte[] in, int inOffset,
byte[] out, int outOffset) {
cryptBlockCheck(in, inOffset);
cryptBlockCheck(out, outOffset);
Objects.checkFromIndexSize(inOffset, AES_BLOCK_SIZE, in.length);
Objects.checkFromIndexSize(outOffset, AES_BLOCK_SIZE, out.length);
implDecryptBlock(in, inOffset, out, outOffset);
}
@ -593,26 +593,6 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
out[outOffset ] = (byte)(Si[(a0 ) & 0xFF] ^ (t1 ));
}
// Used to perform all checks required by the Java semantics
// (i.e., null checks and bounds checks) on the input parameters
// to encryptBlock and to decryptBlock.
// Normally, the Java Runtime performs these checks, however, as
// encryptBlock and decryptBlock are possibly replaced with
// compiler intrinsics, the JDK performs the required checks instead.
// Does not check accesses to class-internal (private) arrays.
private static void cryptBlockCheck(byte[] array, int offset) {
Objects.requireNonNull(array);
if (offset < 0 || offset >= array.length) {
throw new ArrayIndexOutOfBoundsException(offset);
}
int largestIndex = offset + AES_BLOCK_SIZE - 1;
if (largestIndex < 0 || largestIndex >= array.length) {
throw new ArrayIndexOutOfBoundsException(largestIndex);
}
}
/**
* Expand a user-supplied key material into a session key.
*

View File

@ -173,9 +173,9 @@ final class CounterMode extends FeedbackCipher {
*/
private int crypt(byte[] in, int inOff, int len, byte[] out, int outOff) {
cryptBlockCheck(in, inOff, len);
cryptBlockCheck(out, outOff, len);
return implCrypt(in, inOff, len, out, outOff);
Objects.checkFromIndexSize(inOff, len, in.length);
Objects.checkFromIndexSize(outOff, len, out.length);
return implCrypt(in, inOff, len, out, outOff);
}
// Implementation of crpyt() method. Possibly replaced with a compiler intrinsic.
@ -193,22 +193,4 @@ final class CounterMode extends FeedbackCipher {
return result;
}
// Used to perform all checks required by the Java semantics
// (i.e., null checks and bounds checks) on the input parameters to crypt().
// Normally, the Java Runtime performs these checks, however, as crypt() is
// possibly replaced with compiler intrinsic, the JDK performs the
// required checks instead.
// Does not check accesses to class-internal (private) arrays.
private static void cryptBlockCheck(byte[] array, int offset, int len) {
Objects.requireNonNull(array);
if (offset < 0 || len < 0 || offset >= array.length) {
throw new ArrayIndexOutOfBoundsException(offset);
}
int largestIndex = offset + len - 1;
if (largestIndex < 0 || largestIndex >= array.length) {
throw new ArrayIndexOutOfBoundsException(largestIndex);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -36,6 +36,10 @@ public class ConstantPool {
public int getSize() { return getSize0 (constantPoolOop); }
public Class<?> getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
// Returns a class reference index for a method or a field.
public int getClassRefIndexAt(int index) {
return getClassRefIndexAt0(constantPoolOop, index);
}
// Returns either a Method or Constructor.
// Static initializers are returned as Method objects.
public Member getMethodAt (int index) { return getMethodAt0 (constantPoolOop, index); }
@ -45,13 +49,56 @@ public class ConstantPool {
// Fetches the class name, member (field, method or interface
// method) name, and type descriptor as an array of three Strings
public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }
// Returns a name and type reference index for a method, a field or an invokedynamic.
public int getNameAndTypeRefIndexAt(int index) {
return getNameAndTypeRefIndexAt0(constantPoolOop, index);
}
// Fetches the name and type from name_and_type index as an array of two Strings
public String[] getNameAndTypeRefInfoAt(int index) {
return getNameAndTypeRefInfoAt0(constantPoolOop, index);
}
public int getIntAt (int index) { return getIntAt0 (constantPoolOop, index); }
public long getLongAt (int index) { return getLongAt0 (constantPoolOop, index); }
public float getFloatAt (int index) { return getFloatAt0 (constantPoolOop, index); }
public double getDoubleAt (int index) { return getDoubleAt0 (constantPoolOop, index); }
public String getStringAt (int index) { return getStringAt0 (constantPoolOop, index); }
public String getUTF8At (int index) { return getUTF8At0 (constantPoolOop, index); }
public Tag getTagAt(int index) {
return Tag.valueOf(getTagAt0(constantPoolOop, index));
}
public static enum Tag {
UTF8(1),
INTEGER(3),
FLOAT(4),
LONG(5),
DOUBLE(6),
CLASS(7),
STRING(8),
FIELDREF(9),
METHODREF(10),
INTERFACEMETHODREF(11),
NAMEANDTYPE(12),
METHODHANDLE(15),
METHODTYPE(16),
INVOKEDYNAMIC(18),
INVALID(0);
private final int tagCode;
private Tag(int tagCode) {
this.tagCode = tagCode;
}
private static Tag valueOf(byte v) {
for (Tag tag : Tag.values()) {
if (tag.tagCode == v) {
return tag;
}
}
throw new IllegalArgumentException("Unknown constant pool tag code " + v);
}
}
//---------------------------------------------------------------------------
// Internals only below this point
//
@ -66,15 +113,19 @@ public class ConstantPool {
private native int getSize0 (Object constantPoolOop);
private native Class<?> getClassAt0 (Object constantPoolOop, int index);
private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
private native int getClassRefIndexAt0 (Object constantPoolOop, int index);
private native Member getMethodAt0 (Object constantPoolOop, int index);
private native Member getMethodAtIfLoaded0(Object constantPoolOop, int index);
private native Field getFieldAt0 (Object constantPoolOop, int index);
private native Field getFieldAtIfLoaded0 (Object constantPoolOop, int index);
private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
private native int getNameAndTypeRefIndexAt0(Object constantPoolOop, int index);
private native String[] getNameAndTypeRefInfoAt0(Object constantPoolOop, int index);
private native int getIntAt0 (Object constantPoolOop, int index);
private native long getLongAt0 (Object constantPoolOop, int index);
private native float getFloatAt0 (Object constantPoolOop, int index);
private native double getDoubleAt0 (Object constantPoolOop, int index);
private native String getStringAt0 (Object constantPoolOop, int index);
private native String getUTF8At0 (Object constantPoolOop, int index);
private native byte getTagAt0 (Object constantPoolOop, int index);
}

View File

@ -63,7 +63,7 @@ extern "C" {
* class.
*/
#define JVM_INTERFACE_VERSION 4
#define JVM_INTERFACE_VERSION 5
JNIEXPORT jint JNICALL
JVM_GetInterfaceVersion(void);
@ -502,6 +502,9 @@ JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt
JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded
(JNIEnv *env, jobject unused, jobject jcpool, jint index);
JNIEXPORT jint JNICALL JVM_ConstantPoolGetClassRefIndexAt
(JNIEnv *env, jobject obj, jobject unused, jint index);
JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt
(JNIEnv *env, jobject unused, jobject jcpool, jint index);
@ -517,6 +520,12 @@ JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded
JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt
(JNIEnv *env, jobject unused, jobject jcpool, jint index);
JNIEXPORT jint JNICALL JVM_ConstantPoolGetNameAndTypeRefIndexAt
(JNIEnv *env, jobject obj, jobject unused, jint index);
JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetNameAndTypeRefInfoAt
(JNIEnv *env, jobject obj, jobject unused, jint index);
JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt
(JNIEnv *env, jobject unused, jobject jcpool, jint index);
@ -535,6 +544,9 @@ JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt
JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At
(JNIEnv *env, jobject unused, jobject jcpool, jint index);
JNIEXPORT jbyte JNICALL JVM_ConstantPoolGetTagAt
(JNIEnv *env, jobject unused, jobject jcpool, jint index);
/*
* Parameter reflection
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -44,6 +44,12 @@ JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0
return JVM_ConstantPoolGetClassAtIfLoaded(env, unused, jcpool, index);
}
JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getClassRefIndexAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassRefIndexAt(env, unused, jcpool, index);
}
JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
@ -74,6 +80,18 @@ JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0
return JVM_ConstantPoolGetMemberRefInfoAt(env, unused, jcpool, index);
}
JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getNameAndTypeRefIndexAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetNameAndTypeRefIndexAt(env, unused, jcpool, index);
}
JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getNameAndTypeRefInfoAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetNameAndTypeRefInfoAt(env, unused, jcpool, index);
}
JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
@ -109,3 +127,10 @@ JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getUTF8At0
{
return JVM_ConstantPoolGetUTF8At(env, unused, jcpool, index);
}
JNIEXPORT jbyte JNICALL Java_sun_reflect_ConstantPool_getTagAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetTagAt(env, unused, jcpool, index);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, 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,8 +24,6 @@
/*
* @test
* @bug 8028994
* @ignore 8147477
* @ignore 8147494
* @author Staffan Larsen
* @library /lib/testlibrary
* @modules jdk.attach/sun.tools.attach
@ -73,7 +71,7 @@ public class CheckOrigin {
Map<String, String> env = pb.environment();
// "UseCMSGC" should be ignored.
env.put("_JAVA_OPTIONS", "-XX:+TraceExceptions -XX:+UseCMSGC");
env.put("_JAVA_OPTIONS", "-XX:+CheckJNICalls -XX:+UseCMSGC");
// "UseGOneGC" should be ignored.
env.put("JAVA_TOOL_OPTIONS", "-XX:+IgnoreUnrecognizedVMOptions "
+ "-XX:+PrintVMOptions -XX:+UseGOneGC");
@ -101,7 +99,7 @@ public class CheckOrigin {
// Set on the command line
checkOrigin("UseCodeAging", Origin.VM_CREATION);
// Set in _JAVA_OPTIONS
checkOrigin("TraceExceptions", Origin.ENVIRON_VAR);
checkOrigin("CheckJNICalls", Origin.ENVIRON_VAR);
// Set in JAVA_TOOL_OPTIONS
checkOrigin("IgnoreUnrecognizedVMOptions", Origin.ENVIRON_VAR);
checkOrigin("PrintVMOptions", Origin.ENVIRON_VAR);

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2016, 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
@ -62,6 +62,25 @@ public class ClassToInterfaceConverter implements ClassFilePreprocessor {
}
}
cf.methods = new_methods;
// Convert method tag. Find Methodref, which is not "<init>" and only invoked by other methods
// in the interface, convert it to InterfaceMethodref
ArrayList<ClassFile.CpEntry> cpool = new ArrayList<>();
for (int i = 0; i < cf.constant_pool.size(); i++) {
ClassFile.CpEntry ce = cf.constant_pool.get(i);
if (ce instanceof ClassFile.CpMethodRef) {
ClassFile.CpMethodRef me = (ClassFile.CpMethodRef)ce;
ClassFile.CpNameAndType nameType = (ClassFile.CpNameAndType)cf.constant_pool.get(me.name_and_type_index);
ClassFile.CpEntry name = cf.constant_pool.get(nameType.name_index);
if (!utf8Matches(name, "<init>") && cf.this_class == me.class_index) {
ClassFile.CpInterfaceMethodRef newEntry = new ClassFile.CpInterfaceMethodRef();
newEntry.class_index = me.class_index;
newEntry.name_and_type_index = me.name_and_type_index;
ce = newEntry;
}
}
cpool.add(ce);
}
cf.constant_pool = cpool;
}
public byte[] preprocess(String classname, byte[] bytes) {

View File

@ -130,7 +130,7 @@ public class JMXAgentInterfaceBinding {
private static class JMXConnectorThread extends Thread {
private final InetAddress addr;
private final String addr;
private final int jmxPort;
private final int rmiPort;
private final boolean useSSL;
@ -139,7 +139,7 @@ public class JMXAgentInterfaceBinding {
private boolean jmxConnectWorked;
private boolean rmiConnectWorked;
private JMXConnectorThread(InetAddress addr,
private JMXConnectorThread(String addr,
int jmxPort,
int rmiPort,
boolean useSSL,
@ -163,11 +163,11 @@ public class JMXAgentInterfaceBinding {
private void connect() throws IOException {
System.out.println(
"JMXConnectorThread: Attempting JMX connection on: "
+ addr.getHostAddress() + " on port " + jmxPort);
+ addr + " on port " + jmxPort);
JMXServiceURL url;
try {
url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"
+ addr.getHostAddress() + ":" + jmxPort + "/jmxrmi");
+ addr + ":" + jmxPort + "/jmxrmi");
} catch (MalformedURLException e) {
throw new RuntimeException("Test failed.", e);
}
@ -200,7 +200,7 @@ public class JMXAgentInterfaceBinding {
}
System.out.println(
"JMXConnectorThread: connection to rmi socket worked host/port = "
+ addr.getHostAddress() + "/" + rmiPort);
+ addr + "/" + rmiPort);
rmiConnectWorked = true;
// Closing the channel without sending any data will cause an
// java.io.EOFException on the server endpoint. We don't care about this
@ -224,7 +224,7 @@ public class JMXAgentInterfaceBinding {
private static class MainThread extends Thread {
private static final int WAIT_FOR_JMX_AGENT_TIMEOUT_MS = 500;
private final InetAddress bindAddress;
private final String addr;
private final int jmxPort;
private final int rmiPort;
private final boolean useSSL;
@ -233,7 +233,7 @@ public class JMXAgentInterfaceBinding {
private Exception excptn;
private MainThread(InetAddress bindAddress, int jmxPort, int rmiPort, boolean useSSL) {
this.bindAddress = bindAddress;
this.addr = wrapAddress(bindAddress.getHostAddress());
this.jmxPort = jmxPort;
this.rmiPort = rmiPort;
this.useSSL = useSSL;
@ -259,7 +259,7 @@ public class JMXAgentInterfaceBinding {
private void waitUntilReadyForConnections() {
CountDownLatch latch = new CountDownLatch(1);
JMXConnectorThread connectionTester = new JMXConnectorThread(
bindAddress, jmxPort, rmiPort, useSSL, latch);
addr, jmxPort, rmiPort, useSSL, latch);
connectionTester.start();
boolean expired = false;
try {
@ -294,4 +294,13 @@ public class JMXAgentInterfaceBinding {
}
}
/**
* Will wrap IPv6 address in '[]'
*/
static String wrapAddress(String address) {
if (address.contains(":")) {
return "[" + address + "]";
}
return address;
}
}

View File

@ -23,9 +23,11 @@
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import jdk.testlibrary.ProcessThread;
import jdk.testlibrary.ProcessTools;
@ -72,25 +74,28 @@ public class JMXInterfaceBindingTest {
"truststore";
public static final String TEST_CLASSPATH = System.getProperty("test.classes", ".");
public void run(InetAddress[] addrs) {
public void run(List<InetAddress> addrs) {
System.out.println("DEBUG: Running tests with plain sockets.");
runTests(addrs, false);
System.out.println("DEBUG: Running tests with SSL sockets.");
runTests(addrs, true);
}
private void runTests(InetAddress[] addrs, boolean useSSL) {
ProcessThread[] jvms = new ProcessThread[addrs.length];
for (int i = 0; i < addrs.length; i++) {
private void runTests(List<InetAddress> addrs, boolean useSSL) {
List<ProcessThread> jvms = new ArrayList<>(addrs.size());
int i = 1;
for (InetAddress addr : addrs) {
String address = JMXAgentInterfaceBinding.wrapAddress(addr.getHostAddress());
System.out.println();
String msg = String.format("DEBUG: Launching java tester for triplet (HOSTNAME,JMX_PORT,RMI_PORT) == (%s,%d,%d)",
addrs[i].getHostAddress(),
address,
JMX_PORT,
RMI_PORT);
System.out.println(msg);
jvms[i] = runJMXBindingTest(addrs[i], useSSL);
jvms[i].start();
System.out.println("DEBUG: Started " + (i + 1) + " Process(es).");
ProcessThread jvm = runJMXBindingTest(address, useSSL);
jvms.add(jvm);
jvm.start();
System.out.println("DEBUG: Started " + (i++) + " Process(es).");
}
int failedProcesses = 0;
for (ProcessThread pt: jvms) {
@ -117,15 +122,15 @@ public class JMXInterfaceBindingTest {
}
}
if (failedProcesses > 0) {
throw new RuntimeException("Test FAILED. " + failedProcesses + " out of " + addrs.length + " process(es) failed to start the JMX agent.");
throw new RuntimeException("Test FAILED. " + failedProcesses + " out of " + addrs.size() + " process(es) failed to start the JMX agent.");
}
}
private ProcessThread runJMXBindingTest(InetAddress a, boolean useSSL) {
private ProcessThread runJMXBindingTest(String address, boolean useSSL) {
List<String> args = new ArrayList<>();
args.add("-classpath");
args.add(TEST_CLASSPATH);
args.add("-Dcom.sun.management.jmxremote.host=" + a.getHostAddress());
args.add("-Dcom.sun.management.jmxremote.host=" + address);
args.add("-Dcom.sun.management.jmxremote.port=" + JMX_PORT);
args.add("-Dcom.sun.management.jmxremote.rmi.port=" + RMI_PORT);
args.add("-Dcom.sun.management.jmxremote.authenticate=false");
@ -138,14 +143,14 @@ public class JMXInterfaceBindingTest {
args.add("-Djavax.net.ssl.trustStorePassword=trustword");
}
args.add(TEST_CLASS);
args.add(a.getHostAddress());
args.add(address);
args.add(Integer.toString(JMX_PORT));
args.add(Integer.toString(RMI_PORT));
args.add(Boolean.toString(useSSL));
try {
ProcessBuilder builder = ProcessTools.createJavaProcessBuilder(args.toArray(new String[] {}));
System.out.println(ProcessTools.getCommandLine(builder));
ProcessThread jvm = new ProcessThread("JMX-Tester-" + a.getHostAddress(), JMXInterfaceBindingTest::isJMXAgentResponseAvailable, builder);
ProcessThread jvm = new ProcessThread("JMX-Tester-" + address, JMXInterfaceBindingTest::isJMXAgentResponseAvailable, builder);
return jvm;
} catch (Exception e) {
throw new RuntimeException("Test failed", e);
@ -171,8 +176,8 @@ public class JMXInterfaceBindingTest {
}
public static void main(String[] args) {
InetAddress[] addrs = getAddressesForLocalHost();
if (addrs.length < 2) {
List<InetAddress> addrs = getAddressesForLocalHost();
if (addrs.size() < 2) {
System.out.println("Ignoring manual test since no more than one IPs are configured for 'localhost'");
return;
}
@ -181,13 +186,24 @@ public class JMXInterfaceBindingTest {
System.out.println("All tests PASSED.");
}
private static InetAddress[] getAddressesForLocalHost() {
InetAddress[] addrs;
private static List<InetAddress> getAddressesForLocalHost() {
try {
addrs = InetAddress.getAllByName("localhost");
} catch (UnknownHostException e) {
return NetworkInterface.networkInterfaces()
.flatMap(NetworkInterface::inetAddresses)
.filter(JMXInterfaceBindingTest::isNonloopbackLocalhost)
.collect(Collectors.toList());
} catch (SocketException e) {
throw new RuntimeException("Test failed", e);
}
return addrs;
}
// we need 'real' localhost addresses only (eg. not loopback ones)
// so we can bind the remote JMX connector to them
private static boolean isNonloopbackLocalhost(InetAddress i) {
if (!i.isLoopbackAddress()) {
return i.getHostName().toLowerCase().equals("localhost");
}
return false;
}
}

View File

@ -0,0 +1,170 @@
/*
* Copyright (c) 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
* 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 8141615
* @summary Tests new public methods at sun.reflect.ConstantPool
* @modules java.base/sun.reflect
* @library /lib/testlibrary
* @compile ConstantPoolTestDummy.jasm
* @run main sun.reflect.constantPool.ConstantPoolTest
*/
package sun.reflect.constantPool;
import java.util.HashMap;
import java.util.Map;
import jdk.internal.misc.SharedSecrets;
import jdk.testlibrary.Asserts;
import sun.reflect.ConstantPool;
public class ConstantPoolTest {
private static final Class<?> TEST_CLASS = ConstantPoolTestDummy.class;
private static final ConstantPool CP = SharedSecrets.getJavaLangAccess()
.getConstantPool(TEST_CLASS);
public static void main(String[] s) {
for (TestCase testCase : TestCase.values()) {
testCase.test();
}
}
public static enum TestCase {
GET_TAG_AT {
{
referenceMap.put(1, ConstantPool.Tag.METHODREF);
referenceMap.put(2, ConstantPool.Tag.CLASS);
referenceMap.put(4, ConstantPool.Tag.UTF8);
referenceMap.put(10, ConstantPool.Tag.NAMEANDTYPE);
referenceMap.put(13, ConstantPool.Tag.LONG);
referenceMap.put(15, ConstantPool.Tag.INTEGER);
referenceMap.put(16, ConstantPool.Tag.INTERFACEMETHODREF);
referenceMap.put(21, ConstantPool.Tag.DOUBLE);
referenceMap.put(23, ConstantPool.Tag.STRING);
referenceMap.put(25, ConstantPool.Tag.INVOKEDYNAMIC);
referenceMap.put(29, ConstantPool.Tag.METHODHANDLE);
referenceMap.put(30, ConstantPool.Tag.METHODTYPE);
referenceMap.put(48, ConstantPool.Tag.FIELDREF);
referenceMap.put(52, ConstantPool.Tag.FLOAT);
}
@Override
void testIndex(int cpi, Object reference) {
ConstantPool.Tag tagToVerify = CP.getTagAt(cpi);
ConstantPool.Tag tagToRefer = (ConstantPool.Tag) reference;
String msg = String.format("Method getTagAt works not as expected"
+ "at CP entry #%d: got CP tag %s, but should be %s",
cpi, tagToVerify.name(), tagToRefer.name());
Asserts.assertEquals(tagToVerify, tagToRefer, msg);
}
},
GET_CLASS_REF_INDEX_AT {
{
referenceMap.put(1, 3);
referenceMap.put(16, 17);
referenceMap.put(32, 35);
referenceMap.put(34, 3);
referenceMap.put(48, 2);
}
@Override
void testIndex(int cpi, Object reference) {
int indexToVerify = CP.getClassRefIndexAt(cpi);
int indexToRefer = (int) reference;
String msg = String.format("Method getClassRefIndexAt works not"
+ " as expected at CP entry #%d:"
+ " got index %d, but should be %d",
cpi, indexToVerify, indexToRefer);
Asserts.assertEquals(indexToVerify, indexToRefer, msg);
}
},
GET_NAME_AND_TYPE_REF_INDEX_AT {
{
referenceMap.put(1, 10);
referenceMap.put(16, 18);
referenceMap.put(25, 26);
referenceMap.put(32, 36);
referenceMap.put(34, 37);
referenceMap.put(48, 49);
}
@Override
void testIndex(int cpi, Object reference) {
int indexToRefer = (int) reference;
int indexToVerify = CP.getNameAndTypeRefIndexAt(cpi);
String msg = String.format("Method getNameAndTypeRefIndexAt works"
+ " not as expected at CP entry #%d:"
+ " got index %d, but should be %d",
cpi, indexToVerify, indexToRefer);
Asserts.assertEquals(indexToVerify, indexToRefer, msg);
}
},
GET_NAME_AND_TYPE_REF_INFO_AT {
{
referenceMap.put(10, new String[]{"<init>", "()V"});
referenceMap.put(18, new String[]{"run", "()V"});
referenceMap.put(26, new String[]{"accept", "()Ljava/util/function/Consumer;"});
referenceMap.put(36, new String[]{"metafactory",
"(Ljava/lang/invoke/MethodHandles$Lookup;"
+ "Ljava/lang/String;Ljava/lang/invoke/MethodType;"
+ "Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;"
+ "Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"});
referenceMap.put(37, new String[]{"toString", "()Ljava/lang/String;"});
referenceMap.put(49, new String[]{"myField", "I"});
}
@Override
void testIndex(int cpi, Object reference) {
String[] natInfo = CP.getNameAndTypeRefInfoAt(cpi);
String msg = String.format("Method getNameAndTypeRefInfoAt"
+ " works not as expected at CP entry #%d:"
+ " returned value should not be null", cpi);
Asserts.assertNotNull(natInfo, msg);
String[] castedReference = (String[]) reference;
int natInfoLength = natInfo.length;
msg = String.format("Method getNameAndTypeRefInfoAt"
+ " works not as expected at CP entry #%d:"
+ " length of the returned string array is %d, but should be 2",
cpi, natInfoLength);
Asserts.assertEquals(natInfoLength, 2, msg);
String[] nameOrType = new String[]{"name", "type"};
for (int i = 0; i < 2; i++) {
String infoToVerify = natInfo[i];
String infoToRefer = castedReference[i];
msg = String.format("Method getNameAndTypeRefInfoAt"
+ " works not as expected at CP entry #%d:"
+ " got %s info %s, but should be %s",
cpi, nameOrType[i], infoToVerify, infoToRefer);
Asserts.assertEquals(infoToVerify, infoToRefer, msg);
}
}
};
protected final Map<Integer, Object> referenceMap;
TestCase() {
this.referenceMap = new HashMap<>();
}
abstract void testIndex(int cpi, Object reference);
public void test() {
referenceMap.forEach(this::testIndex);
}
}
}

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 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
* 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 sun/reflect/constantPool;
super public #2; //class ConstantPoolTestDummy
version 52:0
{
// Actually, only first 13 constant pool entries are actually used by the class
// and its methods. All the rest are added just for the testing of getTagAt method
// and getNameAndTypeRefIndexAt method.
const #1 = Method #3.#10; // java/lang/Object."<init>":"()V"
const #2 = class #11; // ConstantPoolTestDummy
const #3 = class #12; // java/lang/Object
const #4 = Asciz "<init>";
const #5 = Asciz "()V";
const #6 = Asciz "Code";
const #7 = Asciz "LineNumberTable";
const #8 = Asciz "SourceFile";
const #9 = Asciz "ConstantPoolTestDummy.java";
const #10 = NameAndType #4:#5; // "<init>":"()V"
const #11 = Asciz "sun/reflect/constantPool/ConstantPoolTestDummy";
const #12 = Asciz "java/lang/Object";
const #13 = long 6l;
const #15 = int 1;
const #16 = InterfaceMethod #17.#18; // java/lang/Runnable.run:"()V"
const #17 = class #19; // java/lang/Runnable
const #18 = NameAndType #20:#5; // run:"()V"
const #19 = Asciz "java/lang/Runnable";
const #20 = Asciz "run";
const #21 = double 1.45d;
const #23 = String #24; // "Hello"
const #24 = Asciz "Hello";
const #25 = InvokeDynamic 0:#26; // REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;":accept:"()Ljava/util/function/Consumer;" MethodType "(Ljava/lang/Object;)V", MethodHandle REF_invokeVirtual:java/lang/Object.toString:"()Ljava/lang/String;", MethodType "(Ljava/lang/Object;)V"
const #26 = NameAndType #27:#28; // accept:"()Ljava/util/function/Consumer;"
const #27 = Asciz "accept";
const #28 = Asciz "()Ljava/util/function/Consumer;";
const #29 = MethodHandle 6:#32; // REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
const #30 = MethodType #33; // "(Ljava/lang/Object;)V"
const #31 = MethodHandle 5:#34; // REF_invokeVirtual:java/lang/Object.toString:"()Ljava/lang/String;"
const #32 = Method #35.#36; // java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
const #33 = Asciz "(Ljava/lang/Object;)V";
const #34 = Method #3.#37; // java/lang/Object.toString:"()Ljava/lang/String;"
const #35 = class #38; // java/lang/invoke/LambdaMetafactory
const #36 = NameAndType #39:#40; // metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
const #37 = NameAndType #41:#42; // toString:"()Ljava/lang/String;"
const #38 = Asciz "java/lang/invoke/LambdaMetafactory";
const #39 = Asciz "metafactory";
const #40 = Asciz "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;";
const #41 = Asciz "toString";
const #42 = Asciz "()Ljava/lang/String;";
const #43 = class #46; // java/lang/invoke/MethodHandles$Lookup
const #44 = Asciz "Lookup";
const #45 = class #47; // java/lang/invoke/MethodHandles
const #46 = Asciz "java/lang/invoke/MethodHandles$Lookup";
const #47 = Asciz "java/lang/invoke/MethodHandles";
const #48 = Field #2.#49; // sun/reflect/constantPool/ConstantPoolTestDummy.myField:"I"
const #49 = NameAndType #50:#51; // myField:"I"
const #50 = Asciz "myField";
const #51 = Asciz "I";
const #52 = float 1.34f;
public Method #4:#5 // "<init>":"()V"
stack 1 locals 1
{
3 0: aload_0;
1: invokespecial #1; // Method java/lang/Object."<init>":"()V";
4: return;
}
public static final InnerClass #44= #43 of #45; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
BootstrapMethod #29 #30 #31 #30;
} // end Class ConstantPoolTestDummy

View File

@ -24,7 +24,6 @@
/*
* @test
* @bug 6762191
* @ignore 8146751
* @summary Setting stack size to 16K causes segmentation fault
* @compile TooSmallStackSize.java
* @run main TooSmallStackSize