614 _callee(callee),
615 _thread(THREAD),
616 _bytecode(THREAD, 50),
617 _constants(THREAD, 10),
618 _cur_stack(0),
619 _max_stack(0),
620 _rtype(T_ILLEGAL)
621 {
622
623 // Element zero is always the null constant.
624 (void) _constants.append(NULL);
625
626 // Set name and signature index.
627 _name_index = cpool_symbol_put(_callee->name());
628 _signature_index = cpool_symbol_put(_callee->signature());
629
630 // Get return type klass.
631 Handle first_mtype(THREAD, chain().method_type_oop());
632 // _rklass is NULL for primitives.
633 _rtype = java_lang_Class::as_BasicType(java_dyn_MethodType::rtype(first_mtype()), &_rklass);
634
635 int params = _callee->size_of_parameters(); // Incoming arguments plus receiver.
636 _num_params = for_invokedynamic() ? params - 1 : params; // XXX Check if callee is static?
637 }
638
639
640 // -----------------------------------------------------------------------------
641 // MethodHandleCompiler::compile
642 //
643 // Compile this MethodHandle into a bytecode adapter and return a
644 // methodOop.
645 methodHandle MethodHandleCompiler::compile(TRAPS) {
646 assert(_thread == THREAD, "must be same thread");
647 methodHandle nullHandle;
648 (void) walk(CHECK_(nullHandle));
649 return get_method_oop(CHECK_(nullHandle));
650 }
651
652
653 void MethodHandleCompiler::emit_bc(Bytecodes::Code op, int index) {
940 // MethodHandleCompiler
941 //
942
943 static jvalue zero_jvalue;
944
945 // Emit bytecodes for the given invoke instruction.
946 MethodHandleWalker::ArgToken
947 MethodHandleCompiler::make_invoke(methodOop m, vmIntrinsics::ID iid,
948 Bytecodes::Code op, bool tailcall,
949 int argc, MethodHandleWalker::ArgToken* argv,
950 TRAPS) {
951 if (m == NULL) {
952 // Get the intrinsic methodOop.
953 m = vmIntrinsics::method_for(iid);
954 }
955
956 klassOop klass = m->method_holder();
957 symbolOop name = m->name();
958 symbolOop signature = m->signature();
959
960 // This generated adapter method should be in the same class as the
961 // DMH target method (for accessability reasons).
962 if (tailcall) {
963 _target_klass = klass;
964 }
965
966 // instanceKlass* ik = instanceKlass::cast(klass);
967 // tty->print_cr("MethodHandleCompiler::make_invoke: %s %s.%s%s", Bytecodes::name(op), ik->external_name(), name->as_C_string(), signature->as_C_string());
968
969 // Inline the method.
970 InvocationCounter* ic = m->invocation_counter();
971 ic->set_carry();
972
973 for (int i = 0; i < argc; i++) {
974 ArgToken arg = argv[i];
975 TokenType tt = arg.token_type();
976 BasicType bt = arg.basic_type();
977
978 switch (tt) {
979 case tt_parameter:
980 case tt_temporary:
981 emit_load(bt, arg.index());
982 break;
983 case tt_constant:
1000 int klass_index = cpool_klass_put(klass);
1001 int methodref_index = cpool_methodref_put(klass_index, name_and_type_index);
1002
1003 // Generate invoke.
1004 switch (op) {
1005 case Bytecodes::_invokestatic:
1006 case Bytecodes::_invokespecial:
1007 case Bytecodes::_invokevirtual:
1008 emit_bc(op, methodref_index);
1009 break;
1010 case Bytecodes::_invokeinterface:
1011 Unimplemented();
1012 break;
1013 default:
1014 ShouldNotReachHere();
1015 }
1016
1017 // If tailcall, we have walked all the way to a direct method handle.
1018 // Otherwise, make a recursive call to some helper routine.
1019 BasicType rbt = m->result_type();
1020 ArgToken ret;
1021 if (tailcall) {
1022 if (rbt != _rtype) {
1023 if (rbt == T_VOID) {
1024 // push a zero of the right sort
1025 ArgToken zero;
1026 if (_rtype == T_OBJECT) {
1027 zero = make_oop_constant(NULL, CHECK_(zero));
1028 } else {
1029 zero = make_prim_constant(_rtype, &zero_jvalue, CHECK_(zero));
1030 }
1031 emit_load_constant(zero);
1032 } else if (_rtype == T_VOID) {
1033 // We'll emit a _return with something on the stack.
1034 // It's OK to ignore what's on the stack.
1035 } else {
1036 tty->print_cr("*** rbt=%d != rtype=%d", rbt, _rtype);
1037 assert(false, "IMPLEMENT ME");
1038 }
1039 }
|
614 _callee(callee),
615 _thread(THREAD),
616 _bytecode(THREAD, 50),
617 _constants(THREAD, 10),
618 _cur_stack(0),
619 _max_stack(0),
620 _rtype(T_ILLEGAL)
621 {
622
623 // Element zero is always the null constant.
624 (void) _constants.append(NULL);
625
626 // Set name and signature index.
627 _name_index = cpool_symbol_put(_callee->name());
628 _signature_index = cpool_symbol_put(_callee->signature());
629
630 // Get return type klass.
631 Handle first_mtype(THREAD, chain().method_type_oop());
632 // _rklass is NULL for primitives.
633 _rtype = java_lang_Class::as_BasicType(java_dyn_MethodType::rtype(first_mtype()), &_rklass);
634 if (_rtype == T_ARRAY) _rtype = T_OBJECT;
635
636 int params = _callee->size_of_parameters(); // Incoming arguments plus receiver.
637 _num_params = for_invokedynamic() ? params - 1 : params; // XXX Check if callee is static?
638 }
639
640
641 // -----------------------------------------------------------------------------
642 // MethodHandleCompiler::compile
643 //
644 // Compile this MethodHandle into a bytecode adapter and return a
645 // methodOop.
646 methodHandle MethodHandleCompiler::compile(TRAPS) {
647 assert(_thread == THREAD, "must be same thread");
648 methodHandle nullHandle;
649 (void) walk(CHECK_(nullHandle));
650 return get_method_oop(CHECK_(nullHandle));
651 }
652
653
654 void MethodHandleCompiler::emit_bc(Bytecodes::Code op, int index) {
941 // MethodHandleCompiler
942 //
943
944 static jvalue zero_jvalue;
945
946 // Emit bytecodes for the given invoke instruction.
947 MethodHandleWalker::ArgToken
948 MethodHandleCompiler::make_invoke(methodOop m, vmIntrinsics::ID iid,
949 Bytecodes::Code op, bool tailcall,
950 int argc, MethodHandleWalker::ArgToken* argv,
951 TRAPS) {
952 if (m == NULL) {
953 // Get the intrinsic methodOop.
954 m = vmIntrinsics::method_for(iid);
955 }
956
957 klassOop klass = m->method_holder();
958 symbolOop name = m->name();
959 symbolOop signature = m->signature();
960
961 if (tailcall) {
962 // Actually, in order to make these methods more recognizable,
963 // let's put them in holder classes MethodHandle and InvokeDynamic.
964 // That way stack walkers and compiler heuristics can recognize them.
965 _target_klass = (for_invokedynamic()
966 ? SystemDictionary::InvokeDynamic_klass()
967 : SystemDictionary::MethodHandle_klass());
968 }
969
970 // instanceKlass* ik = instanceKlass::cast(klass);
971 // tty->print_cr("MethodHandleCompiler::make_invoke: %s %s.%s%s", Bytecodes::name(op), ik->external_name(), name->as_C_string(), signature->as_C_string());
972
973 // Inline the method.
974 InvocationCounter* ic = m->invocation_counter();
975 ic->set_carry();
976
977 for (int i = 0; i < argc; i++) {
978 ArgToken arg = argv[i];
979 TokenType tt = arg.token_type();
980 BasicType bt = arg.basic_type();
981
982 switch (tt) {
983 case tt_parameter:
984 case tt_temporary:
985 emit_load(bt, arg.index());
986 break;
987 case tt_constant:
1004 int klass_index = cpool_klass_put(klass);
1005 int methodref_index = cpool_methodref_put(klass_index, name_and_type_index);
1006
1007 // Generate invoke.
1008 switch (op) {
1009 case Bytecodes::_invokestatic:
1010 case Bytecodes::_invokespecial:
1011 case Bytecodes::_invokevirtual:
1012 emit_bc(op, methodref_index);
1013 break;
1014 case Bytecodes::_invokeinterface:
1015 Unimplemented();
1016 break;
1017 default:
1018 ShouldNotReachHere();
1019 }
1020
1021 // If tailcall, we have walked all the way to a direct method handle.
1022 // Otherwise, make a recursive call to some helper routine.
1023 BasicType rbt = m->result_type();
1024 if (rbt == T_ARRAY) rbt = T_OBJECT;
1025 ArgToken ret;
1026 if (tailcall) {
1027 if (rbt != _rtype) {
1028 if (rbt == T_VOID) {
1029 // push a zero of the right sort
1030 ArgToken zero;
1031 if (_rtype == T_OBJECT) {
1032 zero = make_oop_constant(NULL, CHECK_(zero));
1033 } else {
1034 zero = make_prim_constant(_rtype, &zero_jvalue, CHECK_(zero));
1035 }
1036 emit_load_constant(zero);
1037 } else if (_rtype == T_VOID) {
1038 // We'll emit a _return with something on the stack.
1039 // It's OK to ignore what's on the stack.
1040 } else {
1041 tty->print_cr("*** rbt=%d != rtype=%d", rbt, _rtype);
1042 assert(false, "IMPLEMENT ME");
1043 }
1044 }
|