1236 // ASM exceptions are poorly specified
1237 ClassFormatError cfe = new ClassFormatError();
1238 cfe.initCause(e);
1239 throw cfe;
1240 }
1241
1242 // get package and class name in binary form
1243 String cn, pn;
1244 int index = name.lastIndexOf('/');
1245 if (index == -1) {
1246 cn = name;
1247 pn = "";
1248 } else {
1249 cn = name.replace('/', '.');
1250 pn = cn.substring(0, index);
1251 }
1252 if (!pn.equals(lookupClass.getPackageName())) {
1253 throw new IllegalArgumentException(cn + " not in same package as lookup class: " + lookupClass.getName());
1254 }
1255
1256 Class<?> host = lookupClass;
1257 if ((flags & NESTMATE_CLASS) != 0) {
1258 // cached in the Class object
1259 host = lookupClass.getNestHost();
1260 }
1261
1262 if ((flags & NONFINDABLE_CLASS) != 0) {
1263 // assign a new name
1264 // cn = cn + "\\" + ++seq;
1265 cn = null;
1266 }
1267
1268 // invoke the class loader's defineClass method
1269 ClassLoader loader = lookupClass.getClassLoader();
1270 ProtectionDomain pd = (loader != null) ? lookupClassProtectionDomain() : null;
1271 Class<?> clazz = JLA.defineClass(loader, host, cn, bytes, pd, flags, classData);
1272 assert clazz.getClassLoader() == lookupClass.getClassLoader()
1273 && clazz.getPackageName().equals(lookupClass.getPackageName());
1274
1275 // ## TBD what if multiple threads defining this same class??
1276 // may need VM to inject the classData in a Class itself at define class time
1277 if (classData != null) {
1278 CLASS_DATA_MAP.putIfAbsent(clazz, classData);
1279 }
1280 return clazz;
1281 }
1282
1283 private static volatile int seq = 0;
1284
1285 private ProtectionDomain lookupClassProtectionDomain() {
1286 ProtectionDomain pd = cachedProtectionDomain;
1287 if (pd == null) {
1288 cachedProtectionDomain = pd = JLA.protectionDomain(lookupClass);
1289 }
1290 return pd;
1291 }
|
1236 // ASM exceptions are poorly specified
1237 ClassFormatError cfe = new ClassFormatError();
1238 cfe.initCause(e);
1239 throw cfe;
1240 }
1241
1242 // get package and class name in binary form
1243 String cn, pn;
1244 int index = name.lastIndexOf('/');
1245 if (index == -1) {
1246 cn = name;
1247 pn = "";
1248 } else {
1249 cn = name.replace('/', '.');
1250 pn = cn.substring(0, index);
1251 }
1252 if (!pn.equals(lookupClass.getPackageName())) {
1253 throw new IllegalArgumentException(cn + " not in same package as lookup class: " + lookupClass.getName());
1254 }
1255
1256 if ((flags & NONFINDABLE_CLASS) != 0) {
1257 // assign a new name
1258 // cn = cn + "\\" + ++seq;
1259 cn = null;
1260 }
1261
1262 // invoke the class loader's defineClass method
1263 ClassLoader loader = lookupClass.getClassLoader();
1264 ProtectionDomain pd = (loader != null) ? lookupClassProtectionDomain() : null;
1265 Class<?> clazz = JLA.defineClass(loader, lookupClass, cn, bytes, pd, flags, classData);
1266 assert clazz.getClassLoader() == lookupClass.getClassLoader()
1267 && clazz.getPackageName().equals(lookupClass.getPackageName());
1268
1269 // ## TBD what if multiple threads defining this same class??
1270 // may need VM to inject the classData in a Class itself at define class time
1271 if (classData != null) {
1272 CLASS_DATA_MAP.putIfAbsent(clazz, classData);
1273 }
1274 return clazz;
1275 }
1276
1277 private static volatile int seq = 0;
1278
1279 private ProtectionDomain lookupClassProtectionDomain() {
1280 ProtectionDomain pd = cachedProtectionDomain;
1281 if (pd == null) {
1282 cachedProtectionDomain = pd = JLA.protectionDomain(lookupClass);
1283 }
1284 return pd;
1285 }
|