Mercurial > hg > truffle
comparison src/cpu/zero/vm/cppInterpreter_zero.cpp @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | 1d7922586cf6 |
children | a3e2f723f2a5 |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. | 3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 * | 5 * |
6 * This code is free software; you can redistribute it and/or modify it | 6 * This code is free software; you can redistribute it and/or modify it |
7 * under the terms of the GNU General Public License version 2 only, as | 7 * under the terms of the GNU General Public License version 2 only, as |
29 #include "interpreter/cppInterpreter.hpp" | 29 #include "interpreter/cppInterpreter.hpp" |
30 #include "interpreter/interpreter.hpp" | 30 #include "interpreter/interpreter.hpp" |
31 #include "interpreter/interpreterGenerator.hpp" | 31 #include "interpreter/interpreterGenerator.hpp" |
32 #include "interpreter/interpreterRuntime.hpp" | 32 #include "interpreter/interpreterRuntime.hpp" |
33 #include "oops/arrayOop.hpp" | 33 #include "oops/arrayOop.hpp" |
34 #include "oops/methodDataOop.hpp" | 34 #include "oops/methodData.hpp" |
35 #include "oops/methodOop.hpp" | 35 #include "oops/method.hpp" |
36 #include "oops/oop.inline.hpp" | 36 #include "oops/oop.inline.hpp" |
37 #include "prims/jvmtiExport.hpp" | 37 #include "prims/jvmtiExport.hpp" |
38 #include "prims/jvmtiThreadState.hpp" | 38 #include "prims/jvmtiThreadState.hpp" |
39 #include "runtime/arguments.hpp" | 39 #include "runtime/arguments.hpp" |
40 #include "runtime/deoptimization.hpp" | 40 #include "runtime/deoptimization.hpp" |
63 | 63 |
64 #define CALL_VM_NOCHECK(func) \ | 64 #define CALL_VM_NOCHECK(func) \ |
65 CALL_VM_NOCHECK_NOFIX(func) \ | 65 CALL_VM_NOCHECK_NOFIX(func) \ |
66 fixup_after_potential_safepoint() | 66 fixup_after_potential_safepoint() |
67 | 67 |
68 int CppInterpreter::normal_entry(methodOop method, intptr_t UNUSED, TRAPS) { | 68 int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) { |
69 JavaThread *thread = (JavaThread *) THREAD; | 69 JavaThread *thread = (JavaThread *) THREAD; |
70 | 70 |
71 // Allocate and initialize our frame. | 71 // Allocate and initialize our frame. |
72 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); | 72 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); |
73 thread->push_zero_frame(frame); | 73 thread->push_zero_frame(frame); |
88 if (recurse) | 88 if (recurse) |
89 main_loop(recurse - 1, THREAD); | 89 main_loop(recurse - 1, THREAD); |
90 | 90 |
91 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); | 91 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
92 interpreterState istate = frame->interpreter_state(); | 92 interpreterState istate = frame->interpreter_state(); |
93 methodOop method = istate->method(); | 93 Method* method = istate->method(); |
94 | 94 |
95 intptr_t *result = NULL; | 95 intptr_t *result = NULL; |
96 int result_slots = 0; | 96 int result_slots = 0; |
97 | 97 |
98 while (true) { | 98 while (true) { |
112 // Clear the frame anchor | 112 // Clear the frame anchor |
113 thread->reset_last_Java_frame(); | 113 thread->reset_last_Java_frame(); |
114 | 114 |
115 // Examine the message from the interpreter to decide what to do | 115 // Examine the message from the interpreter to decide what to do |
116 if (istate->msg() == BytecodeInterpreter::call_method) { | 116 if (istate->msg() == BytecodeInterpreter::call_method) { |
117 methodOop callee = istate->callee(); | 117 Method* callee = istate->callee(); |
118 | 118 |
119 // Trim back the stack to put the parameters at the top | 119 // Trim back the stack to put the parameters at the top |
120 stack->set_sp(istate->stack() + 1); | 120 stack->set_sp(istate->stack() + 1); |
121 | 121 |
122 // Make the call | 122 // Make the call |
213 // Push our result | 213 // Push our result |
214 for (int i = 0; i < result_slots; i++) | 214 for (int i = 0; i < result_slots; i++) |
215 stack->push(result[-i]); | 215 stack->push(result[-i]); |
216 } | 216 } |
217 | 217 |
218 int CppInterpreter::native_entry(methodOop method, intptr_t UNUSED, TRAPS) { | 218 int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { |
219 // Make sure method is native and not abstract | 219 // Make sure method is native and not abstract |
220 assert(method->is_native() && !method->is_abstract(), "should be"); | 220 assert(method->is_native() && !method->is_abstract(), "should be"); |
221 | 221 |
222 JavaThread *thread = (JavaThread *) THREAD; | 222 JavaThread *thread = (JavaThread *) THREAD; |
223 ZeroStack *stack = thread->zero_stack(); | 223 ZeroStack *stack = thread->zero_stack(); |
483 | 483 |
484 // No deoptimized frames on the stack | 484 // No deoptimized frames on the stack |
485 return 0; | 485 return 0; |
486 } | 486 } |
487 | 487 |
488 int CppInterpreter::accessor_entry(methodOop method, intptr_t UNUSED, TRAPS) { | 488 int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) { |
489 JavaThread *thread = (JavaThread *) THREAD; | 489 JavaThread *thread = (JavaThread *) THREAD; |
490 ZeroStack *stack = thread->zero_stack(); | 490 ZeroStack *stack = thread->zero_stack(); |
491 intptr_t *locals = stack->sp(); | 491 intptr_t *locals = stack->sp(); |
492 | 492 |
493 // Drop into the slow path if we need a safepoint check | 493 // Drop into the slow path if we need a safepoint check |
516 code[4] == Bytecodes::_areturn), "should do"); | 516 code[4] == Bytecodes::_areturn), "should do"); |
517 u2 index = Bytes::get_native_u2(&code[2]); | 517 u2 index = Bytes::get_native_u2(&code[2]); |
518 | 518 |
519 // Get the entry from the constant pool cache, and drop into | 519 // Get the entry from the constant pool cache, and drop into |
520 // the slow path if it has not been resolved | 520 // the slow path if it has not been resolved |
521 constantPoolCacheOop cache = method->constants()->cache(); | 521 ConstantPoolCache* cache = method->constants()->cache(); |
522 ConstantPoolCacheEntry* entry = cache->entry_at(index); | 522 ConstantPoolCacheEntry* entry = cache->entry_at(index); |
523 if (!entry->is_resolved(Bytecodes::_getfield)) { | 523 if (!entry->is_resolved(Bytecodes::_getfield)) { |
524 return normal_entry(method, 0, THREAD); | 524 return normal_entry(method, 0, THREAD); |
525 } | 525 } |
526 | 526 |
611 | 611 |
612 // No deoptimized frames on the stack | 612 // No deoptimized frames on the stack |
613 return 0; | 613 return 0; |
614 } | 614 } |
615 | 615 |
616 int CppInterpreter::empty_entry(methodOop method, intptr_t UNUSED, TRAPS) { | 616 int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) { |
617 JavaThread *thread = (JavaThread *) THREAD; | 617 JavaThread *thread = (JavaThread *) THREAD; |
618 ZeroStack *stack = thread->zero_stack(); | 618 ZeroStack *stack = thread->zero_stack(); |
619 | 619 |
620 // Drop into the slow path if we need a safepoint check | 620 // Drop into the slow path if we need a safepoint check |
621 if (SafepointSynchronize::do_call_back()) { | 621 if (SafepointSynchronize::do_call_back()) { |
627 | 627 |
628 // No deoptimized frames on the stack | 628 // No deoptimized frames on the stack |
629 return 0; | 629 return 0; |
630 } | 630 } |
631 | 631 |
632 int CppInterpreter::method_handle_entry(methodOop method, | 632 int CppInterpreter::method_handle_entry(Method* method, |
633 intptr_t UNUSED, TRAPS) { | 633 intptr_t UNUSED, TRAPS) { |
634 JavaThread *thread = (JavaThread *) THREAD; | 634 JavaThread *thread = (JavaThread *) THREAD; |
635 ZeroStack *stack = thread->zero_stack(); | 635 ZeroStack *stack = thread->zero_stack(); |
636 int argument_slots = method->size_of_parameters(); | 636 int argument_slots = method->size_of_parameters(); |
637 int result_slots = type2size[result_type_of(method)]; | 637 int result_slots = type2size[result_type_of(method)]; |
735 MethodHandleEntry *entry = | 735 MethodHandleEntry *entry = |
736 java_lang_invoke_MethodHandle::vmentry(method_handle); | 736 java_lang_invoke_MethodHandle::vmentry(method_handle); |
737 MethodHandles::EntryKind entry_kind = | 737 MethodHandles::EntryKind entry_kind = |
738 (MethodHandles::EntryKind) (((intptr_t) entry) & 0xffffffff); | 738 (MethodHandles::EntryKind) (((intptr_t) entry) & 0xffffffff); |
739 | 739 |
740 methodOop method = NULL; | 740 Method* method = NULL; |
741 switch (entry_kind) { | 741 switch (entry_kind) { |
742 case MethodHandles::_invokestatic_mh: | 742 case MethodHandles::_invokestatic_mh: |
743 direct_to_method = true; | 743 direct_to_method = true; |
744 break; | 744 break; |
745 | 745 |
759 assert(HAS_PENDING_EXCEPTION, "should do"); | 759 assert(HAS_PENDING_EXCEPTION, "should do"); |
760 return; | 760 return; |
761 } | 761 } |
762 if (entry_kind != MethodHandles::_invokespecial_mh) { | 762 if (entry_kind != MethodHandles::_invokespecial_mh) { |
763 intptr_t index = java_lang_invoke_DirectMethodHandle::vmindex(method_handle); | 763 intptr_t index = java_lang_invoke_DirectMethodHandle::vmindex(method_handle); |
764 instanceKlass* rcvrKlass = | 764 InstanceKlass* rcvrKlass = |
765 (instanceKlass *) receiver->klass()->klass_part(); | 765 (InstanceKlass *) receiver->klass(); |
766 if (entry_kind == MethodHandles::_invokevirtual_mh) { | 766 if (entry_kind == MethodHandles::_invokevirtual_mh) { |
767 method = (methodOop) rcvrKlass->start_of_vtable()[index]; | 767 method = (Method*) rcvrKlass->start_of_vtable()[index]; |
768 } | 768 } |
769 else { | 769 else { |
770 oop iclass = java_lang_invoke_MethodHandle::vmtarget(method_handle); | 770 oop iclass = java_lang_invoke_MethodHandle::next_target(method_handle); |
771 itableOffsetEntry* ki = | 771 itableOffsetEntry* ki = |
772 (itableOffsetEntry *) rcvrKlass->start_of_itable(); | 772 (itableOffsetEntry *) rcvrKlass->start_of_itable(); |
773 int i, length = rcvrKlass->itable_length(); | 773 int i, length = rcvrKlass->itable_length(); |
774 for (i = 0; i < length; i++, ki++ ) { | 774 for (i = 0; i < length; i++, ki++ ) { |
775 if (ki->interface_klass() == iclass) | 775 if (ki->interface_klass() == iclass) |
871 break; | 871 break; |
872 | 872 |
873 case MethodHandles::_adapter_retype_only: | 873 case MethodHandles::_adapter_retype_only: |
874 case MethodHandles::_adapter_retype_raw: | 874 case MethodHandles::_adapter_retype_raw: |
875 src_rtype = result_type_of_handle( | 875 src_rtype = result_type_of_handle( |
876 java_lang_invoke_MethodHandle::vmtarget(method_handle)); | 876 java_lang_invoke_MethodHandle::next_target(method_handle)); |
877 dst_rtype = result_type_of_handle(method_handle); | 877 dst_rtype = result_type_of_handle(method_handle); |
878 break; | 878 break; |
879 | 879 |
880 case MethodHandles::_adapter_check_cast: | 880 case MethodHandles::_adapter_check_cast: |
881 { | 881 { |
882 int arg_slot = | 882 int arg_slot = |
883 java_lang_invoke_AdapterMethodHandle::vmargslot(method_handle); | 883 java_lang_invoke_AdapterMethodHandle::vmargslot(method_handle); |
884 oop arg = VMSLOTS_OBJECT(arg_slot); | 884 oop arg = VMSLOTS_OBJECT(arg_slot); |
885 if (arg != NULL) { | 885 if (arg != NULL) { |
886 klassOop objKlassOop = arg->klass(); | 886 Klass* objKlassOop = arg->klass(); |
887 klassOop klassOf = java_lang_Class::as_klassOop( | 887 Klass* klassOf = java_lang_Class::as_Klass( |
888 java_lang_invoke_AdapterMethodHandle::argument(method_handle)); | 888 java_lang_invoke_AdapterMethodHandle::argument(method_handle)); |
889 | 889 |
890 if (objKlassOop != klassOf && | 890 if (objKlassOop != klassOf && |
891 !objKlassOop->klass_part()->is_subtype_of(klassOf)) { | 891 !objKlassOop->is_subtype_of(klassOf)) { |
892 ResourceMark rm(THREAD); | 892 ResourceMark rm(THREAD); |
893 const char* objName = Klass::cast(objKlassOop)->external_name(); | 893 const char* objName = Klass::cast(objKlassOop)->external_name(); |
894 const char* klassName = Klass::cast(klassOf)->external_name(); | 894 const char* klassName = Klass::cast(klassOf)->external_name(); |
895 char* message = SharedRuntime::generate_class_cast_message( | 895 char* message = SharedRuntime::generate_class_cast_message( |
896 objName, klassName); | 896 objName, klassName); |
1087 | 1087 |
1088 // Continue along the chain | 1088 // Continue along the chain |
1089 if (direct_to_method) { | 1089 if (direct_to_method) { |
1090 if (method == NULL) { | 1090 if (method == NULL) { |
1091 method = | 1091 method = |
1092 (methodOop) java_lang_invoke_MethodHandle::vmtarget(method_handle); | 1092 (Method*) java_lang_invoke_MethodHandle::vmtarget(method_handle); |
1093 } | 1093 } |
1094 address entry_point = method->from_interpreted_entry(); | 1094 address entry_point = method->from_interpreted_entry(); |
1095 Interpreter::invoke_method(method, entry_point, THREAD); | 1095 Interpreter::invoke_method(method, entry_point, THREAD); |
1096 } | 1096 } |
1097 else { | 1097 else { |
1098 process_method_handle( | 1098 process_method_handle( |
1099 java_lang_invoke_MethodHandle::vmtarget(method_handle), THREAD); | 1099 java_lang_invoke_MethodHandle::next_target(method_handle), THREAD); |
1100 } | 1100 } |
1101 // NB all oops now trashed | 1101 // NB all oops now trashed |
1102 | 1102 |
1103 // Adapt the result type, if necessary | 1103 // Adapt the result type, if necessary |
1104 if (src_rtype != dst_rtype && !HAS_PENDING_EXCEPTION) { | 1104 if (src_rtype != dst_rtype && !HAS_PENDING_EXCEPTION) { |
1170 } | 1170 } |
1171 | 1171 |
1172 BasicType CppInterpreter::result_type_of_handle(oop method_handle) { | 1172 BasicType CppInterpreter::result_type_of_handle(oop method_handle) { |
1173 oop method_type = java_lang_invoke_MethodHandle::type(method_handle); | 1173 oop method_type = java_lang_invoke_MethodHandle::type(method_handle); |
1174 oop return_type = java_lang_invoke_MethodType::rtype(method_type); | 1174 oop return_type = java_lang_invoke_MethodType::rtype(method_type); |
1175 return java_lang_Class::as_BasicType(return_type, (klassOop *) NULL); | 1175 return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL); |
1176 } | 1176 } |
1177 | 1177 |
1178 intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack, | 1178 intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack, |
1179 oop method_handle) { | 1179 oop method_handle) { |
1180 oop method_type = java_lang_invoke_MethodHandle::type(method_handle); | 1180 oop method_type = java_lang_invoke_MethodHandle::type(method_handle); |
1187 Symbol* name, | 1187 Symbol* name, |
1188 char* message)) | 1188 char* message)) |
1189 THROW_MSG(name, message); | 1189 THROW_MSG(name, message); |
1190 IRT_END | 1190 IRT_END |
1191 | 1191 |
1192 InterpreterFrame *InterpreterFrame::build(const methodOop method, TRAPS) { | 1192 InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) { |
1193 JavaThread *thread = (JavaThread *) THREAD; | 1193 JavaThread *thread = (JavaThread *) THREAD; |
1194 ZeroStack *stack = thread->zero_stack(); | 1194 ZeroStack *stack = thread->zero_stack(); |
1195 | 1195 |
1196 // Calculate the size of the frame we'll build, including | 1196 // Calculate the size of the frame we'll build, including |
1197 // any adjustments to the caller's frame that we'll make. | 1197 // any adjustments to the caller's frame that we'll make. |
1283 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, | 1283 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, |
1284 "index out of bounds"); | 1284 "index out of bounds"); |
1285 return i; | 1285 return i; |
1286 } | 1286 } |
1287 | 1287 |
1288 BasicType CppInterpreter::result_type_of(methodOop method) { | 1288 BasicType CppInterpreter::result_type_of(Method* method) { |
1289 BasicType t; | 1289 BasicType t; |
1290 switch (method->result_index()) { | 1290 switch (method->result_index()) { |
1291 case 0 : t = T_BOOLEAN; break; | 1291 case 0 : t = T_BOOLEAN; break; |
1292 case 1 : t = T_CHAR; break; | 1292 case 1 : t = T_CHAR; break; |
1293 case 2 : t = T_BYTE; break; | 1293 case 2 : t = T_BYTE; break; |
1438 stack->alloc((size_in_words - header_words) * wordSize); | 1438 stack->alloc((size_in_words - header_words) * wordSize); |
1439 | 1439 |
1440 return (InterpreterFrame *) fp; | 1440 return (InterpreterFrame *) fp; |
1441 } | 1441 } |
1442 | 1442 |
1443 int AbstractInterpreter::layout_activation(methodOop method, | 1443 int AbstractInterpreter::layout_activation(Method* method, |
1444 int tempcount, | 1444 int tempcount, |
1445 int popframe_extra_args, | 1445 int popframe_extra_args, |
1446 int moncount, | 1446 int moncount, |
1447 int caller_actual_parameters, | 1447 int caller_actual_parameters, |
1448 int callee_param_count, | 1448 int callee_param_count, |
1494 } | 1494 } |
1495 | 1495 |
1496 void BytecodeInterpreter::layout_interpreterState(interpreterState istate, | 1496 void BytecodeInterpreter::layout_interpreterState(interpreterState istate, |
1497 frame* caller, | 1497 frame* caller, |
1498 frame* current, | 1498 frame* current, |
1499 methodOop method, | 1499 Method* method, |
1500 intptr_t* locals, | 1500 intptr_t* locals, |
1501 intptr_t* stack, | 1501 intptr_t* stack, |
1502 intptr_t* stack_base, | 1502 intptr_t* stack_base, |
1503 intptr_t* monitor_base, | 1503 intptr_t* monitor_base, |
1504 intptr_t* frame_bottom, | 1504 intptr_t* frame_bottom, |
1537 return NULL; | 1537 return NULL; |
1538 } | 1538 } |
1539 | 1539 |
1540 // Helper for (runtime) stack overflow checks | 1540 // Helper for (runtime) stack overflow checks |
1541 | 1541 |
1542 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { | 1542 int AbstractInterpreter::size_top_interpreter_activation(Method* method) { |
1543 return 0; | 1543 return 0; |
1544 } | 1544 } |
1545 | 1545 |
1546 // Helper for figuring out if frames are interpreter frames | 1546 // Helper for figuring out if frames are interpreter frames |
1547 | 1547 |