diff --git a/src/share/classes/java/lang/Class.java b/src/share/classes/java/lang/Class.java index eb2b8b80a76d79098a645657d34d1f9d8fec1e65..2440baaaba545a6775c64f0a65635389641bb0eb 100644 --- a/src/share/classes/java/lang/Class.java +++ b/src/share/classes/java/lang/Class.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2014, 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 @@ -130,11 +130,15 @@ public final class Class implements java.io.Serializable, } /* - * Constructor. Only the Java Virtual Machine creates Class - * objects. + * Private constructor. Only the Java Virtual Machine creates Class objects. + * This constructor is not used and prevents the default constructor being + * generated. */ - private Class() {} - + private Class(ClassLoader loader) { + // Initialize final field for classLoader. The initialization value of non-null + // prevents future JIT optimizations from assuming this final field is null. + classLoader = loader; + } /** * Converts the object to a string. The string representation is the @@ -677,8 +681,10 @@ public final class Class implements java.io.Serializable, } // Package-private to allow ClassLoader access - native ClassLoader getClassLoader0(); + ClassLoader getClassLoader0() { return classLoader; } + // Initialized in JVM not by private constructor + private final ClassLoader classLoader; /** * Returns an array of {@code TypeVariable} objects that represent the diff --git a/src/share/classes/java/lang/reflect/AccessibleObject.java b/src/share/classes/java/lang/reflect/AccessibleObject.java index f98aed5db25e3f29e19df4e8d2314fbd92a719a9..0bf5e0eea417d12b264bb493258acecb535917b0 100644 --- a/src/share/classes/java/lang/reflect/AccessibleObject.java +++ b/src/share/classes/java/lang/reflect/AccessibleObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, 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 @@ -129,16 +129,24 @@ public class AccessibleObject implements AnnotatedElement { setAccessible0(this, flag); } - /* Check that you aren't exposing java.lang.Class.. */ + /* Check that you aren't exposing java.lang.Class. or sensitive + fields in java.lang.Class. */ private static void setAccessible0(AccessibleObject obj, boolean flag) throws SecurityException { if (obj instanceof Constructor && flag == true) { Constructor c = (Constructor)obj; if (c.getDeclaringClass() == Class.class) { - throw new SecurityException("Can not make a java.lang.Class" + + throw new SecurityException("Cannot make a java.lang.Class" + " constructor accessible"); } + } else if (obj instanceof Field && flag == true) { + Field f = (Field)obj; + if (f.getDeclaringClass() == Class.class && + f.getName().equals("classLoader")) { + throw new SecurityException("Cannot make java.lang.Class.classLoader" + + " accessible"); + } } obj.override = flag; } diff --git a/src/share/javavm/export/jvm.h b/src/share/javavm/export/jvm.h index 2bef0812054f6a71e90f00e1273a1684750deb51..396ca68558e20b3023db6c55809fa23cbe0db769 100644 --- a/src/share/javavm/export/jvm.h +++ b/src/share/javavm/export/jvm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, 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 @@ -426,9 +426,6 @@ JVM_GetClassName(JNIEnv *env, jclass cls); JNIEXPORT jobjectArray JNICALL JVM_GetClassInterfaces(JNIEnv *env, jclass cls); -JNIEXPORT jobject JNICALL -JVM_GetClassLoader(JNIEnv *env, jclass cls); - JNIEXPORT jboolean JNICALL JVM_IsInterface(JNIEnv *env, jclass cls); diff --git a/src/share/native/common/check_code.c b/src/share/native/common/check_code.c index 92d96b19675c1a852e27b672811876d2b2b0d44f..4ffbd67eaf246a6c68ec4a68365c9a7d82f5cb06 100644 --- a/src/share/native/common/check_code.c +++ b/src/share/native/common/check_code.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2014, 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 @@ -1357,16 +1357,9 @@ verify_opcode_operands(context_type *context, unsigned int inumber, int offset) } (*env)->DeleteLocalRef(env, super); - /* The optimizer make cause this to happen on local code */ + /* The optimizer may cause this to happen on local code */ if (not_found) { -#ifdef BROKEN_JAVAC - jobject loader = JVM_GetClassLoader(env, context->class); - int has_loader = (loader != 0); - (*env)->DeleteLocalRef(env, loader); - if (has_loader) -#endif /* BROKEN_JAVAC */ - CCerror(context, - "Illegal use of nonvirtual function call"); + CCerror(context, "Illegal use of nonvirtual function call"); } } } diff --git a/src/share/native/java/lang/Class.c b/src/share/native/java/lang/Class.c index b0ba34349d8d19ebcaffc1d77cfabd5e57c01124..c5e717fe0df57c6736376189aa5c8d980ae16ba3 100644 --- a/src/share/native/java/lang/Class.c +++ b/src/share/native/java/lang/Class.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2014, 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 @@ -45,7 +45,6 @@ extern jboolean VerifyFixClassname(char *utf_name); #define CLS "Ljava/lang/Class;" #define CPL "Lsun/reflect/ConstantPool;" #define STR "Ljava/lang/String;" -#define JCL "Ljava/lang/ClassLoader;" #define FLD "Ljava/lang/reflect/Field;" #define MHD "Ljava/lang/reflect/Method;" #define CTR "Ljava/lang/reflect/Constructor;" @@ -56,7 +55,6 @@ static JNINativeMethod methods[] = { {"getName0", "()" STR, (void *)&JVM_GetClassName}, {"getSuperclass", "()" CLS, NULL}, {"getInterfaces0", "()[" CLS, (void *)&JVM_GetClassInterfaces}, - {"getClassLoader0", "()" JCL, (void *)&JVM_GetClassLoader}, {"isInterface", "()Z", (void *)&JVM_IsInterface}, {"getSigners", "()[" OBJ, (void *)&JVM_GetClassSigners}, {"setSigners", "([" OBJ ")V", (void *)&JVM_SetClassSigners}, @@ -81,7 +79,6 @@ static JNINativeMethod methods[] = { #undef OBJ #undef CLS #undef STR -#undef JCL #undef FLD #undef MHD #undef CTR