mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8349145: Make Class.getProtectionDomain() non-native
Reviewed-by: liach, dholmes, yzheng
This commit is contained in:
parent
e700460b49
commit
ed17c55ea3
13 changed files with 31 additions and 50 deletions
|
@ -1500,7 +1500,8 @@ oop java_lang_Class::primitive_mirror(BasicType t) {
|
||||||
macro(_classData_offset, k, "classData", object_signature, false); \
|
macro(_classData_offset, k, "classData", object_signature, false); \
|
||||||
macro(_reflectionData_offset, k, "reflectionData", java_lang_ref_SoftReference_signature, false); \
|
macro(_reflectionData_offset, k, "reflectionData", java_lang_ref_SoftReference_signature, false); \
|
||||||
macro(_signers_offset, k, "signers", object_array_signature, false); \
|
macro(_signers_offset, k, "signers", object_array_signature, false); \
|
||||||
macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false);
|
macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \
|
||||||
|
macro(_protection_domain_offset, k, "protectionDomain", java_security_ProtectionDomain_signature, false);
|
||||||
|
|
||||||
void java_lang_Class::compute_offsets() {
|
void java_lang_Class::compute_offsets() {
|
||||||
if (_offsets_computed) {
|
if (_offsets_computed) {
|
||||||
|
|
|
@ -228,7 +228,6 @@ class java_lang_String : AllStatic {
|
||||||
macro(java_lang_Class, array_klass, intptr_signature, false) \
|
macro(java_lang_Class, array_klass, intptr_signature, false) \
|
||||||
macro(java_lang_Class, oop_size, int_signature, false) \
|
macro(java_lang_Class, oop_size, int_signature, false) \
|
||||||
macro(java_lang_Class, static_oop_field_count, int_signature, false) \
|
macro(java_lang_Class, static_oop_field_count, int_signature, false) \
|
||||||
macro(java_lang_Class, protection_domain, object_signature, false) \
|
|
||||||
macro(java_lang_Class, source_file, object_signature, false) \
|
macro(java_lang_Class, source_file, object_signature, false) \
|
||||||
macro(java_lang_Class, init_lock, object_signature, false)
|
macro(java_lang_Class, init_lock, object_signature, false)
|
||||||
|
|
||||||
|
|
|
@ -306,6 +306,7 @@ class SerializeClosure;
|
||||||
template(jdk_internal_vm_annotation_JvmtiMountTransition_signature, "Ljdk/internal/vm/annotation/JvmtiMountTransition;") \
|
template(jdk_internal_vm_annotation_JvmtiMountTransition_signature, "Ljdk/internal/vm/annotation/JvmtiMountTransition;") \
|
||||||
\
|
\
|
||||||
template(java_lang_ref_SoftReference_signature, "Ljava/lang/ref/SoftReference;") \
|
template(java_lang_ref_SoftReference_signature, "Ljava/lang/ref/SoftReference;") \
|
||||||
|
template(java_security_ProtectionDomain_signature, "Ljava/security/ProtectionDomain;") \
|
||||||
\
|
\
|
||||||
/* Support for JSR 292 & invokedynamic (JDK 1.7 and above) */ \
|
/* Support for JSR 292 & invokedynamic (JDK 1.7 and above) */ \
|
||||||
template(java_lang_invoke_CallSite, "java/lang/invoke/CallSite") \
|
template(java_lang_invoke_CallSite, "java/lang/invoke/CallSite") \
|
||||||
|
|
|
@ -1211,22 +1211,6 @@ JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
|
||||||
JVM_END
|
JVM_END
|
||||||
|
|
||||||
|
|
||||||
JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
|
|
||||||
oop mirror = JNIHandles::resolve_non_null(cls);
|
|
||||||
if (mirror == nullptr) {
|
|
||||||
THROW_(vmSymbols::java_lang_NullPointerException(), nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (java_lang_Class::is_primitive(mirror)) {
|
|
||||||
// Primitive types does not have a protection domain.
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
oop pd = java_lang_Class::protection_domain(mirror);
|
|
||||||
return (jobject) JNIHandles::make_local(THREAD, pd);
|
|
||||||
JVM_END
|
|
||||||
|
|
||||||
|
|
||||||
class ScopedValueBindingsResolver {
|
class ScopedValueBindingsResolver {
|
||||||
public:
|
public:
|
||||||
InstanceKlass* Carrier_klass;
|
InstanceKlass* Carrier_klass;
|
||||||
|
|
|
@ -236,12 +236,13 @@ public final class Class<T> implements java.io.Serializable,
|
||||||
* This constructor is not used and prevents the default constructor being
|
* This constructor is not used and prevents the default constructor being
|
||||||
* generated.
|
* generated.
|
||||||
*/
|
*/
|
||||||
private Class(ClassLoader loader, Class<?> arrayComponentType, int mods) {
|
private Class(ClassLoader loader, Class<?> arrayComponentType, int mods, ProtectionDomain pd) {
|
||||||
// Initialize final field for classLoader. The initialization value of non-null
|
// Initialize final field for classLoader. The initialization value of non-null
|
||||||
// prevents future JIT optimizations from assuming this final field is null.
|
// prevents future JIT optimizations from assuming this final field is null.
|
||||||
classLoader = loader;
|
classLoader = loader;
|
||||||
componentType = arrayComponentType;
|
componentType = arrayComponentType;
|
||||||
modifiers = mods;
|
modifiers = mods;
|
||||||
|
protectionDomain = pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2697,17 +2698,7 @@ public final class Class<T> implements java.io.Serializable,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private transient final ProtectionDomain protectionDomain;
|
||||||
* Returns the {@code ProtectionDomain} of this class.
|
|
||||||
*
|
|
||||||
* @return the ProtectionDomain of this class
|
|
||||||
*
|
|
||||||
* @see java.security.ProtectionDomain
|
|
||||||
* @since 1.2
|
|
||||||
*/
|
|
||||||
public ProtectionDomain getProtectionDomain() {
|
|
||||||
return protectionDomain();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Holder for the protection domain returned when the internal domain is null */
|
/** Holder for the protection domain returned when the internal domain is null */
|
||||||
private static class Holder {
|
private static class Holder {
|
||||||
|
@ -2719,21 +2710,22 @@ public final class Class<T> implements java.io.Serializable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// package-private
|
/**
|
||||||
ProtectionDomain protectionDomain() {
|
* Returns the {@code ProtectionDomain} of this class.
|
||||||
ProtectionDomain pd = getProtectionDomain0();
|
*
|
||||||
if (pd == null) {
|
* @return the ProtectionDomain of this class
|
||||||
|
*
|
||||||
|
* @see java.security.ProtectionDomain
|
||||||
|
* @since 1.2
|
||||||
|
*/
|
||||||
|
public ProtectionDomain getProtectionDomain() {
|
||||||
|
if (protectionDomain == null) {
|
||||||
return Holder.allPermDomain;
|
return Holder.allPermDomain;
|
||||||
} else {
|
} else {
|
||||||
return pd;
|
return protectionDomain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ProtectionDomain of this class.
|
|
||||||
*/
|
|
||||||
private native ProtectionDomain getProtectionDomain0();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the Class object for the named primitive type. Type parameter T
|
* Returns the Class object for the named primitive type. Type parameter T
|
||||||
* avoids redundant casts for trusted code.
|
* avoids redundant casts for trusted code.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1994, 2024, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1994, 2025, 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
|
||||||
|
@ -2148,7 +2148,7 @@ public final class System {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtectionDomain protectionDomain(Class<?> c) {
|
public ProtectionDomain protectionDomain(Class<?> c) {
|
||||||
return c.protectionDomain();
|
return c.getProtectionDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodHandle stringConcatHelper(String name, MethodType methodType) {
|
public MethodHandle stringConcatHelper(String name, MethodType methodType) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class Reflection {
|
||||||
fieldFilterMap = Map.of(
|
fieldFilterMap = Map.of(
|
||||||
Reflection.class, ALL_MEMBERS,
|
Reflection.class, ALL_MEMBERS,
|
||||||
AccessibleObject.class, ALL_MEMBERS,
|
AccessibleObject.class, ALL_MEMBERS,
|
||||||
Class.class, Set.of("classLoader", "classData", "modifiers"),
|
Class.class, Set.of("classLoader", "classData", "modifiers", "protectionDomain"),
|
||||||
ClassLoader.class, ALL_MEMBERS,
|
ClassLoader.class, ALL_MEMBERS,
|
||||||
Constructor.class, ALL_MEMBERS,
|
Constructor.class, ALL_MEMBERS,
|
||||||
Field.class, ALL_MEMBERS,
|
Field.class, ALL_MEMBERS,
|
||||||
|
|
|
@ -49,7 +49,6 @@ extern jboolean VerifyFixClassname(char *utf_name);
|
||||||
#define FLD "Ljava/lang/reflect/Field;"
|
#define FLD "Ljava/lang/reflect/Field;"
|
||||||
#define MHD "Ljava/lang/reflect/Method;"
|
#define MHD "Ljava/lang/reflect/Method;"
|
||||||
#define CTR "Ljava/lang/reflect/Constructor;"
|
#define CTR "Ljava/lang/reflect/Constructor;"
|
||||||
#define PD "Ljava/security/ProtectionDomain;"
|
|
||||||
#define BA "[B"
|
#define BA "[B"
|
||||||
#define RC "Ljava/lang/reflect/RecordComponent;"
|
#define RC "Ljava/lang/reflect/RecordComponent;"
|
||||||
|
|
||||||
|
@ -64,7 +63,6 @@ static JNINativeMethod methods[] = {
|
||||||
{"getDeclaredFields0","(Z)[" FLD, (void *)&JVM_GetClassDeclaredFields},
|
{"getDeclaredFields0","(Z)[" FLD, (void *)&JVM_GetClassDeclaredFields},
|
||||||
{"getDeclaredMethods0","(Z)[" MHD, (void *)&JVM_GetClassDeclaredMethods},
|
{"getDeclaredMethods0","(Z)[" MHD, (void *)&JVM_GetClassDeclaredMethods},
|
||||||
{"getDeclaredConstructors0","(Z)[" CTR, (void *)&JVM_GetClassDeclaredConstructors},
|
{"getDeclaredConstructors0","(Z)[" CTR, (void *)&JVM_GetClassDeclaredConstructors},
|
||||||
{"getProtectionDomain0", "()" PD, (void *)&JVM_GetProtectionDomain},
|
|
||||||
{"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses},
|
{"getDeclaredClasses0", "()[" CLS, (void *)&JVM_GetDeclaredClasses},
|
||||||
{"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass},
|
{"getDeclaringClass0", "()" CLS, (void *)&JVM_GetDeclaringClass},
|
||||||
{"getSimpleBinaryName0", "()" STR, (void *)&JVM_GetSimpleBinaryName},
|
{"getSimpleBinaryName0", "()" STR, (void *)&JVM_GetSimpleBinaryName},
|
||||||
|
|
|
@ -57,7 +57,7 @@ TEST_VM(InstanceKlass, class_loader_printer) {
|
||||||
// See if mirror injected fields are printed.
|
// See if mirror injected fields are printed.
|
||||||
oop mirror = vmClasses::ClassLoader_klass()->java_mirror();
|
oop mirror = vmClasses::ClassLoader_klass()->java_mirror();
|
||||||
mirror->print_on(&st);
|
mirror->print_on(&st);
|
||||||
ASSERT_THAT(st.base(), HasSubstr("injected 'protection_domain'")) << "Must contain injected fields";
|
ASSERT_THAT(st.base(), HasSubstr("injected 'array_klass'")) << "Must contain injected fields";
|
||||||
// We should test other printing functions too.
|
// We should test other printing functions too.
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
st.reset();
|
st.reset();
|
||||||
|
|
|
@ -929,7 +929,10 @@ public class TestResolvedJavaType extends TypeUniverse {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class))) {
|
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class))) {
|
||||||
return f.getName().equals("classLoader") || f.getName().equals("classData") || f.getName().equals("modifiers");
|
return f.getName().equals("classLoader") ||
|
||||||
|
f.getName().equals("classData") ||
|
||||||
|
f.getName().equals("modifiers") ||
|
||||||
|
f.getName().equals("protectionDomain");
|
||||||
}
|
}
|
||||||
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Lookup.class))) {
|
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Lookup.class))) {
|
||||||
return f.getName().equals("allowedModes") || f.getName().equals("lookupClass");
|
return f.getName().equals("allowedModes") || f.getName().equals("lookupClass");
|
||||||
|
|
|
@ -36,6 +36,7 @@ import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InaccessibleObjectException;
|
import java.lang.reflect.InaccessibleObjectException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
import jdk.internal.misc.Unsafe;
|
import jdk.internal.misc.Unsafe;
|
||||||
|
|
||||||
|
@ -147,7 +148,7 @@ public class ModuleSetAccessibleTest {
|
||||||
|
|
||||||
// non-public constructor
|
// non-public constructor
|
||||||
Constructor<?> ctor
|
Constructor<?> ctor
|
||||||
= Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, int.class);
|
= Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, int.class, ProtectionDomain.class);
|
||||||
AccessibleObject[] ctors = { ctor };
|
AccessibleObject[] ctors = { ctor };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.lang.reflect.Method;
|
||||||
import jdk.internal.misc.Unsafe;
|
import jdk.internal.misc.Unsafe;
|
||||||
import jdk.internal.module.ModulePath;
|
import jdk.internal.module.ModulePath;
|
||||||
import jdk.internal.perf.Perf;
|
import jdk.internal.perf.Perf;
|
||||||
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import static org.testng.Assert.*;
|
import static org.testng.Assert.*;
|
||||||
|
@ -193,7 +194,7 @@ public class TrySetAccessibleTest {
|
||||||
|
|
||||||
// non-public constructor
|
// non-public constructor
|
||||||
Constructor<?> ctor
|
Constructor<?> ctor
|
||||||
= Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, int.class);
|
= Class.class.getDeclaredConstructor(ClassLoader.class, Class.class, int.class, ProtectionDomain.class);
|
||||||
AccessibleObject[] ctors = { ctor };
|
AccessibleObject[] ctors = { ctor };
|
||||||
|
|
||||||
assertFalse(ctor.trySetAccessible());
|
assertFalse(ctor.trySetAccessible());
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8210496 8346567
|
* @bug 8210496 8349145 8346567
|
||||||
* @modules java.base/jdk.internal.reflect
|
* @modules java.base/jdk.internal.reflect
|
||||||
* @run testng Filtering
|
* @run testng Filtering
|
||||||
* @summary Test that security sensitive fields that filtered by core reflection
|
* @summary Test that security sensitive fields that filtered by core reflection
|
||||||
|
@ -56,6 +56,7 @@ public class Filtering {
|
||||||
{ Class.class, "classLoader" },
|
{ Class.class, "classLoader" },
|
||||||
{ Class.class, "classData" },
|
{ Class.class, "classData" },
|
||||||
{ Class.class, "modifiers" },
|
{ Class.class, "modifiers" },
|
||||||
|
{ Class.class, "protectionDomain" },
|
||||||
{ ClassLoader.class, "parent" },
|
{ ClassLoader.class, "parent" },
|
||||||
{ Field.class, "clazz" },
|
{ Field.class, "clazz" },
|
||||||
{ Field.class, "modifiers" },
|
{ Field.class, "modifiers" },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue