replace native_hash_table argument-passing with vm
This commit is contained in:
parent
8f49f69e7e
commit
9982538c89
@ -453,8 +453,7 @@ static struct Code_attribute * resolve_code_attribute(struct class_entry * class
|
|||||||
return attribute->code;
|
return attribute->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resolve_method_entry(int native_hash_table_length,
|
static void resolve_method_entry(struct vm * vm,
|
||||||
struct hash_table_entry * native_hash_table,
|
|
||||||
struct class_entry * class_entry,
|
struct class_entry * class_entry,
|
||||||
struct constant * method_name_constant,
|
struct constant * method_name_constant,
|
||||||
struct constant * method_descriptor_constant,
|
struct constant * method_descriptor_constant,
|
||||||
@ -485,8 +484,8 @@ static void resolve_method_entry(int native_hash_table_length,
|
|||||||
struct constant * method_descriptor_constant = &class_file->constant_pool[method_info->descriptor_index - 1];
|
struct constant * method_descriptor_constant = &class_file->constant_pool[method_info->descriptor_index - 1];
|
||||||
assert(method_descriptor_constant->tag == CONSTANT_Utf8);
|
assert(method_descriptor_constant->tag == CONSTANT_Utf8);
|
||||||
|
|
||||||
method_entry->native_func = native_method_lookup(native_hash_table_length,
|
method_entry->native_func = native_method_lookup(vm->native_hash_table.length,
|
||||||
native_hash_table,
|
vm->native_hash_table.entry,
|
||||||
class_name_constant,
|
class_name_constant,
|
||||||
method_name_constant,
|
method_name_constant,
|
||||||
method_descriptor_constant);
|
method_descriptor_constant);
|
||||||
@ -500,10 +499,7 @@ static void resolve_method_entry(int native_hash_table_length,
|
|||||||
debugc('\n');
|
debugc('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resolve_method_entry_from_superclasses(int class_hash_table_length,
|
static void resolve_method_entry_from_superclasses(struct vm * vm,
|
||||||
struct hash_table_entry * class_hash_table,
|
|
||||||
int native_hash_table_length,
|
|
||||||
struct hash_table_entry * native_hash_table,
|
|
||||||
struct class_entry * class_entry,
|
struct class_entry * class_entry,
|
||||||
struct constant * method_name_constant,
|
struct constant * method_name_constant,
|
||||||
struct constant * method_descriptor_constant,
|
struct constant * method_descriptor_constant,
|
||||||
@ -514,8 +510,7 @@ static void resolve_method_entry_from_superclasses(int class_hash_table_length,
|
|||||||
method_entry->method_info = nullptr;
|
method_entry->method_info = nullptr;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
resolve_method_entry(native_hash_table_length,
|
resolve_method_entry(vm,
|
||||||
native_hash_table,
|
|
||||||
class_entry,
|
class_entry,
|
||||||
method_name_constant,
|
method_name_constant,
|
||||||
method_descriptor_constant,
|
method_descriptor_constant,
|
||||||
@ -532,22 +527,20 @@ static void resolve_method_entry_from_superclasses(int class_hash_table_length,
|
|||||||
assert(class_name_constant->tag == CONSTANT_Utf8);
|
assert(class_name_constant->tag == CONSTANT_Utf8);
|
||||||
|
|
||||||
// lookup the method from the superclass
|
// lookup the method from the superclass
|
||||||
class_entry = class_resolver_lookup_class_from_class_index(class_hash_table_length,
|
class_entry = class_resolver_lookup_class_from_class_index(vm->class_hash_table.length,
|
||||||
class_hash_table,
|
vm->class_hash_table.entry,
|
||||||
class_entry,
|
class_entry,
|
||||||
class_entry->class_file->super_class);
|
class_entry->class_file->super_class);
|
||||||
assert(class_entry != nullptr);
|
assert(class_entry != nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct method_entry class_resolver_lookup_method_from_objectref_class(int class_hash_table_length,
|
struct method_entry class_resolver_lookup_method_from_objectref_class(struct vm * vm,
|
||||||
struct hash_table_entry * class_hash_table,
|
|
||||||
int native_hash_table_length,
|
|
||||||
struct hash_table_entry * native_hash_table,
|
|
||||||
int32_t methodref_index,
|
int32_t methodref_index,
|
||||||
struct class_entry * objectref_class_entry,
|
struct class_entry * objectref_class_entry)
|
||||||
struct class_entry * origin_class_entry)
|
|
||||||
{
|
{
|
||||||
|
struct class_entry * origin_class_entry = vm->current_frame->class_entry;
|
||||||
|
|
||||||
struct constant * methodref_constant = &origin_class_entry->class_file->constant_pool[methodref_index - 1];
|
struct constant * methodref_constant = &origin_class_entry->class_file->constant_pool[methodref_index - 1];
|
||||||
assert(methodref_constant->tag == CONSTANT_InterfaceMethodref || methodref_constant->tag == CONSTANT_Methodref);
|
assert(methodref_constant->tag == CONSTANT_InterfaceMethodref || methodref_constant->tag == CONSTANT_Methodref);
|
||||||
struct constant * nameandtype_constant = &origin_class_entry->class_file->constant_pool[methodref_constant->methodref.name_and_type_index - 1];
|
struct constant * nameandtype_constant = &origin_class_entry->class_file->constant_pool[methodref_constant->methodref.name_and_type_index - 1];
|
||||||
@ -561,10 +554,7 @@ struct method_entry class_resolver_lookup_method_from_objectref_class(int class_
|
|||||||
|
|
||||||
struct method_entry method_entry;
|
struct method_entry method_entry;
|
||||||
|
|
||||||
resolve_method_entry_from_superclasses(class_hash_table_length,
|
resolve_method_entry_from_superclasses(vm,
|
||||||
class_hash_table,
|
|
||||||
native_hash_table_length,
|
|
||||||
native_hash_table,
|
|
||||||
class_entry,
|
class_entry,
|
||||||
method_name_constant,
|
method_name_constant,
|
||||||
method_descriptor_constant,
|
method_descriptor_constant,
|
||||||
@ -573,13 +563,10 @@ struct method_entry class_resolver_lookup_method_from_objectref_class(int class_
|
|||||||
return method_entry;
|
return method_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct method_entry * class_resolver_lookup_method_from_origin_class(int class_hash_table_length,
|
struct method_entry * class_resolver_lookup_method_from_origin_class(struct vm * vm,
|
||||||
struct hash_table_entry * class_hash_table,
|
int32_t methodref_index)
|
||||||
int native_hash_table_length,
|
|
||||||
struct hash_table_entry * native_hash_table,
|
|
||||||
int32_t methodref_index,
|
|
||||||
struct class_entry * origin_class_entry)
|
|
||||||
{
|
{
|
||||||
|
struct class_entry * origin_class_entry = vm->current_frame->class_entry;
|
||||||
if (origin_class_entry->attribute_entry[methodref_index - 1].method_entry != nullptr) {
|
if (origin_class_entry->attribute_entry[methodref_index - 1].method_entry != nullptr) {
|
||||||
debugf("class_resolver_lookup_method_from_origin_class %d: [cached]\n", methodref_index);
|
debugf("class_resolver_lookup_method_from_origin_class %d: [cached]\n", methodref_index);
|
||||||
return origin_class_entry->attribute_entry[methodref_index - 1].method_entry;
|
return origin_class_entry->attribute_entry[methodref_index - 1].method_entry;
|
||||||
@ -594,17 +581,14 @@ struct method_entry * class_resolver_lookup_method_from_origin_class(int class_h
|
|||||||
struct constant * method_descriptor_constant = &origin_class_entry->class_file->constant_pool[nameandtype_constant->nameandtype.descriptor_index - 1];
|
struct constant * method_descriptor_constant = &origin_class_entry->class_file->constant_pool[nameandtype_constant->nameandtype.descriptor_index - 1];
|
||||||
assert(method_descriptor_constant->tag == CONSTANT_Utf8);
|
assert(method_descriptor_constant->tag == CONSTANT_Utf8);
|
||||||
|
|
||||||
struct class_entry * class_entry = class_resolver_lookup_class_from_class_index(class_hash_table_length,
|
struct class_entry * class_entry = class_resolver_lookup_class_from_class_index(vm->class_hash_table.length,
|
||||||
class_hash_table,
|
vm->class_hash_table.entry,
|
||||||
origin_class_entry,
|
origin_class_entry,
|
||||||
methodref_constant->methodref.class_index);
|
methodref_constant->methodref.class_index);
|
||||||
|
|
||||||
struct method_entry * method_entry = malloc_class_arena((sizeof (struct method_entry)));
|
struct method_entry * method_entry = malloc_class_arena((sizeof (struct method_entry)));
|
||||||
|
|
||||||
resolve_method_entry_from_superclasses(class_hash_table_length,
|
resolve_method_entry_from_superclasses(vm,
|
||||||
class_hash_table,
|
|
||||||
native_hash_table_length,
|
|
||||||
native_hash_table,
|
|
||||||
class_entry,
|
class_entry,
|
||||||
method_name_constant,
|
method_name_constant,
|
||||||
method_descriptor_constant,
|
method_descriptor_constant,
|
||||||
|
@ -19,19 +19,11 @@ struct class_entry * class_resolver_lookup_class_from_class_index(int class_hash
|
|||||||
struct class_entry * class_entry,
|
struct class_entry * class_entry,
|
||||||
int32_t class_index);
|
int32_t class_index);
|
||||||
|
|
||||||
struct method_entry class_resolver_lookup_method_from_objectref_class(int class_hash_table_length,
|
struct method_entry class_resolver_lookup_method_from_objectref_class(struct vm * vm,
|
||||||
struct hash_table_entry * class_hash_table,
|
|
||||||
int native_hash_table_length,
|
|
||||||
struct hash_table_entry * native_hash_table,
|
|
||||||
int32_t methodref_index,
|
int32_t methodref_index,
|
||||||
struct class_entry * objectref_class_entry,
|
struct class_entry * objectref_class_entry);
|
||||||
struct class_entry * origin_class_entry);
|
struct method_entry * class_resolver_lookup_method_from_origin_class(struct vm * vm,
|
||||||
struct method_entry * class_resolver_lookup_method_from_origin_class(int class_hash_table_length,
|
int32_t methodref_index);
|
||||||
struct hash_table_entry * class_hash_table,
|
|
||||||
int native_hash_table_length,
|
|
||||||
struct hash_table_entry * native_hash_table,
|
|
||||||
int32_t methodref_index,
|
|
||||||
struct class_entry * origin_class_entry);
|
|
||||||
|
|
||||||
struct method_entry class_resolver_lookup_method_from_method_name_method_descriptor(struct class_entry * class_entry,
|
struct method_entry class_resolver_lookup_method_from_method_name_method_descriptor(struct class_entry * class_entry,
|
||||||
const uint8_t * method_name,
|
const uint8_t * method_name,
|
||||||
|
30
c/execute.c
30
c/execute.c
@ -1210,13 +1210,9 @@ void op_invokeinterface(struct vm * vm, uint32_t index, uint32_t count)
|
|||||||
return vm_exception(vm, vm_instance_create(vm, "java/lang/NullPointerException"));
|
return vm_exception(vm, vm_instance_create(vm, "java/lang/NullPointerException"));
|
||||||
|
|
||||||
struct method_entry method_entry =
|
struct method_entry method_entry =
|
||||||
class_resolver_lookup_method_from_objectref_class(vm->class_hash_table.length,
|
class_resolver_lookup_method_from_objectref_class(vm,
|
||||||
vm->class_hash_table.entry,
|
|
||||||
vm->native_hash_table.length,
|
|
||||||
vm->native_hash_table.entry,
|
|
||||||
index,
|
index,
|
||||||
objectref->class_entry,
|
objectref->class_entry);
|
||||||
vm->current_frame->class_entry);
|
|
||||||
|
|
||||||
vm_special_method_call(vm, method_entry.class_entry, &method_entry);
|
vm_special_method_call(vm, method_entry.class_entry, &method_entry);
|
||||||
}
|
}
|
||||||
@ -1241,12 +1237,7 @@ void op_invokespecial(struct vm * vm, uint32_t index)
|
|||||||
return vm_exception(vm, vm_instance_create(vm, "java/lang/NullPointerException"));
|
return vm_exception(vm, vm_instance_create(vm, "java/lang/NullPointerException"));
|
||||||
|
|
||||||
struct method_entry * method_entry =
|
struct method_entry * method_entry =
|
||||||
class_resolver_lookup_method_from_origin_class(vm->class_hash_table.length,
|
class_resolver_lookup_method_from_origin_class(vm, index);
|
||||||
vm->class_hash_table.entry,
|
|
||||||
vm->native_hash_table.length,
|
|
||||||
vm->native_hash_table.entry,
|
|
||||||
index,
|
|
||||||
vm->current_frame->class_entry);
|
|
||||||
|
|
||||||
vm_special_method_call(vm, method_entry->class_entry, method_entry);
|
vm_special_method_call(vm, method_entry->class_entry, method_entry);
|
||||||
}
|
}
|
||||||
@ -1254,12 +1245,7 @@ void op_invokespecial(struct vm * vm, uint32_t index)
|
|||||||
void op_invokestatic(struct vm * vm, uint32_t index)
|
void op_invokestatic(struct vm * vm, uint32_t index)
|
||||||
{
|
{
|
||||||
struct method_entry * method_entry =
|
struct method_entry * method_entry =
|
||||||
class_resolver_lookup_method_from_origin_class(vm->class_hash_table.length,
|
class_resolver_lookup_method_from_origin_class(vm, index);
|
||||||
vm->class_hash_table.entry,
|
|
||||||
vm->native_hash_table.length,
|
|
||||||
vm->native_hash_table.entry,
|
|
||||||
index,
|
|
||||||
vm->current_frame->class_entry);
|
|
||||||
|
|
||||||
/* On successful resolution of the method, the class or interface that
|
/* On successful resolution of the method, the class or interface that
|
||||||
declared the resolved method is initialized if that class or interface has
|
declared the resolved method is initialized if that class or interface has
|
||||||
@ -1288,13 +1274,9 @@ void op_invokevirtual(struct vm * vm, uint32_t index)
|
|||||||
return vm_exception(vm, vm_instance_create(vm, "java/lang/NullPointerException"));
|
return vm_exception(vm, vm_instance_create(vm, "java/lang/NullPointerException"));
|
||||||
|
|
||||||
struct method_entry method_entry =
|
struct method_entry method_entry =
|
||||||
class_resolver_lookup_method_from_objectref_class(vm->class_hash_table.length,
|
class_resolver_lookup_method_from_objectref_class(vm,
|
||||||
vm->class_hash_table.entry,
|
|
||||||
vm->native_hash_table.length,
|
|
||||||
vm->native_hash_table.entry,
|
|
||||||
index,
|
index,
|
||||||
objectref->class_entry,
|
objectref->class_entry);
|
||||||
vm->current_frame->class_entry);
|
|
||||||
|
|
||||||
vm_special_method_call(vm, method_entry.class_entry, &method_entry);
|
vm_special_method_call(vm, method_entry.class_entry, &method_entry);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user