src/share/vm/prims/unsafe.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
bug_8058575.hs.3 Cdiff src/share/vm/prims/unsafe.cpp
src/share/vm/prims/unsafe.cpp
Print this page
*** 777,796 ****
} UNSAFE_END
// define a class but do not make it known to the class loader or system dictionary
// - host_class: supplies context for linkage, access control, protection domain, and class loader
// - data: bytes of a class file, a raw memory address (length gives the number of bytes)
// - cp_patches: where non-null entries exist, they replace corresponding CP entries in data
// When you load an anonymous class U, it works as if you changed its name just before loading,
// to a name that you will never use again. Since the name is lost, no other class can directly
// link to any member of U. Just after U is loaded, the only way to use it is reflectively,
// through java.lang.Class methods like Class.newInstance.
// Access checks for linkage sites within U continue to follow the same rules as for named classes.
- // The package of an anonymous class is given by the package qualifier on the name under which it was loaded.
// An anonymous class also has special privileges to access any member of its host class.
// This is the main reason why this loading operation is unsafe. The purpose of this is to
// allow language implementations to simulate "open classes"; a host class in effect gets
// new code when an anonymous class is loaded alongside it. A less convenient but more
// standard way to do this is with reflection, which can also be set to ignore access
--- 777,801 ----
} UNSAFE_END
// define a class but do not make it known to the class loader or system dictionary
// - host_class: supplies context for linkage, access control, protection domain, and class loader
+ // if host_class is itself anonymous then it is replaced with its host class.
// - data: bytes of a class file, a raw memory address (length gives the number of bytes)
// - cp_patches: where non-null entries exist, they replace corresponding CP entries in data
// When you load an anonymous class U, it works as if you changed its name just before loading,
// to a name that you will never use again. Since the name is lost, no other class can directly
// link to any member of U. Just after U is loaded, the only way to use it is reflectively,
// through java.lang.Class methods like Class.newInstance.
+ // The package of an anonymous class must either match its host's class's package or be in the
+ // unnamed package. If it is in the unnamed package then it will be put in its host class's
+ // package.
+ //
+
// Access checks for linkage sites within U continue to follow the same rules as for named classes.
// An anonymous class also has special privileges to access any member of its host class.
// This is the main reason why this loading operation is unsafe. The purpose of this is to
// allow language implementations to simulate "open classes"; a host class in effect gets
// new code when an anonymous class is loaded alongside it. A less convenient but more
// standard way to do this is with reflection, which can also be set to ignore access
*** 868,880 ****
host_klass = InstanceKlass::cast(host_klass)->host_klass();
}
// Primitive types have NULL Klass* fields in their java.lang.Class instances.
if (host_klass == NULL) {
! THROW_0(vmSymbols::java_lang_IllegalArgumentException());
}
const char* host_source = host_klass->external_name();
Handle host_loader(THREAD, host_klass->class_loader());
Handle host_domain(THREAD, host_klass->protection_domain());
GrowableArray<Handle>* cp_patches = NULL;
--- 873,887 ----
host_klass = InstanceKlass::cast(host_klass)->host_klass();
}
// Primitive types have NULL Klass* fields in their java.lang.Class instances.
if (host_klass == NULL) {
! THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Host class is null");
}
+ assert(host_klass->is_instance_klass(), "Host class must be an instance class");
+
const char* host_source = host_klass->external_name();
Handle host_loader(THREAD, host_klass->class_loader());
Handle host_domain(THREAD, host_klass->protection_domain());
GrowableArray<Handle>* cp_patches = NULL;
*** 901,911 ****
Symbol* no_class_name = NULL;
Klass* anonk = SystemDictionary::parse_stream(no_class_name,
host_loader,
host_domain,
&st,
! host_klass,
cp_patches,
CHECK_NULL);
if (anonk == NULL) {
return NULL;
}
--- 908,918 ----
Symbol* no_class_name = NULL;
Klass* anonk = SystemDictionary::parse_stream(no_class_name,
host_loader,
host_domain,
&st,
! InstanceKlass::cast(host_klass),
cp_patches,
CHECK_NULL);
if (anonk == NULL) {
return NULL;
}
src/share/vm/prims/unsafe.cpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File