hotspot/src/share/vm/interpreter/linkResolver.cpp
author coleenp
Fri, 29 May 2015 11:35:51 -0400
changeset 31019 d05fcdd70109
parent 30773 3f15e2dc056b
child 32189 5264b560ab1b
permissions -rw-r--r--
8029567: Clean up linkResolver code Summary: Moved non-const reference return values to actual return values, refactored error handling code, remove oop from Method* variable names. Reviewed-by: jiangli, lfoltan, acorn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
28731
f7339cba0a6a 8067480: Crash in klassItable::initialize_itable_for_interface when running vm.runtime.defmeth.StaticMethodsTest.
lfoltan
parents: 27020
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5421
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5421
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5421
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    25
#include "precompiled.hpp"
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13929
diff changeset
    26
#include "classfile/defaultMethods.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    28
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    29
#include "compiler/compileBroker.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30227
diff changeset
    30
#include "gc/shared/collectedHeap.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    31
#include "interpreter/bytecode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
#include "interpreter/interpreterRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    33
#include "interpreter/linkResolver.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    34
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    35
#include "memory/universe.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    36
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    37
#include "oops/objArrayOop.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28738
diff changeset
    38
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    39
#include "prims/methodHandles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    40
#include "prims/nativeLookup.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    41
#include "runtime/compilationPolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    42
#include "runtime/fieldDescriptor.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    43
#include "runtime/frame.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    44
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    45
#include "runtime/reflection.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    46
#include "runtime/signature.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 14488
diff changeset
    47
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    48
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// Implementation of CallInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    55
void CallInfo::set_static(KlassHandle resolved_klass, const methodHandle& resolved_method, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
    56
  int vtable_index = Method::nonvirtual_vtable_index;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    57
  set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    61
void CallInfo::set_interface(KlassHandle resolved_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    62
                             KlassHandle selected_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    63
                             const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    64
                             const methodHandle& selected_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    65
                             int itable_index, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // This is only called for interface methods. If the resolved_method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // comes from java/lang/Object, it can be the subject of a virtual call, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // we should pick the vtable index from the resolved method.
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    69
  // In that case, the caller must call set_virtual instead of set_interface.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    70
  assert(resolved_method->method_holder()->is_interface(), "");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    71
  assert(itable_index == resolved_method()->itable_index(), "");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    72
  set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    75
void CallInfo::set_virtual(KlassHandle resolved_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    76
                           KlassHandle selected_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    77
                           const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    78
                           const methodHandle& selected_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    79
                           int vtable_index, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
    80
  assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index");
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    81
  assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), "");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    82
  CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    83
  set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    84
  assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    87
void CallInfo::set_handle(const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    88
                          Handle resolved_appendix,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    89
                          Handle resolved_method_type, TRAPS) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    90
  if (resolved_method.is_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    91
    THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    92
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
    93
  KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    94
  assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    95
         resolved_method->is_compiled_lambda_form(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
    96
         "linkMethod must return one of these");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
    97
  int vtable_index = Method::nonvirtual_vtable_index;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    98
  assert(!resolved_method->has_vtable_index(), "");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
    99
  set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   100
  _resolved_appendix    = resolved_appendix;
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   101
  _resolved_method_type = resolved_method_type;
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5547
diff changeset
   102
}
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5547
diff changeset
   103
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   104
void CallInfo::set_common(KlassHandle resolved_klass,
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   105
                          KlassHandle selected_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   106
                          const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   107
                          const methodHandle& selected_method,
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   108
                          CallKind kind,
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   109
                          int index,
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   110
                          TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  _resolved_klass  = resolved_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  _selected_klass  = selected_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  _resolved_method = resolved_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  _selected_method = selected_method;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   116
  _call_kind       = kind;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   117
  _call_index      = index;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   118
  _resolved_appendix = Handle();
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   119
  DEBUG_ONLY(verify());  // verify before making side effects
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   120
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6062
diff changeset
   121
  if (CompilationPolicy::must_be_compiled(selected_method)) {
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   122
    // This path is unusual, mostly used by the '-Xcomp' stress test mode.
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   123
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6062
diff changeset
   124
    // Note: with several active threads, the must_be_compiled may be true
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6062
diff changeset
   125
    //       while can_be_compiled is false; remove assert
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6062
diff changeset
   126
    // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if (THREAD->is_Compiler_thread()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      // don't force compilation, resolve was on behalf of compiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 14385
diff changeset
   131
    if (selected_method->method_holder()->is_not_initialized()) {
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   132
      // 'is_not_initialized' means not only '!is_initialized', but also that
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   133
      // initialization has not been started yet ('!being_initialized')
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   134
      // Do not force compilation of methods in uninitialized classes.
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   135
      // Note that doing this would throw an assert later,
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   136
      // in CompileBroker::compile_method.
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   137
      // We sometimes use the link resolver to do reflective lookups
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   138
      // even before classes are initialized.
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   139
      return;
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 4429
diff changeset
   140
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    CompileBroker::compile_method(selected_method, InvocationEntryBci,
10250
0794cd144834 7066339: Tiered: policy should make consistent decisions about osr levels
iveresov
parents: 10008
diff changeset
   142
                                  CompilationPolicy::policy()->initial_compile_level(),
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6062
diff changeset
   143
                                  methodHandle(), 0, "must_be_compiled", CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   147
// utility query for unreflecting a method
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   148
CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   149
  Klass* resolved_method_holder = resolved_method->method_holder();
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   150
  if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   151
    resolved_klass = resolved_method_holder;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   152
  }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   153
  _resolved_klass  = resolved_klass;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   154
  _selected_klass  = resolved_klass;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   155
  _resolved_method = resolved_method;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   156
  _selected_method = resolved_method;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   157
  // classify:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   158
  CallKind kind = CallInfo::unknown_kind;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   159
  int index = resolved_method->vtable_index();
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   160
  if (resolved_method->can_be_statically_bound()) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   161
    kind = CallInfo::direct_call;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   162
  } else if (!resolved_method_holder->is_interface()) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   163
    // Could be an Object method inherited into an interface, but still a vtable call.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   164
    kind = CallInfo::vtable_call;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   165
  } else if (!resolved_klass->is_interface()) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   166
    // A default or miranda method.  Compute the vtable index.
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   167
    ResourceMark rm;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   168
    klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable();
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   169
    index = LinkResolver::vtable_index_of_interface_method(resolved_klass,
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   170
                           resolved_method);
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   171
    assert(index >= 0 , "we should have valid vtable index at this point");
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   172
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   173
    kind = CallInfo::vtable_call;
20712
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   174
  } else if (resolved_method->has_vtable_index()) {
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   175
    // Can occur if an interface redeclares a method of Object.
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   176
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   177
#ifdef ASSERT
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   178
    // Ensure that this is really the case.
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   179
    KlassHandle object_klass = SystemDictionary::Object_klass();
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   180
    Method * object_resolved_method = object_klass()->vtable()->method_at(index);
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   181
    assert(object_resolved_method->name() == resolved_method->name(),
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   182
      err_msg("Object and interface method names should match at vtable index %d, %s != %s",
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   183
      index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string()));
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   184
    assert(object_resolved_method->signature() == resolved_method->signature(),
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   185
      err_msg("Object and interface method signatures should match at vtable index %d, %s != %s",
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   186
      index, object_resolved_method->signature()->as_C_string(), resolved_method->signature()->as_C_string()));
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   187
#endif // ASSERT
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   188
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   189
    kind = CallInfo::vtable_call;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   190
  } else {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   191
    // A regular interface call.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   192
    kind = CallInfo::itable_call;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   193
    index = resolved_method->itable_index();
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   194
  }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   195
  assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index));
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   196
  _call_kind  = kind;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   197
  _call_index = index;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   198
  _resolved_appendix = Handle();
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   199
  DEBUG_ONLY(verify());
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   200
}
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   201
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   202
#ifdef ASSERT
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   203
void CallInfo::verify() {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   204
  switch (call_kind()) {  // the meaning and allowed value of index depends on kind
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   205
  case CallInfo::direct_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   206
    if (_call_index == Method::nonvirtual_vtable_index)  break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   207
    // else fall through to check vtable index:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   208
  case CallInfo::vtable_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   209
    assert(resolved_klass()->verify_vtable_index(_call_index), "");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   210
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   211
  case CallInfo::itable_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   212
    assert(resolved_method()->method_holder()->verify_itable_index(_call_index), "");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   213
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   214
  case CallInfo::unknown_kind:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   215
    assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set");
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   216
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   217
  default:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   218
    fatal(err_msg_res("Unexpected call kind %d", call_kind()));
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   219
  }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   220
}
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   221
#endif //ASSERT
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   222
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   223
#ifndef PRODUCT
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   224
void CallInfo::print() {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   225
  ResourceMark rm;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   226
  const char* kindstr = "unknown";
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   227
  switch (_call_kind) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   228
  case direct_call: kindstr = "direct"; break;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   229
  case vtable_call: kindstr = "vtable"; break;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   230
  case itable_call: kindstr = "itable"; break;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   231
  }
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   232
  tty->print_cr("Call %s@%d %s", kindstr, _call_index,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   233
                _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   234
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   235
#endif
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   236
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   237
//------------------------------------------------------------------------------------------------------------------------
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   238
// Implementation of LinkInfo
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   240
LinkInfo::LinkInfo(constantPoolHandle pool, int index, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   241
   // resolve klass
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   242
  Klass* result = pool->klass_ref_at(index, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   243
  _resolved_klass = KlassHandle(THREAD, result);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   244
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   245
  // Get name, signature, and static klass
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   246
  _name          = pool->name_ref_at(index);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   247
  _signature     = pool->signature_ref_at(index);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   248
  _current_klass = KlassHandle(THREAD, pool->pool_holder());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   249
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   250
  // Coming from the constant pool always checks access
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   251
  _check_access  = true;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   252
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   253
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   254
char* LinkInfo::method_string() const {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   255
  return Method::name_and_sig_as_C_string(_resolved_klass(), _name, _signature);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   256
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   257
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   258
#ifndef PRODUCT
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   259
void LinkInfo::print() {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   260
  ResourceMark rm;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   261
  tty->print_cr("Link resolved_klass=%s name=%s signature=%s current_klass=%s check_access=%s",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   262
                _resolved_klass->name()->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   263
                _name->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   264
                _signature->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   265
                _current_klass.is_null() ? "(none)" : _current_klass->name()->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   266
                _check_access ? "true" : "false");
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   267
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   268
#endif // PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
// Klass resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   273
  if (!Reflection::verify_class_access(ref_klass(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   274
                                       sel_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
                                       true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   279
      vmSymbols::java_lang_IllegalAccessError(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      "tried to access class %s from class %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      sel_klass->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      ref_klass->external_name()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
// Method resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
// According to JVM spec. $5.4.3c & $5.4.3d
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   293
// Look up method in klasses, including static methods
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   294
// Then look up local default methods
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   295
methodHandle LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   296
                                                    bool checkpolymorphism,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   297
                                                    bool in_imethod_resolve, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   298
  KlassHandle klass = link_info.resolved_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   299
  Symbol* name = link_info.name();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   300
  Symbol* signature = link_info.signature();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   301
23999
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   302
  // Ignore overpasses so statics can be found during resolution
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   303
  Method* result = klass->uncached_lookup_method(name, signature, Klass::skip_overpass);
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   304
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   305
  if (klass->oop_is_array()) {
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   306
    // Only consider klass and super klass for arrays
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   307
    return methodHandle(THREAD, result);
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   308
  }
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   309
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   310
  // JDK 8, JVMS 5.4.3.4: Interface method resolution should
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   311
  // ignore static and non-public methods of java.lang.Object,
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   312
  // like clone, finalize, registerNatives.
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   313
  if (in_imethod_resolve &&
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   314
      result != NULL &&
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   315
      klass->is_interface() &&
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   316
      (result->is_static() || !result->is_public()) &&
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   317
      result->method_holder() == SystemDictionary::Object_klass()) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   318
    result = NULL;
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   319
  }
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   320
23999
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   321
  // Before considering default methods, check for an overpass in the
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   322
  // current class if a method has not been found.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   323
  if (result == NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   324
    result = InstanceKlass::cast(klass())->find_method(name, signature);
23999
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   325
  }
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   326
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   327
  if (result == NULL) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   328
    Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   329
    if (default_methods != NULL) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   330
      result = InstanceKlass::find_method(default_methods, name, signature);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   331
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   332
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   333
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   334
  if (checkpolymorphism && result != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   335
    vmIntrinsics::ID iid = result->intrinsic_id();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   336
    if (MethodHandles::is_signature_polymorphic(iid)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   337
      // Do not link directly to these.  The VM must produce a synthetic one using lookup_polymorphic_method.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   338
      return NULL;
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4571
diff changeset
   339
    }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4571
diff changeset
   340
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   341
  return methodHandle(THREAD, result);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
// returns first instance method
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   345
// Looks up method in classes, then looks up local default methods
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   346
methodHandle LinkResolver::lookup_instance_method_in_klasses(KlassHandle klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   347
                                                             Symbol* name,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   348
                                                             Symbol* signature, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   349
  Method* result = klass->uncached_lookup_method(name, signature, Klass::find_overpass);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   350
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   351
  while (result != NULL && result->is_static() && result->method_holder()->super() != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   352
    Klass* super_klass = result->method_holder()->super();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   353
    result = super_klass->uncached_lookup_method(name, signature, Klass::find_overpass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   355
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   356
  if (klass->oop_is_array()) {
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   357
    // Only consider klass and super klass for arrays
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   358
    return methodHandle(THREAD, result);
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   359
  }
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   360
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   361
  if (result == NULL) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   362
    Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   363
    if (default_methods != NULL) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   364
      result = InstanceKlass::find_method(default_methods, name, signature);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   365
      assert(result == NULL || !result->is_static(), "static defaults not allowed");
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   366
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   367
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   368
  return methodHandle(THREAD, result);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   371
int LinkResolver::vtable_index_of_interface_method(KlassHandle klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   372
                                                   const methodHandle& resolved_method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   374
  int vtable_index = Method::invalid_vtable_index;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   375
  Symbol* name = resolved_method->name();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   376
  Symbol* signature = resolved_method->signature();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   377
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   378
  // First check in default method array
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   379
  if (!resolved_method->is_abstract() &&
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   380
    (InstanceKlass::cast(klass())->default_methods() != NULL)) {
28731
f7339cba0a6a 8067480: Crash in klassItable::initialize_itable_for_interface when running vm.runtime.defmeth.StaticMethodsTest.
lfoltan
parents: 27020
diff changeset
   381
    int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(),
f7339cba0a6a 8067480: Crash in klassItable::initialize_itable_for_interface when running vm.runtime.defmeth.StaticMethodsTest.
lfoltan
parents: 27020
diff changeset
   382
                                                 name, signature, Klass::find_overpass, Klass::find_static);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   383
    if (index >= 0 ) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   384
      vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   385
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   386
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   387
  if (vtable_index == Method::invalid_vtable_index) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   388
    // get vtable_index for miranda methods
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   389
    ResourceMark rm;
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   390
    klassVtable *vt = InstanceKlass::cast(klass())->vtable();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   391
    vtable_index = vt->index_of_miranda(name, signature);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   392
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   393
  return vtable_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   396
methodHandle LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   397
  InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass()());
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   398
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   399
  // Specify 'true' in order to skip default methods when searching the
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   400
  // interfaces.  Function lookup_method_in_klasses() already looked for
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   401
  // the method in the default methods table.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   402
  return methodHandle(THREAD,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   403
    ik->lookup_method_in_all_interfaces(cp_info.name(), cp_info.signature(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   404
    Klass::skip_defaults));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   407
methodHandle LinkResolver::lookup_polymorphic_method(
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   408
                                             const LinkInfo& link_info,
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   409
                                             Handle *appendix_result_or_null,
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   410
                                             Handle *method_type_result,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   411
                                             TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   412
  KlassHandle klass = link_info.resolved_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   413
  Symbol* name = link_info.name();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   414
  Symbol* full_signature = link_info.signature();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   415
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   416
  vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   417
  if (TraceMethodHandles) {
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   418
    ResourceMark rm(THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   419
    tty->print_cr("lookup_polymorphic_method iid=%s %s.%s%s",
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   420
                  vmIntrinsics::name_at(iid), klass->external_name(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   421
                  name->as_C_string(), full_signature->as_C_string());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   422
  }
24322
c2978d1578e3 8036956: remove EnableInvokeDynamic flag
anoll
parents: 23999
diff changeset
   423
  if (klass() == SystemDictionary::MethodHandle_klass() &&
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   424
      iid != vmIntrinsics::_none) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   425
    if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   426
      // Most of these do not need an up-call to Java to resolve, so can be done anywhere.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   427
      // Do not erase last argument type (MemberName) if it is a static linkTo method.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   428
      bool keep_last_arg = MethodHandles::is_signature_polymorphic_static(iid);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   429
      TempNewSymbol basic_signature =
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   430
        MethodHandles::lookup_basic_type_signature(full_signature, keep_last_arg, CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   431
      if (TraceMethodHandles) {
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   432
        ResourceMark rm(THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   433
        tty->print_cr("lookup_polymorphic_method %s %s => basic %s",
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   434
                      name->as_C_string(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   435
                      full_signature->as_C_string(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   436
                      basic_signature->as_C_string());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   437
      }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   438
      methodHandle result = SystemDictionary::find_method_handle_intrinsic(iid,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   439
                                                              basic_signature,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   440
                                                              CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   441
      if (result.not_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   442
        assert(result->is_method_handle_intrinsic(), "MH.invokeBasic or MH.linkTo* intrinsic");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   443
        assert(result->intrinsic_id() != vmIntrinsics::_invokeGeneric, "wrong place to find this");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   444
        assert(basic_signature == result->signature(), "predict the result signature");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   445
        if (TraceMethodHandles) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   446
          tty->print("lookup_polymorphic_method => intrinsic ");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   447
          result->print_on(tty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   448
        }
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5547
diff changeset
   449
      }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   450
      return result;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   451
    } else if (iid == vmIntrinsics::_invokeGeneric
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   452
               && !THREAD->is_Compiler_thread()
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   453
               && appendix_result_or_null != NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   454
      // This is a method with type-checking semantics.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   455
      // We will ask Java code to spin an adapter method for it.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   456
      if (!MethodHandles::enabled()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   457
        // Make sure the Java part of the runtime has been booted up.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   458
        Klass* natives = SystemDictionary::MethodHandleNatives_klass();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   459
        if (natives == NULL || InstanceKlass::cast(natives)->is_not_initialized()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   460
          SystemDictionary::resolve_or_fail(vmSymbols::java_lang_invoke_MethodHandleNatives(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   461
                                            Handle(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   462
                                            Handle(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   463
                                            true,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   464
                                            CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   465
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   466
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   467
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   468
      Handle appendix;
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   469
      Handle method_type;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   470
      methodHandle result = SystemDictionary::find_method_handle_invoker(
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   471
                                                            name,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   472
                                                            full_signature,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   473
                                                            link_info.current_klass(),
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   474
                                                            &appendix,
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   475
                                                            &method_type,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   476
                                                            CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   477
      if (TraceMethodHandles) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   478
        tty->print("lookup_polymorphic_method => (via Java) ");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   479
        result->print_on(tty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   480
        tty->print("  lookup_polymorphic_method => appendix = ");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   481
        if (appendix.is_null())  tty->print_cr("(none)");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   482
        else                     appendix->print_on(tty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   483
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   484
      if (result.not_null()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   485
#ifdef ASSERT
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   486
        ResourceMark rm(THREAD);
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   487
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   488
        TempNewSymbol basic_signature =
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   489
          MethodHandles::lookup_basic_type_signature(full_signature, CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   490
        int actual_size_of_params = result->size_of_parameters();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   491
        int expected_size_of_params = ArgumentSizeComputer(basic_signature).size();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   492
        // +1 for MethodHandle.this, +1 for trailing MethodType
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   493
        if (!MethodHandles::is_signature_polymorphic_static(iid))  expected_size_of_params += 1;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   494
        if (appendix.not_null())                                   expected_size_of_params += 1;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   495
        if (actual_size_of_params != expected_size_of_params) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   496
          tty->print_cr("*** basic_signature=%s", basic_signature->as_C_string());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   497
          tty->print_cr("*** result for %s: ", vmIntrinsics::name_at(iid));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   498
          result->print();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   499
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   500
        assert(actual_size_of_params == expected_size_of_params,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   501
               err_msg("%d != %d", actual_size_of_params, expected_size_of_params));
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   502
#endif //ASSERT
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   503
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   504
        assert(appendix_result_or_null != NULL, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   505
        (*appendix_result_or_null) = appendix;
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
   506
        (*method_type_result)      = method_type;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   507
      }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   508
      return result;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   509
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   510
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   511
  return NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   512
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   513
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
void LinkResolver::check_method_accessability(KlassHandle ref_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
                                              KlassHandle resolved_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
                                              KlassHandle sel_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   517
                                              const methodHandle& sel_method,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
                                              TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  AccessFlags flags = sel_method->access_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   522
  // Special case:  arrays always override "clone". JVMS 2.15.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  // If the resolved klass is an array class, and the declaring class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  // is java.lang.Object and the method is "clone", set the flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  // to public.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  //
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   527
  // We'll check for the method name first, as that's most likely
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   528
  // to be false (so we'll short-circuit out of these tests).
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   529
  if (sel_method->name() == vmSymbols::clone_name() &&
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   530
      sel_klass() == SystemDictionary::Object_klass() &&
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   531
      resolved_klass->oop_is_array()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    // We need to change "protected" to "public".
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   533
    assert(flags.is_protected(), "clone not protected?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    jint new_flags = flags.as_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    new_flags = new_flags & (~JVM_ACC_PROTECTED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    new_flags = new_flags | JVM_ACC_PUBLIC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    flags.set_flags(new_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   539
//  assert(extra_arg_result_or_null != NULL, "must be able to return extra argument");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   541
  if (!Reflection::verify_field_access(ref_klass(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   542
                                       resolved_klass(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   543
                                       sel_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
                                       flags,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
                                       true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   549
      vmSymbols::java_lang_IllegalAccessError(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      "tried to access method %s.%s%s from class %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
      sel_klass->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      sel_method->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      sel_method->signature()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
      ref_klass->external_name()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   560
methodHandle LinkResolver::resolve_method_statically(Bytecodes::Code code,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   561
                                                     constantPoolHandle pool, int index, TRAPS) {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   562
  // This method is used only
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   563
  // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call),
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   564
  // and
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   565
  // (2) in Bytecode_invoke::static_target
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   566
  // It appears to fail when applied to an invokeinterface call site.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   567
  // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // resolve klass
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   569
  KlassHandle resolved_klass;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   570
  if (code == Bytecodes::_invokedynamic) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   571
    resolved_klass = SystemDictionary::MethodHandle_klass();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   572
    Symbol* method_name = vmSymbols::invoke_name();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   573
    Symbol* method_signature = pool->signature_ref_at(index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   574
    KlassHandle  current_klass(THREAD, pool->pool_holder());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   575
    LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   576
    return resolve_method(link_info, /*require_methodref*/false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   577
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   578
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   579
  LinkInfo link_info(pool, index, CHECK_NULL);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   580
  resolved_klass = link_info.resolved_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   582
  if (pool->has_preresolution()
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   583
      || (resolved_klass() == SystemDictionary::MethodHandle_klass() &&
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   584
          MethodHandles::is_signature_polymorphic_name(resolved_klass(), link_info.name()))) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   585
    Method* result = ConstantPool::method_at_if_loaded(pool, index);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   586
    if (result != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   587
      return methodHandle(THREAD, result);
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   588
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   589
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   590
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   591
  if (code == Bytecodes::_invokeinterface) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   592
    return resolve_interface_method(link_info, true, THREAD);
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   593
  } else if (code == Bytecodes::_invokevirtual) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   594
    return resolve_method(link_info, /*require_methodref*/true, THREAD);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   595
  } else if (!resolved_klass->is_interface()) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   596
    return resolve_method(link_info, /*require_methodref*/false, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   597
  } else {
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   598
    bool nostatics = (code == Bytecodes::_invokestatic) ? false : true;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   599
    return resolve_interface_method(link_info, nostatics, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   600
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   603
// Check and print a loader constraint violation message for method or interface method
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   604
void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   605
                                                   const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   606
                                                   const char* method_type, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   607
  Handle current_loader(THREAD, link_info.current_klass()->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   608
  Handle resolved_loader(THREAD, resolved_method->method_holder()->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   609
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   610
  ResourceMark rm(THREAD);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   611
  Symbol* failed_type_symbol =
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   612
    SystemDictionary::check_signature_loaders(link_info.signature(), current_loader,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   613
                                              resolved_loader, true, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   614
  if (failed_type_symbol != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   615
    const char* msg = "loader constraint violation: when resolving %s"
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   616
      " \"%s\" the class loader (instance of %s) of the current class, %s,"
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   617
      " and the class loader (instance of %s) for the method's defining class, %s, have"
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   618
      " different Class objects for the type %s used in the signature";
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   619
    char* sig = link_info.method_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   620
    const char* loader1_name = SystemDictionary::loader_name(current_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   621
    char* current = link_info.current_klass()->name()->as_C_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   622
    const char* loader2_name = SystemDictionary::loader_name(resolved_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   623
    char* target = resolved_method->method_holder()->name()->as_C_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   624
    char* failed_type_name = failed_type_symbol->as_C_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   625
    size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1_name) +
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   626
      strlen(current) + strlen(loader2_name) + strlen(target) +
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   627
      strlen(failed_type_name) + strlen(method_type) + 1;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   628
    char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   629
    jio_snprintf(buf, buflen, msg, method_type, sig, loader1_name, current, loader2_name,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   630
                 target, failed_type_name);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   631
    THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   632
  }
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   633
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   634
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   635
void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   636
                                                  KlassHandle current_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   637
                                                  KlassHandle sel_klass, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   638
  Handle ref_loader(THREAD, current_klass->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   639
  Handle sel_loader(THREAD, sel_klass->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   640
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   641
  ResourceMark rm(THREAD);  // needed for check_signature_loaders
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   642
  Symbol* failed_type_symbol =
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   643
    SystemDictionary::check_signature_loaders(sig,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   644
                                              ref_loader, sel_loader,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   645
                                              false,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   646
                                              CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   647
  if (failed_type_symbol != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   648
    const char* msg = "loader constraint violation: when resolving field"
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   649
      " \"%s\" the class loader (instance of %s) of the referring class, "
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   650
      "%s, and the class loader (instance of %s) for the field's resolved "
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   651
      "type, %s, have different Class objects for that type";
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   652
    char* field_name = field->as_C_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   653
    const char* loader1_name = SystemDictionary::loader_name(ref_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   654
    char* sel = sel_klass->name()->as_C_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   655
    const char* loader2_name = SystemDictionary::loader_name(sel_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   656
    char* failed_type_name = failed_type_symbol->as_C_string();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   657
    size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1_name) +
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   658
                    strlen(sel) + strlen(loader2_name) + strlen(failed_type_name) + 1;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   659
    char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   660
    jio_snprintf(buf, buflen, msg, field_name, loader1_name, sel, loader2_name,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   661
                     failed_type_name);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   662
    THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   663
  }
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   664
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   665
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   666
methodHandle LinkResolver::resolve_method(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   667
                                          bool require_methodref, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   669
  Handle nested_exception;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   670
  KlassHandle resolved_klass = link_info.resolved_klass();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   671
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   672
  // 1. check if methodref required, that resolved_klass is not interfacemethodref
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   673
  if (require_methodref && resolved_klass->is_interface()) {
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   674
    ResourceMark rm(THREAD);
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   675
    char buf[200];
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   676
    jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected",
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   677
        resolved_klass()->external_name());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   678
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   679
  }
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   680
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   681
  // 2. lookup method in resolved klass and its super klasses
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   682
  methodHandle resolved_method = lookup_method_in_klasses(link_info, true, false, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   684
  if (resolved_method.is_null() && !resolved_klass->oop_is_array()) { // not found in the class hierarchy
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   685
    // 3. lookup method in all the interfaces implemented by the resolved klass
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   686
    resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    if (resolved_method.is_null()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   689
      // JSR 292:  see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   690
      resolved_method = lookup_polymorphic_method(link_info, (Handle*)NULL, (Handle*)NULL, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   691
      if (HAS_PENDING_EXCEPTION) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   692
        nested_exception = Handle(THREAD, PENDING_EXCEPTION);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   693
        CLEAR_PENDING_EXCEPTION;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   694
      }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   695
    }
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   696
  }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   697
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   698
  if (resolved_method.is_null()) {
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   699
    // 4. method lookup failed
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   700
    ResourceMark rm(THREAD);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   701
    THROW_MSG_CAUSE_(vmSymbols::java_lang_NoSuchMethodError(),
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   702
                    Method::name_and_sig_as_C_string(resolved_klass(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   703
                                                     link_info.name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   704
                                                     link_info.signature()),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   705
                    nested_exception, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
22739
74105c330330 8032010: Attempt to resolve abstract method in concrete class fails with AbstractMethodError
ccheung
parents: 22521
diff changeset
   708
  // 5. access checks, access checking may be turned off when calling from within the VM.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   709
  KlassHandle current_klass = link_info.current_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   710
  if (link_info.check_access()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    assert(current_klass.not_null() , "current_klass should not be null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    // check if method can be accessed by the referring class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    check_method_accessability(current_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
                               resolved_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
                               KlassHandle(THREAD, resolved_method->method_holder()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
                               resolved_method,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   718
                               CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    // check loader constraints
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   721
    check_method_loader_constraints(link_info, resolved_method, "method", CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   723
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   724
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   727
methodHandle LinkResolver::resolve_interface_method(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   728
                                                    bool nostatics, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   729
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   730
  KlassHandle resolved_klass = link_info.resolved_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   732
  // check if klass is interface
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  if (!resolved_klass->is_interface()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
   734
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    char buf[200];
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   736
    jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   737
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  // lookup method in this interface or its super, java.lang.Object
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   741
  // JDK8: also look for static methods
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   742
  methodHandle resolved_method = lookup_method_in_klasses(link_info, false, true, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   744
  if (resolved_method.is_null() && !resolved_klass->oop_is_array()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    // lookup method in all the super-interfaces
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   746
    resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL);
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   747
  }
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   748
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   749
  if (resolved_method.is_null()) {
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   750
    // no method found
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   751
    ResourceMark rm(THREAD);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   752
    THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   753
                   Method::name_and_sig_as_C_string(resolved_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   754
                                                    link_info.name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   755
                                                    link_info.signature()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   758
  if (link_info.check_access()) {
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   759
    // JDK8 adds non-public interface methods, and accessability check requirement
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   760
    KlassHandle current_klass = link_info.current_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   761
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   762
    assert(current_klass.not_null() , "current_klass should not be null");
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   763
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   764
    // check if method can be accessed by the referring class
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   765
    check_method_accessability(current_klass,
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   766
                               resolved_klass,
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   767
                               KlassHandle(THREAD, resolved_method->method_holder()),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   768
                               resolved_method,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   769
                               CHECK_NULL);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   770
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   771
    check_method_loader_constraints(link_info, resolved_method, "interface method", CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   773
22521
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   774
  if (nostatics && resolved_method->is_static()) {
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   775
    ResourceMark rm(THREAD);
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   776
    char buf[200];
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   777
    jio_snprintf(buf, sizeof(buf), "Expected instance not static method %s",
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   778
                 Method::name_and_sig_as_C_string(resolved_klass(),
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   779
                 resolved_method->name(), resolved_method->signature()));
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   780
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
22521
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   781
  }
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   782
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   783
  if (TraceItables && Verbose) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   784
    trace_method_resolution("invokeinterface resolved method: caller-class",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   785
                            link_info.current_klass(), resolved_klass, resolved_method);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   786
    tty->cr();
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   787
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   788
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   789
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
// Field resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
void LinkResolver::check_field_accessability(KlassHandle ref_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
                                             KlassHandle resolved_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
                                             KlassHandle sel_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   798
                                             const fieldDescriptor& fd,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
                                             TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   800
  if (!Reflection::verify_field_access(ref_klass(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   801
                                       resolved_klass(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   802
                                       sel_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
                                       fd.access_flags(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
                                       true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   808
      vmSymbols::java_lang_IllegalAccessError(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      "tried to access field %s.%s from class %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
      sel_klass->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      fd.name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
      ref_klass->external_name()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   818
void LinkResolver::resolve_field_access(fieldDescriptor& fd, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   819
  LinkInfo link_info(pool, index, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   820
  resolve_field(fd, link_info, byte, true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   823
void LinkResolver::resolve_field(fieldDescriptor& fd,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   824
                                 const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   825
                                 Bytecodes::Code byte, bool initialize_class,
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   826
                                 TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic ||
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   828
         byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 29081
diff changeset
   829
         byte == Bytecodes::_nofast_getfield  || byte == Bytecodes::_nofast_putfield  ||
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   830
         (byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 29081
diff changeset
   833
  bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  // Check if there's a resolved klass containing the field
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   835
  KlassHandle resolved_klass = link_info.resolved_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   836
  Symbol* field = link_info.name();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   837
  Symbol* sig = link_info.signature();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   838
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   839
  if (resolved_klass.is_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  // Resolve instance field
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   845
  KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  // check if field exists; i.e., if a klass containing the field def has been selected
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   847
  if (sel_klass.is_null()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   852
  if (!link_info.check_access())
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   853
    // Access checking may be turned off when calling from within the VM.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   854
    return;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   855
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  // check access
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   857
  KlassHandle current_klass = link_info.current_klass();
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   858
  check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  // check for errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  if (is_static != fd.is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
   862
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    char msg[200];
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   864
    jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // Final fields can only be accessed from its own class.
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   869
  if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    THROW(vmSymbols::java_lang_IllegalAccessError());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  // initialize resolved_klass if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  // note 1: the klass which declared the field must be initialized (i.e, sel_klass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  //         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  // note 2: we don't want to force initialization if we are just checking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  //         if the field access is legal; e.g., during compilation
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   879
  if (is_static && initialize_class) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    sel_klass->initialize(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   883
  if (sel_klass() != current_klass()) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   884
    check_field_loader_constraints(field, sig, current_klass, sel_klass, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  // return information. note that the klass is set to the actual klass containing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  // field, otherwise access of static fields in superclasses will not work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
// Invoke resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
// Naming conventions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
// resolved_method    the specified method (i.e., static receiver specified via constant pool index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
// sel_method         the selected method  (selected via run-time lookup; e.g., based on dynamic receiver class)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
// resolved_klass     the specified klass  (i.e., specified via constant pool index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
// recv_klass         the receiver klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   903
void LinkResolver::resolve_static_call(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   904
                                       const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   905
                                       bool initialize_class, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   906
  methodHandle resolved_method = linktime_resolve_static_method(link_info, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   908
  // The resolved class can change as a result of this resolution.
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   909
  KlassHandle resolved_klass = KlassHandle(THREAD, resolved_method->method_holder());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   910
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   911
  Method* save_resolved_method = resolved_method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  // Initialize klass (this should only happen if everything is ok)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  if (initialize_class && resolved_klass->should_be_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
    resolved_klass->initialize(CHECK);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   915
    // Use updated LinkInfo (to reresolve with resolved_klass as method_holder?)
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   916
    LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   917
                      link_info.current_klass(), link_info.check_access());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   918
    resolved_method = linktime_resolve_static_method(new_info, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   921
  assert(save_resolved_method == resolved_method(), "does this change?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  // setup result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  result.set_static(resolved_klass, resolved_method, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
// throws linktime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   927
methodHandle LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   929
  KlassHandle resolved_klass = link_info.resolved_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   930
  methodHandle resolved_method;
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   931
  if (!resolved_klass->is_interface()) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   932
    resolved_method = resolve_method(link_info, /*require_methodref*/false, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   933
  } else {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   934
    resolved_method = resolve_interface_method(link_info, /*nostatics*/false, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   935
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  // check if static
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  if (!resolved_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
   940
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    char buf[200];
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
   942
    jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
                                                      resolved_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
                                                      resolved_method->signature()));
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   945
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   947
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   951
void LinkResolver::resolve_special_call(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   952
                                        const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   953
                                        TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   954
  methodHandle resolved_method = linktime_resolve_special_method(link_info, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   955
  runtime_resolve_special_method(result, resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   956
                                 link_info.resolved_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   957
                                 link_info.current_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   958
                                 link_info.check_access(), CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
// throws linktime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   962
methodHandle LinkResolver::linktime_resolve_special_method(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   963
                                                           TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   965
  // Invokespecial is called for multiple special reasons:
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   966
  // <init>
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   967
  // local private method invocation, for classes and interfaces
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   968
  // superclass.method, which can also resolve to a default method
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   969
  // and the selected method is recalculated relative to the direct superclass
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   970
  // superinterface.method, which explicitly does not check shadowing
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   971
  KlassHandle resolved_klass = link_info.resolved_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   972
  methodHandle resolved_method;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13929
diff changeset
   973
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   974
  if (!resolved_klass->is_interface()) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   975
    resolved_method = resolve_method(link_info, /*require_methodref*/false, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   976
  } else {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   977
    resolved_method = resolve_interface_method(link_info, /*nostatics*/true, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   978
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  // check if method name is <init>, that it is found in same klass as static type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  if (resolved_method->name() == vmSymbols::object_initializer_name() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
      resolved_method->method_holder() != resolved_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   986
      vmSymbols::java_lang_NoSuchMethodError(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      "%s: method %s%s not found",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      resolved_klass->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
      resolved_method->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      resolved_method->signature()->as_C_string()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    );
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   992
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
   995
  // check if invokespecial's interface method reference is in an indirect superinterface
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   996
  KlassHandle current_klass = link_info.current_klass();
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
   997
  if (!current_klass.is_null() && resolved_klass->is_interface()) {
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
   998
    Klass *klass_to_check = !InstanceKlass::cast(current_klass())->is_anonymous() ?
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
   999
                                  current_klass() :
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1000
                                  InstanceKlass::cast(current_klass())->host_klass();
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24456
diff changeset
  1001
    // Disable verification for the dynamically-generated reflection bytecodes.
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24456
diff changeset
  1002
    bool is_reflect = klass_to_check->is_subclass_of(
22218
71cff6a30ec1 8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents: 21913
diff changeset
  1003
                        SystemDictionary::reflect_MagicAccessorImpl_klass());
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1004
22218
71cff6a30ec1 8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents: 21913
diff changeset
  1005
    if (!is_reflect &&
71cff6a30ec1 8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents: 21913
diff changeset
  1006
        !InstanceKlass::cast(klass_to_check)->is_same_or_direct_interface(resolved_klass())) {
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1007
      ResourceMark rm(THREAD);
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1008
      char buf[200];
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1009
      jio_snprintf(buf, sizeof(buf),
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1010
                   "Interface method reference: %s, is in an indirect superinterface of %s",
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1011
                   Method::name_and_sig_as_C_string(resolved_klass(),
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1012
                                                         resolved_method->name(),
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1013
                                                         resolved_method->signature()),
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1014
                   current_klass->external_name());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1015
      THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1016
    }
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1017
  }
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1018
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  // check if not static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  if (resolved_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1021
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
    char buf[200];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
    jio_snprintf(buf, sizeof(buf),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
                 "Expecting non-static method %s",
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1025
                 Method::name_and_sig_as_C_string(resolved_klass(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1026
                                                  resolved_method->name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1027
                                                  resolved_method->signature()));
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1028
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1030
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1031
  if (TraceItables && Verbose) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1032
    trace_method_resolution("invokespecial resolved method: caller-class:",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1033
                            current_klass, resolved_klass, resolved_method);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1034
    tty->cr();
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1035
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1036
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1037
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
// throws runtime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1041
void LinkResolver::runtime_resolve_special_method(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1042
                                                  const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1043
                                                  KlassHandle resolved_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1044
                                                  KlassHandle current_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1045
                                                  bool check_access, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  // resolved method is selected method unless we have an old-style lookup
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1048
  // for a superclass method
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1049
  // Invokespecial for a superinterface, resolved method is selected method,
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1050
  // no checks for shadowing
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  methodHandle sel_method(THREAD, resolved_method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  // check if this is an old-style super call and do a new lookup if so
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  { KlassHandle method_klass  = KlassHandle(THREAD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
                                            resolved_method->method_holder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1057
    if (check_access &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
        // a) check if ACC_SUPER flag is set for the current class
15918
3fcc894aca8c 8001307: Modify ACC_SUPER behavior
kamg
parents: 13929
diff changeset
  1059
        (current_klass->is_super() || !AllowNonVirtualCalls) &&
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1060
        // b) check if the class of the resolved_klass is a superclass
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1061
        // (not supertype in order to exclude interface classes) of the current class.
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1062
        // This check is not performed for super.invoke for interface methods
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1063
        // in super interfaces.
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1064
        current_klass->is_subclass_of(resolved_klass()) &&
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1065
        current_klass() != resolved_klass() &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
        // c) check if the method is not <init>
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
        resolved_method->name() != vmSymbols::object_initializer_name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
      // Lookup super method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      KlassHandle super_klass(THREAD, current_klass->super());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1070
      sel_method = lookup_instance_method_in_klasses(super_klass,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
  1071
                           resolved_method->name(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
  1072
                           resolved_method->signature(), CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
      // check if found
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
      if (sel_method.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
        ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
        THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1077
                  Method::name_and_sig_as_C_string(resolved_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
                                            resolved_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
                                            resolved_method->signature()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  // check if not static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  if (sel_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1086
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
    char buf[200];
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1088
    jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
                                                                                                             resolved_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
                                                                                                             resolved_method->signature()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  // check if abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  if (sel_method->is_abstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1098
              Method::name_and_sig_as_C_string(resolved_klass(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1099
                                               sel_method->name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1100
                                               sel_method->signature()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1103
  if (TraceItables && Verbose) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1104
    trace_method_resolution("invokespecial selected method: resolved-class:",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1105
                            resolved_klass, resolved_klass, sel_method);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1106
    tty->cr();
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1107
  }
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1108
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  // setup result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  result.set_static(resolved_klass, sel_method, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1113
void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1114
                                        const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1115
                                        bool check_null_and_abstract, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1116
  methodHandle resolved_method = linktime_resolve_virtual_method(link_info, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1117
  runtime_resolve_virtual_method(result, resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1118
                                 link_info.resolved_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1119
                                 recv, receiver_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1120
                                 check_null_and_abstract, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
// throws linktime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1124
methodHandle LinkResolver::linktime_resolve_virtual_method(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1125
                                                           TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  // normal method resolution
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1127
  methodHandle resolved_method = resolve_method(link_info, /*require_methodref*/true, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1132
  // check if private interface method
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1133
  KlassHandle resolved_klass = link_info.resolved_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1134
  KlassHandle current_klass = link_info.current_klass();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1135
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1136
  if (resolved_klass->is_interface() && resolved_method->is_private()) {
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1137
    ResourceMark rm(THREAD);
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1138
    char buf[200];
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1139
    jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s",
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1140
                 Method::name_and_sig_as_C_string(resolved_klass(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1141
                                                  resolved_method->name(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1142
                                                  resolved_method->signature()),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1143
                   (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()));
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1144
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1145
  }
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1146
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  // check if not static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  if (resolved_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1149
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    char buf[200];
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1151
    jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
                                                                                                             resolved_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
                                                                                                             resolved_method->signature()));
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1154
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
  }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1156
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1157
  if (PrintVtables && Verbose) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1158
    trace_method_resolution("invokevirtual resolved method: caller-class:",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1159
                            current_klass, resolved_klass, resolved_method);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1160
    tty->cr();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1161
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1162
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1163
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
// throws runtime exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1168
                                                  const methodHandle& resolved_method,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
                                                  KlassHandle resolved_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
                                                  Handle recv,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
                                                  KlassHandle recv_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
                                                  bool check_null_and_abstract,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
                                                  TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
  // setup default return values
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1176
  int vtable_index = Method::invalid_vtable_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  methodHandle selected_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  assert(recv.is_null() || recv->is_oop(), "receiver is not an oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  // runtime method resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1186
  // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  // a missing receiver might result in a bogus lookup.
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 14385
diff changeset
  1189
  assert(resolved_method->method_holder()->is_linked(), "must be linked");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  // do lookup based on receiver klass using the vtable index
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1192
  if (resolved_method->method_holder()->is_interface()) { // miranda method
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1193
    vtable_index = vtable_index_of_interface_method(resolved_klass,
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1194
                           resolved_method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
    assert(vtable_index >= 0 , "we should have valid vtable index at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1197
    InstanceKlass* inst = InstanceKlass::cast(recv_klass());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    // at this point we are sure that resolved_method is virtual and not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    // a miranda method; therefore, it must have a valid vtable index.
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1202
    assert(!resolved_method->has_itable_index(), "");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
    vtable_index = resolved_method->vtable_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    // We could get a negative vtable_index for final methods,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    // because as an optimization they are they are never put in the vtable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    // unless they override an existing method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
    // If we do get a negative, it means the resolved method is the the selected
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    // method, and it can never be changed by an override.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1209
    if (vtable_index == Method::nonvirtual_vtable_index) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
      assert(resolved_method->can_be_statically_bound(), "cannot override this method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
      selected_method = resolved_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
      // recv_klass might be an arrayKlassOop but all vtables start at
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
      // the same place. The cast is to avoid virtual call and assertion.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1215
      InstanceKlass* inst = (InstanceKlass*)recv_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
      selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
  // check if method exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
  if (selected_method.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1224
              Method::name_and_sig_as_C_string(resolved_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
                                                      resolved_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
                                                      resolved_method->signature()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  // check if abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  if (check_null_and_abstract && selected_method->is_abstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1233
              Method::name_and_sig_as_C_string(resolved_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
                                                      selected_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
                                                      selected_method->signature()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1238
  if (PrintVtables && Verbose) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1239
    trace_method_resolution("invokevirtual selected method: receiver-class:",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1240
                            recv_klass, resolved_klass, selected_method);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1241
    tty->print_cr("vtable_index:%d", vtable_index);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1242
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  // setup result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
  result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1247
void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1248
                                          const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1249
                                          bool check_null_and_abstract, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1250
  // throws linktime exceptions
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1251
  methodHandle resolved_method = linktime_resolve_interface_method(link_info, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1252
  runtime_resolve_interface_method(result, resolved_method,link_info.resolved_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1253
                                   recv, recv_klass, check_null_and_abstract, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1256
methodHandle LinkResolver::linktime_resolve_interface_method(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1257
                                                             TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  // normal interface method resolution
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1259
  methodHandle resolved_method = resolve_interface_method(link_info, true, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1262
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1263
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
// throws runtime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1267
void LinkResolver::runtime_resolve_interface_method(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1268
                                                    const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1269
                                                    KlassHandle resolved_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1270
                                                    Handle recv,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1271
                                                    KlassHandle recv_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1272
                                                    bool check_null_and_abstract, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  // check if receiver exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
  if (check_null_and_abstract && recv.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1278
  // check if private interface method
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1279
  if (resolved_klass->is_interface() && resolved_method->is_private()) {
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1280
    ResourceMark rm(THREAD);
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1281
    char buf[200];
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1282
    jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s",
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1283
                 Method::name_and_sig_as_C_string(resolved_klass(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1284
                                                  resolved_method->name(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1285
                                                  resolved_method->signature()));
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1286
    THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1287
  }
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1288
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
  // check if receiver klass implements the resolved interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  if (!recv_klass->is_subtype_of(resolved_klass())) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1291
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    char buf[200];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
    jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1294
                 recv_klass()->external_name(),
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1295
                 resolved_klass()->external_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
    THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  }
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
  1298
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  // do lookup based on receiver klass
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
  1300
  // This search must match the linktime preparation search for itable initialization
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
  1301
  // to correctly enforce loader constraints for interface method inheritance
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1302
  methodHandle sel_method = lookup_instance_method_in_klasses(recv_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1303
                                                  resolved_method->name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1304
                                                  resolved_method->signature(), CHECK);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1305
  if (sel_method.is_null() && !check_null_and_abstract) {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1306
    // In theory this is a harmless placeholder value, but
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1307
    // in practice leaving in null affects the nsk default method tests.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1308
    // This needs further study.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1309
    sel_method = resolved_method;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1310
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  // check if method exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  if (sel_method.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1315
                   Method::name_and_sig_as_C_string(recv_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1316
                                                    resolved_method->name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1317
                                                    resolved_method->signature()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
  }
17024
49cbeca23983 8006267: InterfaceMethod_ref should allow invokestatic and invokespecial
bharadwaj
parents: 16691
diff changeset
  1319
  // check access
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1320
  // Throw Illegal Access Error if sel_method is not public.
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1321
  if (!sel_method->is_public()) {
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1322
    ResourceMark rm(THREAD);
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1323
    THROW_MSG(vmSymbols::java_lang_IllegalAccessError(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1324
              Method::name_and_sig_as_C_string(recv_klass(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1325
                                               sel_method->name(),
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1326
                                               sel_method->signature()));
17024
49cbeca23983 8006267: InterfaceMethod_ref should allow invokestatic and invokespecial
bharadwaj
parents: 16691
diff changeset
  1327
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  // check if abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
  if (check_null_and_abstract && sel_method->is_abstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
    THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14391
diff changeset
  1332
              Method::name_and_sig_as_C_string(recv_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
                                                      sel_method->name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
                                                      sel_method->signature()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1336
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1337
  if (TraceItables && Verbose) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1338
    trace_method_resolution("invokeinterface selected method: receiver-class",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1339
                            recv_klass, resolved_klass, sel_method);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1340
    tty->cr();
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1341
  }
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1342
  // setup result
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1343
  if (!resolved_method->has_itable_index()) {
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1344
    int vtable_index = resolved_method->vtable_index();
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1345
    assert(vtable_index == sel_method->vtable_index(), "sanity check");
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1346
    result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK);
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1347
  } else {
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1348
    int itable_index = resolved_method()->itable_index();
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1349
    result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK);
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1350
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
methodHandle LinkResolver::linktime_resolve_interface_method_or_null(
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1355
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  EXCEPTION_MARK;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1357
  methodHandle method_result = linktime_resolve_interface_method(link_info, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
    return methodHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
    return method_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
methodHandle LinkResolver::linktime_resolve_virtual_method_or_null(
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1367
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  EXCEPTION_MARK;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1369
  methodHandle method_result = linktime_resolve_virtual_method(link_info, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
    return methodHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
    return method_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
methodHandle LinkResolver::resolve_virtual_call_or_null(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
                                                 KlassHandle receiver_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1380
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1383
  resolve_virtual_call(info, Handle(), receiver_klass, link_info, false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    return methodHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
methodHandle LinkResolver::resolve_interface_call_or_null(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
                                                 KlassHandle receiver_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1393
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1396
  resolve_interface_call(info, Handle(), receiver_klass, link_info, false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
    return methodHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1404
int LinkResolver::resolve_virtual_vtable_index(KlassHandle receiver_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1405
                                               const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1408
  resolve_virtual_call(info, Handle(), receiver_klass, link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1409
                       /*check_null_or_abstract*/false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
    CLEAR_PENDING_EXCEPTION;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1412
    return Method::invalid_vtable_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  return info.vtable_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1417
methodHandle LinkResolver::resolve_static_call_or_null(const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1420
  resolve_static_call(info, link_info, /*initialize_class*/false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
    return methodHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1428
methodHandle LinkResolver::resolve_special_call_or_null(const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1431
  resolve_special_call(info, link_info, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
    CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
    return methodHandle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
// ConstantPool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
  switch (byte) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
    case Bytecodes::_invokestatic   : resolve_invokestatic   (result,       pool, index, CHECK); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
    case Bytecodes::_invokespecial  : resolve_invokespecial  (result,       pool, index, CHECK); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    case Bytecodes::_invokevirtual  : resolve_invokevirtual  (result, recv, pool, index, CHECK); break;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1449
    case Bytecodes::_invokehandle   : resolve_invokehandle   (result,       pool, index, CHECK); break;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1450
    case Bytecodes::_invokedynamic  : resolve_invokedynamic  (result,       pool, index, CHECK); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
    case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
void LinkResolver::resolve_invokestatic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1457
  LinkInfo link_info(pool, index, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1458
  resolve_static_call(result, link_info, /*initialize_class*/true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
void LinkResolver::resolve_invokespecial(CallInfo& result, constantPoolHandle pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1463
  LinkInfo link_info(pool, index, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1464
  resolve_special_call(result, link_info, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
                                          constantPoolHandle pool, int index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
                                          TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1472
  LinkInfo link_info(pool, index, CHECK);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1473
  KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1474
  resolve_virtual_call(result, recv, recvrKlass, link_info, /*check_null_or_abstract*/true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1479
  LinkInfo link_info(pool, index, CHECK);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1480
  KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1481
  resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1484
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1485
void LinkResolver::resolve_invokehandle(CallInfo& result, constantPoolHandle pool, int index, TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1486
  // This guy is reached from InterpreterRuntime::resolve_invokehandle.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1487
  LinkInfo link_info(pool, index, CHECK);
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
  1488
  if (TraceMethodHandles) {
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
  1489
    ResourceMark rm(THREAD);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1490
    tty->print_cr("resolve_invokehandle %s %s", link_info.name()->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1491
                  link_info.signature()->as_C_string());
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
  1492
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1493
  resolve_handle_call(result, link_info, CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1494
}
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1495
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1496
void LinkResolver::resolve_handle_call(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1497
                                       const LinkInfo& link_info,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1498
                                       TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1499
  // JSR 292:  this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1500
  assert(link_info.resolved_klass()() == SystemDictionary::MethodHandle_klass(), "");
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1501
  assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1502
  Handle       resolved_appendix;
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1503
  Handle       resolved_method_type;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1504
  methodHandle resolved_method = lookup_polymorphic_method(link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1505
                                       &resolved_appendix, &resolved_method_type, CHECK);
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1506
  result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1507
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1508
30746
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1509
static void wrap_invokedynamic_exception(TRAPS) {
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1510
  if (HAS_PENDING_EXCEPTION) {
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1511
    if (TraceMethodHandles) {
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1512
      tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION));
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1513
      PENDING_EXCEPTION->print();
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1514
    }
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1515
    if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) {
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1516
      // throw these guys, since they are already wrapped
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1517
      return;
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1518
    }
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1519
    if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1520
      // intercept only LinkageErrors which might have failed to wrap
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1521
      return;
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1522
    }
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1523
    // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS.
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1524
    Handle nested_exception(THREAD, PENDING_EXCEPTION);
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1525
    CLEAR_PENDING_EXCEPTION;
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1526
    THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception)
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1527
  }
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1528
}
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1529
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1530
void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1531
  Symbol* method_name       = pool->name_ref_at(index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1532
  Symbol* method_signature  = pool->signature_ref_at(index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1533
  KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder());
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1534
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1535
  // Resolve the bootstrap specifier (BSM + optional arguments).
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1536
  Handle bootstrap_specifier;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1537
  // Check if CallSite has been bound already:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1538
  ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1539
  if (cpce->is_f1_null()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1540
    int pool_index = cpce->constant_pool_index();
30746
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1541
    oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD);
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1542
    wrap_invokedynamic_exception(CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1543
    assert(bsm_info != NULL, "");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1544
    // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1545
    bootstrap_specifier = Handle(THREAD, bsm_info);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1546
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1547
  if (!cpce->is_f1_null()) {
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1548
    methodHandle method(     THREAD, cpce->f1_as_method());
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1549
    Handle       appendix(   THREAD, cpce->appendix_if_resolved(pool));
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1550
    Handle       method_type(THREAD, cpce->method_type_if_resolved(pool));
30746
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1551
    result.set_handle(method, appendix, method_type, THREAD);
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1552
    wrap_invokedynamic_exception(CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1553
    return;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1554
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1555
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1556
  if (TraceMethodHandles) {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1557
      ResourceMark rm(THREAD);
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1558
      tty->print_cr("resolve_invokedynamic #%d %s %s",
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1559
                  ConstantPool::decode_invokedynamic_index(index),
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1560
                  method_name->as_C_string(), method_signature->as_C_string());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1561
    tty->print("  BSM info: "); bootstrap_specifier->print();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1562
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1563
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1564
  resolve_dynamic_call(result, bootstrap_specifier, method_name, method_signature, current_klass, CHECK);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1565
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1566
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1567
void LinkResolver::resolve_dynamic_call(CallInfo& result,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1568
                                        Handle bootstrap_specifier,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1569
                                        Symbol* method_name, Symbol* method_signature,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1570
                                        KlassHandle current_klass,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1571
                                        TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1572
  // JSR 292:  this must resolve to an implicitly generated method MH.linkToCallSite(*...)
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1573
  // The appendix argument is likely to be a freshly-created CallSite.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1574
  Handle       resolved_appendix;
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1575
  Handle       resolved_method_type;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1576
  methodHandle resolved_method =
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1577
    SystemDictionary::find_dynamic_call_site_invoker(current_klass,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1578
                                                     bootstrap_specifier,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1579
                                                     method_name, method_signature,
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1580
                                                     &resolved_appendix,
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1581
                                                     &resolved_method_type,
13732
a9865f5514fc 7196120: NPG: JSR 2292 test fails because missing fix for 7188911
twisti
parents: 13728
diff changeset
  1582
                                                     THREAD);
30746
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1583
  wrap_invokedynamic_exception(CHECK);
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1584
  result.set_handle(resolved_method, resolved_appendix, resolved_method_type, THREAD);
dfce1db72058 8051045: HotSpot fails to wrap Exceptions from invokedynamic in a BootstrapMethodError
aeriksso
parents: 30227
diff changeset
  1585
  wrap_invokedynamic_exception(CHECK);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1586
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1587
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
#ifndef PRODUCT
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1589
void LinkResolver::trace_method_resolution(const char* prefix,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1590
                                           KlassHandle klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1591
                                           KlassHandle resolved_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1592
                                           const methodHandle& method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  ResourceMark rm;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1594
  tty->print("%s%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1595
             prefix,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1596
             (klass.is_null() ? "<NULL>" : klass->internal_name()),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1597
             (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1598
             Method::name_and_sig_as_C_string(resolved_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1599
                                              method->name(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1600
                                              method->signature()),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1601
             method->method_holder()->internal_name()
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1602
             );
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1603
  method->access_flags().print_on(tty);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1604
  if (method->is_default_method()) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1605
    tty->print("default ");
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
  1606
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1607
  if (method->is_overpass()) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1608
    tty->print("overpass ");
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1609
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
}
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1611
#endif // PRODUCT