Wed, 12 Oct 2011 21:00:13 -0700
7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
Reviewed-by: jrose, never
twisti@1573 | 1 | /* |
twisti@2437 | 2 | * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
twisti@1573 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
twisti@1573 | 4 | * |
twisti@1573 | 5 | * This code is free software; you can redistribute it and/or modify it |
twisti@1573 | 6 | * under the terms of the GNU General Public License version 2 only, as |
twisti@1573 | 7 | * published by the Free Software Foundation. |
twisti@1573 | 8 | * |
twisti@1573 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
twisti@1573 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
twisti@1573 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
twisti@1573 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
twisti@1573 | 13 | * accompanied this code). |
twisti@1573 | 14 | * |
twisti@1573 | 15 | * You should have received a copy of the GNU General Public License version |
twisti@1573 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
twisti@1573 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
twisti@1573 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
twisti@1573 | 22 | * |
twisti@1573 | 23 | */ |
twisti@1573 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "ci/ciClassList.hpp" |
stefank@2314 | 27 | #include "ci/ciInstance.hpp" |
twisti@2903 | 28 | #include "ci/ciMethodData.hpp" |
stefank@2314 | 29 | #include "ci/ciMethodHandle.hpp" |
stefank@2314 | 30 | #include "ci/ciUtilities.hpp" |
stefank@2314 | 31 | #include "prims/methodHandleWalk.hpp" |
stefank@2314 | 32 | #include "prims/methodHandles.hpp" |
twisti@1573 | 33 | |
twisti@1573 | 34 | // ciMethodHandle |
twisti@1573 | 35 | |
twisti@1573 | 36 | // ------------------------------------------------------------------ |
twisti@1573 | 37 | // ciMethodHandle::get_adapter |
twisti@1573 | 38 | // |
twisti@1573 | 39 | // Return an adapter for this MethodHandle. |
never@3105 | 40 | ciMethod* ciMethodHandle::get_adapter_impl(bool is_invokedynamic) { |
twisti@1573 | 41 | VM_ENTRY_MARK; |
twisti@1573 | 42 | Handle h(get_oop()); |
twisti@1573 | 43 | methodHandle callee(_callee->get_methodOop()); |
jrose@2982 | 44 | assert(callee->is_method_handle_invoke(), ""); |
jrose@2982 | 45 | oop mt1 = callee->method_handle_type(); |
jrose@2982 | 46 | oop mt2 = java_lang_invoke_MethodHandle::type(h()); |
jrose@2982 | 47 | if (!java_lang_invoke_MethodType::equals(mt1, mt2)) { |
jrose@2982 | 48 | if (PrintMiscellaneous && (Verbose || WizardMode)) { |
jrose@2982 | 49 | tty->print_cr("ciMethodHandle::get_adapter: types not equal"); |
jrose@2982 | 50 | mt1->print(); mt2->print(); |
jrose@2982 | 51 | } |
jrose@2982 | 52 | return NULL; |
jrose@2982 | 53 | } |
twisti@2437 | 54 | // We catch all exceptions here that could happen in the method |
twisti@2437 | 55 | // handle compiler and stop the VM. |
never@2949 | 56 | MethodHandleCompiler mhc(h, callee->name(), callee->signature(), _profile.count(), is_invokedynamic, THREAD); |
jrose@2744 | 57 | if (!HAS_PENDING_EXCEPTION) { |
jrose@2744 | 58 | methodHandle m = mhc.compile(THREAD); |
jrose@2744 | 59 | if (!HAS_PENDING_EXCEPTION) { |
jrose@2744 | 60 | return CURRENT_ENV->get_object(m())->as_method(); |
jrose@2744 | 61 | } |
jrose@2744 | 62 | } |
jrose@2744 | 63 | if (PrintMiscellaneous && (Verbose || WizardMode)) { |
jrose@2744 | 64 | tty->print("*** ciMethodHandle::get_adapter => "); |
jrose@2744 | 65 | PENDING_EXCEPTION->print(); |
jrose@2982 | 66 | tty->print("*** get_adapter (%s): ", is_invokedynamic ? "indy" : "mh"); ((ciObject*)this)->print(); |
jrose@2744 | 67 | } |
jrose@2744 | 68 | CLEAR_PENDING_EXCEPTION; |
jrose@2744 | 69 | return NULL; |
twisti@1573 | 70 | } |
twisti@1573 | 71 | |
twisti@2903 | 72 | // ------------------------------------------------------------------ |
twisti@2903 | 73 | // ciMethodHandle::get_adapter |
twisti@2903 | 74 | // |
twisti@2903 | 75 | // Return an adapter for this MethodHandle. |
never@3105 | 76 | ciMethod* ciMethodHandle::get_adapter(bool is_invokedynamic) { |
twisti@2903 | 77 | ciMethod* result = get_adapter_impl(is_invokedynamic); |
twisti@2903 | 78 | if (result) { |
twisti@2903 | 79 | // Fake up the MDO maturity. |
twisti@2903 | 80 | ciMethodData* mdo = result->method_data(); |
twisti@2903 | 81 | if (mdo != NULL && _caller->method_data() != NULL && _caller->method_data()->is_mature()) { |
twisti@2903 | 82 | mdo->set_mature(); |
twisti@2903 | 83 | } |
twisti@2903 | 84 | } |
twisti@2903 | 85 | return result; |
twisti@2903 | 86 | } |
twisti@2903 | 87 | |
twisti@1573 | 88 | |
never@3105 | 89 | #ifndef PRODUCT |
twisti@1573 | 90 | // ------------------------------------------------------------------ |
never@3105 | 91 | // ciMethodHandle::print_chain_impl |
twisti@1573 | 92 | // |
twisti@1573 | 93 | // Implementation of the print method. |
never@3105 | 94 | void ciMethodHandle::print_chain_impl(outputStream* st) { |
never@3105 | 95 | ASSERT_IN_VM; |
never@3105 | 96 | MethodHandleChain::print(get_oop()); |
twisti@1573 | 97 | } |
never@3105 | 98 | |
never@3105 | 99 | |
never@3105 | 100 | // ------------------------------------------------------------------ |
never@3105 | 101 | // ciMethodHandle::print_chain |
never@3105 | 102 | // |
never@3105 | 103 | // Implementation of the print_chain method. |
never@3105 | 104 | void ciMethodHandle::print_chain(outputStream* st) { |
never@3105 | 105 | GUARDED_VM_ENTRY(print_chain_impl(st);); |
never@3105 | 106 | } |
never@3105 | 107 | #endif |