Thu, 24 Oct 2013 16:23:07 -0700
8026328: Setting a breakpoint on invokedynamic crashes the JVM
Reviewed-by: jrose, roland
never@1445 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
twisti@2762 | 3 | * Copyright 2009, 2010, 2011 Red Hat, Inc. |
never@1445 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
never@1445 | 5 | * |
never@1445 | 6 | * This code is free software; you can redistribute it and/or modify it |
never@1445 | 7 | * under the terms of the GNU General Public License version 2 only, as |
never@1445 | 8 | * published by the Free Software Foundation. |
never@1445 | 9 | * |
never@1445 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
never@1445 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
never@1445 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
never@1445 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
never@1445 | 14 | * accompanied this code). |
never@1445 | 15 | * |
never@1445 | 16 | * You should have received a copy of the GNU General Public License version |
never@1445 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
never@1445 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
never@1445 | 19 | * |
trims@1907 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 21 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 22 | * questions. |
never@1445 | 23 | * |
never@1445 | 24 | */ |
never@1445 | 25 | |
stefank@2314 | 26 | #include "precompiled.hpp" |
twisti@4237 | 27 | #include "interpreter/interpreterGenerator.hpp" |
stefank@2314 | 28 | #include "interpreter/interpreter.hpp" |
stefank@2314 | 29 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 30 | #include "prims/methodHandles.hpp" |
twisti@1781 | 31 | |
twisti@4237 | 32 | void MethodHandles::invoke_target(Method* method, TRAPS) { |
twisti@4237 | 33 | |
twisti@4237 | 34 | JavaThread *thread = (JavaThread *) THREAD; |
twisti@4237 | 35 | ZeroStack *stack = thread->zero_stack(); |
twisti@4237 | 36 | InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
twisti@4237 | 37 | interpreterState istate = frame->interpreter_state(); |
twisti@4237 | 38 | |
twisti@4237 | 39 | // Trim back the stack to put the parameters at the top |
twisti@4237 | 40 | stack->set_sp(istate->stack() + 1); |
twisti@4237 | 41 | |
twisti@4237 | 42 | Interpreter::invoke_method(method, method->from_interpreted_entry(), THREAD); |
twisti@4237 | 43 | |
twisti@4237 | 44 | // Convert the result |
twisti@4237 | 45 | istate->set_stack(stack->sp() - 1); |
twisti@4237 | 46 | |
twisti@1865 | 47 | } |
twisti@1865 | 48 | |
twisti@4237 | 49 | oop MethodHandles::popFromStack(TRAPS) { |
twisti@4237 | 50 | |
twisti@4237 | 51 | JavaThread *thread = (JavaThread *) THREAD; |
twisti@4237 | 52 | InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
twisti@4237 | 53 | interpreterState istate = frame->interpreter_state(); |
twisti@4237 | 54 | intptr_t* topOfStack = istate->stack(); |
twisti@4237 | 55 | |
twisti@4237 | 56 | oop top = STACK_OBJECT(-1); |
twisti@4237 | 57 | MORE_STACK(-1); |
twisti@4237 | 58 | istate->set_stack(topOfStack); |
twisti@4237 | 59 | |
twisti@4237 | 60 | return top; |
twisti@4237 | 61 | |
twisti@1781 | 62 | } |
twisti@4237 | 63 | |
twisti@4237 | 64 | int MethodHandles::method_handle_entry_invokeBasic(Method* method, intptr_t UNUSED, TRAPS) { |
twisti@4237 | 65 | |
twisti@4237 | 66 | JavaThread *thread = (JavaThread *) THREAD; |
twisti@4237 | 67 | InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
twisti@4237 | 68 | interpreterState istate = frame->interpreter_state(); |
twisti@4237 | 69 | intptr_t* topOfStack = istate->stack(); |
twisti@4237 | 70 | |
twisti@4237 | 71 | // 'this' is a MethodHandle. We resolve the target method by accessing this.form.vmentry.vmtarget. |
twisti@4237 | 72 | int numArgs = method->size_of_parameters(); |
twisti@4237 | 73 | oop lform1 = java_lang_invoke_MethodHandle::form(STACK_OBJECT(-numArgs)); // this.form |
twisti@4237 | 74 | oop vmEntry1 = java_lang_invoke_LambdaForm::vmentry(lform1); |
twisti@4237 | 75 | Method* vmtarget = (Method*) java_lang_invoke_MemberName::vmtarget(vmEntry1); |
twisti@4237 | 76 | |
twisti@4237 | 77 | invoke_target(vmtarget, THREAD); |
twisti@4237 | 78 | |
twisti@4237 | 79 | // No deoptimized frames on the stack |
twisti@4237 | 80 | return 0; |
twisti@4237 | 81 | } |
twisti@4237 | 82 | |
twisti@4237 | 83 | int MethodHandles::method_handle_entry_linkToStaticOrSpecial(Method* method, intptr_t UNUSED, TRAPS) { |
twisti@4237 | 84 | |
twisti@4237 | 85 | // Pop appendix argument from stack. This is a MemberName which we resolve to the |
twisti@4237 | 86 | // target method. |
twisti@4237 | 87 | oop vmentry = popFromStack(THREAD); |
twisti@4237 | 88 | |
twisti@4237 | 89 | Method* vmtarget = (Method*) java_lang_invoke_MemberName::vmtarget(vmentry); |
twisti@4237 | 90 | |
twisti@4237 | 91 | invoke_target(vmtarget, THREAD); |
twisti@4237 | 92 | |
twisti@4237 | 93 | return 0; |
twisti@4237 | 94 | } |
twisti@4237 | 95 | |
twisti@4237 | 96 | int MethodHandles::method_handle_entry_linkToInterface(Method* method, intptr_t UNUSED, TRAPS) { |
twisti@4237 | 97 | JavaThread *thread = (JavaThread *) THREAD; |
twisti@4237 | 98 | InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
twisti@4237 | 99 | interpreterState istate = frame->interpreter_state(); |
twisti@4237 | 100 | |
twisti@4237 | 101 | // Pop appendix argument from stack. This is a MemberName which we resolve to the |
twisti@4237 | 102 | // target method. |
twisti@4237 | 103 | oop vmentry = popFromStack(THREAD); |
twisti@4237 | 104 | intptr_t* topOfStack = istate->stack(); |
twisti@4237 | 105 | |
twisti@4237 | 106 | // Resolve target method by looking up in the receiver object's itable. |
twisti@4237 | 107 | Klass* clazz = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(vmentry)); |
twisti@4237 | 108 | intptr_t vmindex = java_lang_invoke_MemberName::vmindex(vmentry); |
twisti@4237 | 109 | Method* target = (Method*) java_lang_invoke_MemberName::vmtarget(vmentry); |
twisti@4237 | 110 | |
twisti@4237 | 111 | int numArgs = target->size_of_parameters(); |
twisti@4237 | 112 | oop recv = STACK_OBJECT(-numArgs); |
twisti@4237 | 113 | |
twisti@4237 | 114 | InstanceKlass* klass_part = InstanceKlass::cast(recv->klass()); |
twisti@4237 | 115 | itableOffsetEntry* ki = (itableOffsetEntry*) klass_part->start_of_itable(); |
twisti@4237 | 116 | int i; |
twisti@4237 | 117 | for ( i = 0 ; i < klass_part->itable_length() ; i++, ki++ ) { |
twisti@4237 | 118 | if (ki->interface_klass() == clazz) break; |
twisti@4237 | 119 | } |
twisti@4237 | 120 | |
twisti@4237 | 121 | itableMethodEntry* im = ki->first_method_entry(recv->klass()); |
twisti@4237 | 122 | Method* vmtarget = im[vmindex].method(); |
twisti@4237 | 123 | |
twisti@4237 | 124 | invoke_target(vmtarget, THREAD); |
twisti@4237 | 125 | |
twisti@4237 | 126 | return 0; |
twisti@4237 | 127 | } |
twisti@4237 | 128 | |
twisti@4237 | 129 | int MethodHandles::method_handle_entry_linkToVirtual(Method* method, intptr_t UNUSED, TRAPS) { |
twisti@4237 | 130 | JavaThread *thread = (JavaThread *) THREAD; |
twisti@4237 | 131 | |
twisti@4237 | 132 | InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
twisti@4237 | 133 | interpreterState istate = frame->interpreter_state(); |
twisti@4237 | 134 | |
twisti@4237 | 135 | // Pop appendix argument from stack. This is a MemberName which we resolve to the |
twisti@4237 | 136 | // target method. |
twisti@4237 | 137 | oop vmentry = popFromStack(THREAD); |
twisti@4237 | 138 | intptr_t* topOfStack = istate->stack(); |
twisti@4237 | 139 | |
twisti@4237 | 140 | // Resolve target method by looking up in the receiver object's vtable. |
twisti@4237 | 141 | intptr_t vmindex = java_lang_invoke_MemberName::vmindex(vmentry); |
twisti@4237 | 142 | Method* target = (Method*) java_lang_invoke_MemberName::vmtarget(vmentry); |
twisti@4237 | 143 | int numArgs = target->size_of_parameters(); |
twisti@4237 | 144 | oop recv = STACK_OBJECT(-numArgs); |
twisti@4237 | 145 | Klass* clazz = recv->klass(); |
twisti@4237 | 146 | Klass* klass_part = InstanceKlass::cast(clazz); |
twisti@4237 | 147 | klassVtable* vtable = klass_part->vtable(); |
twisti@4237 | 148 | Method* vmtarget = vtable->method_at(vmindex); |
twisti@4237 | 149 | |
twisti@4237 | 150 | invoke_target(vmtarget, THREAD); |
twisti@4237 | 151 | |
twisti@4237 | 152 | return 0; |
twisti@4237 | 153 | } |
twisti@4237 | 154 | |
twisti@4237 | 155 | int MethodHandles::method_handle_entry_invalid(Method* method, intptr_t UNUSED, TRAPS) { |
twisti@4237 | 156 | ShouldNotReachHere(); |
twisti@4237 | 157 | return 0; |
twisti@4237 | 158 | } |
twisti@4237 | 159 | |
twisti@4237 | 160 | address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* masm, |
twisti@4237 | 161 | vmIntrinsics::ID iid) { |
twisti@4237 | 162 | switch (iid) { |
twisti@4237 | 163 | case vmIntrinsics::_invokeGeneric: |
twisti@4237 | 164 | case vmIntrinsics::_compiledLambdaForm: |
twisti@4237 | 165 | // Perhaps surprisingly, the symbolic references visible to Java are not directly used. |
twisti@4237 | 166 | // They are linked to Java-generated adapters via MethodHandleNatives.linkMethod. |
twisti@4237 | 167 | // They all allow an appendix argument. |
twisti@4237 | 168 | return InterpreterGenerator::generate_entry_impl(masm, (address) MethodHandles::method_handle_entry_invalid); |
twisti@4237 | 169 | case vmIntrinsics::_invokeBasic: |
twisti@4237 | 170 | return InterpreterGenerator::generate_entry_impl(masm, (address) MethodHandles::method_handle_entry_invokeBasic); |
twisti@4237 | 171 | case vmIntrinsics::_linkToStatic: |
twisti@4237 | 172 | case vmIntrinsics::_linkToSpecial: |
twisti@4237 | 173 | return InterpreterGenerator::generate_entry_impl(masm, (address) MethodHandles::method_handle_entry_linkToStaticOrSpecial); |
twisti@4237 | 174 | case vmIntrinsics::_linkToInterface: |
twisti@4237 | 175 | return InterpreterGenerator::generate_entry_impl(masm, (address) MethodHandles::method_handle_entry_linkToInterface); |
twisti@4237 | 176 | case vmIntrinsics::_linkToVirtual: |
twisti@4237 | 177 | return InterpreterGenerator::generate_entry_impl(masm, (address) MethodHandles::method_handle_entry_linkToVirtual); |
twisti@4237 | 178 | default: |
twisti@4237 | 179 | ShouldNotReachHere(); |
twisti@4237 | 180 | return NULL; |
twisti@4237 | 181 | } |
twisti@4237 | 182 | } |