ciMethodHandle.cpp 3.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
22 23 24
 *
 */

25 26 27
#include "precompiled.hpp"
#include "ci/ciClassList.hpp"
#include "ci/ciInstance.hpp"
28
#include "ci/ciMethodData.hpp"
29 30 31 32
#include "ci/ciMethodHandle.hpp"
#include "ci/ciUtilities.hpp"
#include "prims/methodHandleWalk.hpp"
#include "prims/methodHandles.hpp"
33 34 35 36 37 38 39

// ciMethodHandle

// ------------------------------------------------------------------
// ciMethodHandle::get_adapter
//
// Return an adapter for this MethodHandle.
40
ciMethod* ciMethodHandle::get_adapter_impl(bool is_invokedynamic) {
41 42 43
  VM_ENTRY_MARK;
  Handle h(get_oop());
  methodHandle callee(_callee->get_methodOop());
44 45 46 47 48 49 50 51 52 53
  assert(callee->is_method_handle_invoke(), "");
  oop mt1 = callee->method_handle_type();
  oop mt2 = java_lang_invoke_MethodHandle::type(h());
  if (!java_lang_invoke_MethodType::equals(mt1, mt2)) {
    if (PrintMiscellaneous && (Verbose || WizardMode)) {
      tty->print_cr("ciMethodHandle::get_adapter: types not equal");
      mt1->print(); mt2->print();
    }
    return NULL;
  }
54 55
  // We catch all exceptions here that could happen in the method
  // handle compiler and stop the VM.
56
  MethodHandleCompiler mhc(h, callee->name(), callee->signature(), _profile.count(), is_invokedynamic, THREAD);
57 58 59 60 61 62 63 64 65
  if (!HAS_PENDING_EXCEPTION) {
    methodHandle m = mhc.compile(THREAD);
    if (!HAS_PENDING_EXCEPTION) {
      return CURRENT_ENV->get_object(m())->as_method();
    }
  }
  if (PrintMiscellaneous && (Verbose || WizardMode)) {
    tty->print("*** ciMethodHandle::get_adapter => ");
    PENDING_EXCEPTION->print();
66
    tty->print("*** get_adapter (%s): ", is_invokedynamic ? "indy" : "mh"); ((ciObject*)this)->print();
67 68 69
  }
  CLEAR_PENDING_EXCEPTION;
  return NULL;
70 71
}

72 73 74 75
// ------------------------------------------------------------------
// ciMethodHandle::get_adapter
//
// Return an adapter for this MethodHandle.
76
ciMethod* ciMethodHandle::get_adapter(bool is_invokedynamic) {
77 78 79 80 81 82 83 84 85 86 87
  ciMethod* result = get_adapter_impl(is_invokedynamic);
  if (result) {
    // Fake up the MDO maturity.
    ciMethodData* mdo = result->method_data();
    if (mdo != NULL && _caller->method_data() != NULL && _caller->method_data()->is_mature()) {
      mdo->set_mature();
    }
  }
  return result;
}

88

89
#ifdef ASSERT
90
// ------------------------------------------------------------------
91
// ciMethodHandle::print_chain_impl
92 93
//
// Implementation of the print method.
94
void ciMethodHandle::print_chain_impl() {
95 96
  ASSERT_IN_VM;
  MethodHandleChain::print(get_oop());
97
}
98 99 100 101 102 103


// ------------------------------------------------------------------
// ciMethodHandle::print_chain
//
// Implementation of the print_chain method.
104 105
void ciMethodHandle::print_chain() {
  GUARDED_VM_ENTRY(print_chain_impl(););
106 107
}
#endif