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