8010319: Implementation of JEP 181: Nest-Based Access Control

Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Maurizio Mimadamore <maurizio.mimadamore@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Vlaidmir Ivanov <vladimir.x.ivanov@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: John Rose <john.r.rose@oracle.com>
Co-authored-by: Daniel Smith <daniel.smith@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Kumar Srinivasan <kumardotsrinivasan@gmail.com>
Co-authored-by: Boris Ulasevich <boris.ulasevich@bell-sw.com>
Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley
This commit is contained in:
David Holmes 2018-06-23 01:32:41 -04:00
parent 6e0bd36f42
commit 95bf19563b
259 changed files with 21354 additions and 890 deletions

View file

@ -1892,6 +1892,98 @@ JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
}
JVM_END
JVM_ENTRY(jboolean, JVM_AreNestMates(JNIEnv *env, jclass current, jclass member))
{
JVMWrapper("JVM_AreNestMates");
Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
assert(c->is_instance_klass(), "must be");
InstanceKlass* ck = InstanceKlass::cast(c);
Klass* m = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(member));
assert(m->is_instance_klass(), "must be");
InstanceKlass* mk = InstanceKlass::cast(m);
return ck->has_nestmate_access_to(mk, THREAD);
}
JVM_END
JVM_ENTRY(jclass, JVM_GetNestHost(JNIEnv* env, jclass current))
{
// current is not a primitive or array class
JVMWrapper("JVM_GetNestHost");
Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
assert(c->is_instance_klass(), "must be");
InstanceKlass* ck = InstanceKlass::cast(c);
// Don't post exceptions if validation fails
InstanceKlass* host = ck->nest_host(NULL, THREAD);
return (jclass) (host == NULL ? NULL :
JNIHandles::make_local(THREAD, host->java_mirror()));
}
JVM_END
JVM_ENTRY(jobjectArray, JVM_GetNestMembers(JNIEnv* env, jclass current))
{
// current is not a primitive or array class
JVMWrapper("JVM_GetNestMembers");
Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
assert(c->is_instance_klass(), "must be");
InstanceKlass* ck = InstanceKlass::cast(c);
// Get the nest host for this nest - throw ICCE if validation fails
Symbol* icce = vmSymbols::java_lang_IncompatibleClassChangeError();
InstanceKlass* host = ck->nest_host(icce, CHECK_NULL);
{
JvmtiVMObjectAllocEventCollector oam;
Array<u2>* members = host->nest_members();
int length = members == NULL ? 0 : members->length();
// nest host is first in the array so make it one bigger
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(),
length + 1, CHECK_NULL);
objArrayHandle result (THREAD, r);
result->obj_at_put(0, host->java_mirror());
if (length != 0) {
int i;
for (i = 0; i < length; i++) {
int cp_index = members->at(i);
Klass* k = host->constants()->klass_at(cp_index, CHECK_NULL);
if (k->is_instance_klass()) {
InstanceKlass* nest_host_k =
InstanceKlass::cast(k)->nest_host(icce, CHECK_NULL);
if (nest_host_k == host) {
result->obj_at_put(i+1, k->java_mirror());
}
else {
// k's nest host is legal but it isn't our host so
// throw ICCE
ResourceMark rm(THREAD);
Exceptions::fthrow(THREAD_AND_LOCATION,
icce,
"Nest member %s in %s declares a different nest host of %s",
k->external_name(),
host->external_name(),
nest_host_k->external_name()
);
return NULL;
}
}
else {
// we have a bad nest member entry - throw ICCE
ResourceMark rm(THREAD);
Exceptions::fthrow(THREAD_AND_LOCATION,
icce,
"Class %s can not be a nest member of %s",
k->external_name(),
host->external_name()
);
return NULL;
}
}
}
else {
assert(host == ck, "must be singleton nest");
}
return (jobjectArray)JNIHandles::make_local(THREAD, result());
}
}
JVM_END
// Constant pool access //////////////////////////////////////////////////////////