mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8237766: Enhance signature API to include ResolvingSignatureStream
New ResolvingSignatureStream class provides the capability to easily walk through the differing parts of a signature while resolving or querying its underlying types. Co-authored-by: John Rose <john.r.rose@oracle.com> Reviewed-by: coleenp, fparain, hseigel
This commit is contained in:
parent
e455d382e7
commit
c280d98e80
5 changed files with 146 additions and 116 deletions
|
@ -52,7 +52,11 @@
|
|||
#include "runtime/thread.inline.hpp"
|
||||
#include "runtime/vframe.inline.hpp"
|
||||
|
||||
static void trace_class_resolution(const Klass* to_class) {
|
||||
static void trace_class_resolution(oop mirror) {
|
||||
if (mirror == NULL || java_lang_Class::is_primitive(mirror)) {
|
||||
return;
|
||||
}
|
||||
Klass* to_class = java_lang_Class::as_Klass(mirror);
|
||||
ResourceMark rm;
|
||||
int line_number = -1;
|
||||
const char * source_file = NULL;
|
||||
|
@ -750,33 +754,6 @@ void Reflection::check_for_inner_class(const InstanceKlass* outer, const Instanc
|
|||
);
|
||||
}
|
||||
|
||||
// Utility method converting a single SignatureStream element into java.lang.Class instance
|
||||
static oop get_mirror_from_signature(const methodHandle& method,
|
||||
SignatureStream* ss,
|
||||
TRAPS) {
|
||||
|
||||
|
||||
if (is_reference_type(ss->type())) {
|
||||
Symbol* name = ss->as_symbol();
|
||||
oop loader = method->method_holder()->class_loader();
|
||||
oop protection_domain = method->method_holder()->protection_domain();
|
||||
const Klass* k = SystemDictionary::resolve_or_fail(name,
|
||||
Handle(THREAD, loader),
|
||||
Handle(THREAD, protection_domain),
|
||||
true,
|
||||
CHECK_NULL);
|
||||
if (log_is_enabled(Debug, class, resolve)) {
|
||||
trace_class_resolution(k);
|
||||
}
|
||||
return k->java_mirror();
|
||||
}
|
||||
|
||||
assert(ss->type() != T_VOID || ss->at_return_type(),
|
||||
"T_VOID should only appear as return type");
|
||||
|
||||
return java_lang_Class::primitive_mirror(ss->type());
|
||||
}
|
||||
|
||||
static objArrayHandle get_parameter_types(const methodHandle& method,
|
||||
int parameter_count,
|
||||
oop* return_type,
|
||||
|
@ -787,19 +764,20 @@ static objArrayHandle get_parameter_types(const methodHandle& method,
|
|||
int index = 0;
|
||||
// Collect parameter types
|
||||
ResourceMark rm(THREAD);
|
||||
Symbol* signature = method->signature();
|
||||
SignatureStream ss(signature);
|
||||
while (!ss.at_return_type()) {
|
||||
oop mirror = get_mirror_from_signature(method, &ss, CHECK_(objArrayHandle()));
|
||||
mirrors->obj_at_put(index++, mirror);
|
||||
ss.next();
|
||||
for (ResolvingSignatureStream ss(method()); !ss.is_done(); ss.next()) {
|
||||
oop mirror = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_(objArrayHandle()));
|
||||
if (log_is_enabled(Debug, class, resolve)) {
|
||||
trace_class_resolution(mirror);
|
||||
}
|
||||
if (!ss.at_return_type()) {
|
||||
mirrors->obj_at_put(index++, mirror);
|
||||
} else if (return_type != NULL) {
|
||||
// Collect return type as well
|
||||
assert(ss.at_return_type(), "return type should be present");
|
||||
*return_type = mirror;
|
||||
}
|
||||
}
|
||||
assert(index == parameter_count, "invalid parameter count");
|
||||
if (return_type != NULL) {
|
||||
// Collect return type as well
|
||||
assert(ss.at_return_type(), "return type should be present");
|
||||
*return_type = get_mirror_from_signature(method, &ss, CHECK_(objArrayHandle()));
|
||||
}
|
||||
return mirrors;
|
||||
}
|
||||
|
||||
|
@ -808,24 +786,11 @@ static objArrayHandle get_exception_types(const methodHandle& method, TRAPS) {
|
|||
}
|
||||
|
||||
static Handle new_type(Symbol* signature, Klass* k, TRAPS) {
|
||||
SignatureStream ss(signature, false);
|
||||
// Basic types
|
||||
BasicType type = ss.is_reference() ? T_OBJECT : ss.type();
|
||||
if (type != T_OBJECT) {
|
||||
return Handle(THREAD, Universe::java_mirror(type));
|
||||
}
|
||||
|
||||
Klass* result =
|
||||
SystemDictionary::resolve_or_fail(signature,
|
||||
Handle(THREAD, k->class_loader()),
|
||||
Handle(THREAD, k->protection_domain()),
|
||||
true, CHECK_(Handle()));
|
||||
|
||||
ResolvingSignatureStream ss(signature, k, false);
|
||||
oop nt = ss.as_java_mirror(SignatureStream::NCDFError, CHECK_NH);
|
||||
if (log_is_enabled(Debug, class, resolve)) {
|
||||
trace_class_resolution(result);
|
||||
trace_class_resolution(nt);
|
||||
}
|
||||
|
||||
oop nt = result->java_mirror();
|
||||
return Handle(THREAD, nt);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue