< prev index next >

src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java

Print this page
rev 54607 : 8222895: StackOverflowError in custom security manager that relies on ClassSpecializer
Reviewed-by: TBD

*** 23,32 **** --- 23,33 ---- * questions. */ package java.lang.invoke; + import jdk.internal.access.SharedSecrets; import jdk.internal.loader.BootLoader; import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.FieldVisitor; import jdk.internal.org.objectweb.asm.MethodVisitor; import jdk.internal.vm.annotation.Stable;
*** 35,44 **** --- 36,46 ---- import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; + import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap;
*** 573,595 **** Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecializer<T,K,S>.SpeciesData speciesData) { byte[] classFile = generateConcreteSpeciesCodeFile(className, speciesData); // load class InvokerBytecodeGenerator.maybeDump(classBCName(className), classFile); ! Class<?> speciesCode; ! ! MethodHandles.Lookup lookup = IMPL_LOOKUP.in(topClass()); ! speciesCode = AccessController.doPrivileged(new PrivilegedAction<>() { @Override ! public Class<?> run() { ! try { ! return lookup.defineClass(classFile); ! } catch (Exception ex) { ! throw newInternalError(ex); ! } } }); return speciesCode.asSubclass(topClass()); } // These are named like constants because there is only one per specialization scheme: private final String SPECIES_DATA = classBCName(metaType); --- 575,597 ---- Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecializer<T,K,S>.SpeciesData speciesData) { byte[] classFile = generateConcreteSpeciesCodeFile(className, speciesData); // load class InvokerBytecodeGenerator.maybeDump(classBCName(className), classFile); ! ClassLoader cl = topClass.getClassLoader(); ! ProtectionDomain pd = null; ! if (cl != null) { ! pd = AccessController.doPrivileged( ! new PrivilegedAction<>() { @Override ! public ProtectionDomain run() { ! return topClass().getProtectionDomain(); } }); + } + Class<?> speciesCode = SharedSecrets.getJavaLangAccess() + .defineClass(cl, className, classFile, pd, "_ClassSpecializer_generateConcreteSpeciesCode"); return speciesCode.asSubclass(topClass()); } // These are named like constants because there is only one per specialization scheme: private final String SPECIES_DATA = classBCName(metaType);
< prev index next >