src/hotspot/share/interpreter/linkResolver.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58545 725244418646
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53437
fd0e3299326d 8217512: Message of LinkageError: use 'class' etc. instead of 'type'
goetz
parents: 52823
diff changeset
     2
 * Copyright (c) 1997, 2019, 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"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47684
diff changeset
    26
#include "jvm.h"
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13929
diff changeset
    27
#include "classfile/defaultMethods.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
    28
#include "classfile/javaClasses.hpp"
47684
c3c04b6e14f8 8174954: Parameter target type is allowed access after a module read edge or a package export has occurred after failed resolution
hseigel
parents: 47216
diff changeset
    29
#include "classfile/resolutionErrors.hpp"
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 34238
diff changeset
    30
#include "classfile/symbolTable.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    31
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
#include "classfile/vmSymbols.hpp"
58545
725244418646 8165056: move JIT Compiler related files from runtime/ to compiler/ directory
xliu
parents: 54786
diff changeset
    33
#include "compiler/compilationPolicy.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    34
#include "compiler/compileBroker.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30227
diff changeset
    35
#include "gc/shared/collectedHeap.inline.hpp"
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
    36
#include "interpreter/bootstrapInfo.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    37
#include "interpreter/bytecode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    38
#include "interpreter/interpreterRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    39
#include "interpreter/linkResolver.hpp"
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
    40
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
    41
#include "logging/logStream.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    42
#include "memory/resourceArea.hpp"
53838
c8c9bd65c198 8219229: Make ConstantPool::tag_at and release_tag_at_put inlineable
redestad
parents: 53746
diff changeset
    43
#include "oops/constantPool.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 48826
diff changeset
    44
#include "oops/cpCache.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    45
#include "oops/instanceKlass.hpp"
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
    46
#include "oops/method.hpp"
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
    47
#include "oops/objArrayKlass.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    48
#include "oops/objArrayOop.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28738
diff changeset
    49
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    50
#include "prims/methodHandles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    51
#include "prims/nativeLookup.hpp"
51467
12997ebbc0d8 8209647: constantPoolHandle::constantPoolHandle(ConstantPool*) when precompiled header is disabled
iklam
parents: 51444
diff changeset
    52
#include "runtime/fieldDescriptor.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    53
#include "runtime/frame.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    54
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    55
#include "runtime/reflection.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49449
diff changeset
    56
#include "runtime/safepointVerifiers.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    57
#include "runtime/signature.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 14488
diff changeset
    58
#include "runtime/thread.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    59
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// Implementation of CallInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
    65
void CallInfo::set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
    66
  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
    67
  set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
    71
void CallInfo::set_interface(Klass* resolved_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
    72
                             Klass* selected_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    73
                             const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    74
                             const methodHandle& selected_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    75
                             int itable_index, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // This is only called for interface methods. If the resolved_method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // comes from java/lang/Object, it can be the subject of a virtual call, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // 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
    79
  // 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
    80
  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
    81
  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
    82
  set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
    85
void CallInfo::set_virtual(Klass* resolved_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
    86
                           Klass* selected_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    87
                           const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    88
                           const methodHandle& selected_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    89
                           int vtable_index, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
    90
  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
    91
  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
    92
  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
    93
  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
    94
  assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
    97
void CallInfo::set_handle(const methodHandle& resolved_method,
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 53437
diff changeset
    98
                          Handle resolved_appendix, TRAPS) {
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 53437
diff changeset
    99
  set_handle(SystemDictionary::MethodHandle_klass(), resolved_method, resolved_appendix, CHECK);
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35913
diff changeset
   100
}
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35913
diff changeset
   101
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   102
void CallInfo::set_handle(Klass* resolved_klass,
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35913
diff changeset
   103
                          const methodHandle& resolved_method,
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 53437
diff changeset
   104
                          Handle resolved_appendix, TRAPS) {
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 53437
diff changeset
   105
  guarantee(resolved_method.not_null(), "resolved method is null");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   106
  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
   107
         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
   108
         "linkMethod must return one of these");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   109
  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
   110
  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
   111
  set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK);
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 53437
diff changeset
   112
  _resolved_appendix = resolved_appendix;
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5547
diff changeset
   113
}
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5547
diff changeset
   114
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   115
void CallInfo::set_common(Klass* resolved_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   116
                          Klass* selected_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   117
                          const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   118
                          const methodHandle& selected_method,
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   119
                          CallKind kind,
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   120
                          int index,
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   121
                          TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  _resolved_klass  = resolved_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  _selected_klass  = selected_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  _resolved_method = resolved_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  _selected_method = selected_method;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   127
  _call_kind       = kind;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   128
  _call_index      = index;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   129
  _resolved_appendix = Handle();
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   130
  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
   131
38139
cf6f5c1b7205 8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents: 38034
diff changeset
   132
  CompilationPolicy::compile_if_required(selected_method, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   135
// utility query for unreflecting a method
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   136
CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass, TRAPS) {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   137
  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
   138
  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
   139
    resolved_klass = resolved_method_holder;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   140
  }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   141
  _resolved_klass  = resolved_klass;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   142
  _selected_klass  = resolved_klass;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   143
  _resolved_method = methodHandle(THREAD, resolved_method);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   144
  _selected_method = methodHandle(THREAD, resolved_method);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   145
  // classify:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   146
  CallKind kind = CallInfo::unknown_kind;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   147
  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
   148
  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
   149
    kind = CallInfo::direct_call;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   150
  } 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
   151
    // 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
   152
    kind = CallInfo::vtable_call;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   153
  } else if (!resolved_klass->is_interface()) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   154
    // A default or miranda method.  Compute the vtable index.
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   155
    index = LinkResolver::vtable_index_of_interface_method(resolved_klass,
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   156
                           _resolved_method);
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
   157
    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
   158
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   159
    kind = CallInfo::vtable_call;
20712
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   160
  } else if (resolved_method->has_vtable_index()) {
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   161
    // 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
   162
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   163
#ifdef ASSERT
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   164
    // Ensure that this is really the case.
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   165
    Klass* object_klass = SystemDictionary::Object_klass();
46408
70aab0c2ea8b 8178350: klassVtable and klassItable should be ValueObj
iklam
parents: 46329
diff changeset
   166
    Method * object_resolved_method = object_klass->vtable().method_at(index);
20712
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   167
    assert(object_resolved_method->name() == resolved_method->name(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   168
      "Object and interface method names should match at vtable index %d, %s != %s",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   169
      index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string());
20712
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   170
    assert(object_resolved_method->signature() == resolved_method->signature(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   171
      "Object and interface method signatures should match at vtable index %d, %s != %s",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   172
      index, object_resolved_method->signature()->as_C_string(), resolved_method->signature()->as_C_string());
20712
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   173
#endif // ASSERT
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   174
a06e1f01fb6e 8026124: JSR-292 bug: java.nio.file.Path.toString cores dump
drchase
parents: 20391
diff changeset
   175
    kind = CallInfo::vtable_call;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   176
  } else {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   177
    // A regular interface call.
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   178
    kind = CallInfo::itable_call;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   179
    index = resolved_method->itable_index();
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   180
  }
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   181
  assert(index == Method::nonvirtual_vtable_index || index >= 0, "bad index %d", index);
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   182
  _call_kind  = kind;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   183
  _call_index = index;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   184
  _resolved_appendix = Handle();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   185
  // Find or create a ResolvedMethod instance for this Method*
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   186
  set_resolved_method_name(CHECK);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   187
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   188
  DEBUG_ONLY(verify());
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   189
}
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   190
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   191
void CallInfo::set_resolved_method_name(TRAPS) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   192
  assert(_resolved_method() != NULL, "Should already have a Method*");
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   193
  oop rmethod_name = java_lang_invoke_ResolvedMethodName::find_resolved_method(_resolved_method, CHECK);
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   194
  _resolved_method_name = Handle(THREAD, rmethod_name);
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   195
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46458
diff changeset
   196
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   197
#ifdef ASSERT
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   198
void CallInfo::verify() {
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   199
  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
   200
  case CallInfo::direct_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   201
    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
   202
    // 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
   203
  case CallInfo::vtable_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   204
    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
   205
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   206
  case CallInfo::itable_call:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   207
    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
   208
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   209
  case CallInfo::unknown_kind:
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   210
    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
   211
    break;
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   212
  default:
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   213
    fatal("Unexpected call kind %d", call_kind());
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   214
  }
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   215
}
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   216
#endif // ASSERT
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   217
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   218
#ifndef PRODUCT
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   219
void CallInfo::print() {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   220
  ResourceMark rm;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
   221
  const char* kindstr;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   222
  switch (_call_kind) {
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
   223
  case direct_call: kindstr = "direct";  break;
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
   224
  case vtable_call: kindstr = "vtable";  break;
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
   225
  case itable_call: kindstr = "itable";  break;
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
   226
  default         : kindstr = "unknown"; break;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   227
  }
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   228
  tty->print_cr("Call %s@%d %s", kindstr, _call_index,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   229
                _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   230
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   231
#endif
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   232
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   233
//------------------------------------------------------------------------------------------------------------------------
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   234
// Implementation of LinkInfo
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   236
LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, const methodHandle& current_method, TRAPS) {
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   237
   // resolve klass
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   238
  _resolved_klass = pool->klass_ref_at(index, CHECK);
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   239
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   240
  // Get name, signature, and static klass
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   241
  _name          = pool->name_ref_at(index);
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   242
  _signature     = pool->signature_ref_at(index);
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   243
  _tag           = pool->tag_ref_at(index);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   244
  _current_klass = pool->pool_holder();
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   245
  _current_method = current_method;
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   246
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   247
  // Coming from the constant pool always checks access
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   248
  _check_access  = true;
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   249
}
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   250
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33198
diff changeset
   251
LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   252
   // resolve klass
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   253
  _resolved_klass = pool->klass_ref_at(index, CHECK);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   254
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   255
  // Get name, signature, and static klass
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   256
  _name          = pool->name_ref_at(index);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   257
  _signature     = pool->signature_ref_at(index);
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   258
  _tag           = pool->tag_ref_at(index);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   259
  _current_klass = pool->pool_holder();
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   260
  _current_method = methodHandle();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   261
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   262
  // Coming from the constant pool always checks access
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   263
  _check_access  = true;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   264
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   265
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   266
#ifndef PRODUCT
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   267
void LinkInfo::print() {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   268
  ResourceMark rm;
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   269
  tty->print_cr("Link resolved_klass=%s name=%s signature=%s current_klass=%s check_access=%s",
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   270
                _resolved_klass->name()->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   271
                _name->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   272
                _signature->as_C_string(),
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   273
                _current_klass == NULL ? "(none)" : _current_klass->name()->as_C_string(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   274
                _check_access ? "true" : "false");
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   275
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   276
#endif // PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// Klass resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   280
void LinkResolver::check_klass_accessability(Klass* ref_klass, Klass* sel_klass,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   281
                                             bool fold_type_to_class, TRAPS) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   282
  Klass* base_klass = sel_klass;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   283
  if (fold_type_to_class) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   284
    if (sel_klass->is_objArray_klass()) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   285
      base_klass = ObjArrayKlass::cast(sel_klass)->bottom_klass();
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   286
    }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   287
    // The element type could be a typeArray - we only need the access
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   288
    // check if it is a reference to another class.
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   289
    if (!base_klass->is_instance_klass()) {
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   290
      return;  // no relevant check to do
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   291
    }
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   292
  }
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   293
  Reflection::VerifyClassAccessResults vca_result =
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   294
    Reflection::verify_class_access(ref_klass, InstanceKlass::cast(base_klass), true);
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   295
  if (vca_result != Reflection::ACCESS_OK) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    ResourceMark rm(THREAD);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   297
    char* msg = Reflection::verify_class_access_msg(ref_klass,
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   298
                                                    InstanceKlass::cast(base_klass),
46262
83280d968b96 8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents: 42074
diff changeset
   299
                                                    vca_result);
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   300
    bool same_module = (base_klass->module() == ref_klass->module());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   301
    if (msg == NULL) {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   302
      Exceptions::fthrow(
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   303
        THREAD_AND_LOCATION,
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   304
        vmSymbols::java_lang_IllegalAccessError(),
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   305
        "failed to access class %s from class %s (%s%s%s)",
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47824
diff changeset
   306
        base_klass->external_name(),
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   307
        ref_klass->external_name(),
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   308
        (same_module) ? base_klass->joint_in_module_of_loader(ref_klass) : base_klass->class_in_module_of_loader(),
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   309
        (same_module) ? "" : "; ",
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   310
        (same_module) ? "" : ref_klass->class_in_module_of_loader());
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   311
    } else {
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   312
      // Use module specific message returned by verify_class_access_msg().
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   313
      Exceptions::fthrow(
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   314
        THREAD_AND_LOCATION,
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   315
        vmSymbols::java_lang_IllegalAccessError(),
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   316
        "%s", msg);
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35913
diff changeset
   317
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// Method resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
// According to JVM spec. $5.4.3c & $5.4.3d
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   326
// Look up method in klasses, including static methods
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   327
// Then look up local default methods
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   328
Method* LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info,
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   329
                                               bool checkpolymorphism,
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   330
                                               bool in_imethod_resolve) {
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   331
  NoSafepointVerifier nsv;  // Method* returned may not be reclaimed
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   332
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   333
  Klass* klass = link_info.resolved_klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   334
  Symbol* name = link_info.name();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   335
  Symbol* signature = link_info.signature();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   336
23999
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   337
  // Ignore overpasses so statics can be found during resolution
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   338
  Method* result = klass->uncached_lookup_method(name, signature, Klass::skip_overpass);
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   339
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   340
  if (klass->is_array_klass()) {
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   341
    // Only consider klass and super klass for arrays
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   342
    return result;
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   343
  }
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   344
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   345
  InstanceKlass* ik = InstanceKlass::cast(klass);
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   346
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   347
  // 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
   348
  // 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
   349
  // 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
   350
  if (in_imethod_resolve &&
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   351
      result != NULL &&
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   352
      ik->is_interface() &&
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   353
      (result->is_static() || !result->is_public()) &&
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   354
      result->method_holder() == SystemDictionary::Object_klass()) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   355
    result = NULL;
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   356
  }
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   357
23999
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   358
  // 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
   359
  // current class if a method has not been found.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   360
  if (result == NULL) {
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   361
    result = ik->find_method(name, signature);
23999
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   362
  }
22eb7be3d99d 8033150: invokestatic: IncompatibleClassChangeError trying to invoke static method from a parent in presence of conflicting defaults.
lfoltan
parents: 22739
diff changeset
   363
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   364
  if (result == NULL) {
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   365
    Array<Method*>* default_methods = ik->default_methods();
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   366
    if (default_methods != NULL) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   367
      result = InstanceKlass::find_method(default_methods, name, signature);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   368
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   369
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   370
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   371
  if (checkpolymorphism && result != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   372
    vmIntrinsics::ID iid = result->intrinsic_id();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   373
    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
   374
      // Do not link directly to these.  The VM must produce a synthetic one using lookup_polymorphic_method.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   375
      return NULL;
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4571
diff changeset
   376
    }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4571
diff changeset
   377
  }
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   378
  return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
// returns first instance method
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   382
// Looks up method in classes, then looks up local default methods
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   383
Method* LinkResolver::lookup_instance_method_in_klasses(Klass* klass,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   384
                                                        Symbol* name,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   385
                                                        Symbol* signature,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   386
                                                        Klass::PrivateLookupMode private_mode, TRAPS) {
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   387
  Method* result = klass->uncached_lookup_method(name, signature, Klass::find_overpass, private_mode);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   388
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   389
  while (result != NULL && result->is_static() && result->method_holder()->super() != NULL) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   390
    Klass* super_klass = result->method_holder()->super();
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   391
    result = super_klass->uncached_lookup_method(name, signature, Klass::find_overpass, private_mode);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   393
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   394
  if (klass->is_array_klass()) {
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   395
    // Only consider klass and super klass for arrays
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   396
    return result;
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   397
  }
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   398
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   399
  if (result == NULL) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   400
    Array<Method*>* default_methods = InstanceKlass::cast(klass)->default_methods();
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   401
    if (default_methods != NULL) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   402
      result = InstanceKlass::find_method(default_methods, name, signature);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   403
      assert(result == NULL || !result->is_static(), "static defaults not allowed");
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   404
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   405
  }
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   406
  return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   409
int LinkResolver::vtable_index_of_interface_method(Klass* klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   410
                                                   const methodHandle& resolved_method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   412
  int vtable_index = Method::invalid_vtable_index;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   413
  Symbol* name = resolved_method->name();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   414
  Symbol* signature = resolved_method->signature();
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   415
  InstanceKlass* ik = InstanceKlass::cast(klass);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   416
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   417
  // First check in default method array
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   418
  if (!resolved_method->is_abstract() && ik->default_methods() != NULL) {
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   419
    int index = InstanceKlass::find_method_index(ik->default_methods(),
32189
5264b560ab1b 8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents: 31019
diff changeset
   420
                                                 name, signature, Klass::find_overpass,
5264b560ab1b 8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents: 31019
diff changeset
   421
                                                 Klass::find_static, Klass::find_private);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   422
    if (index >= 0 ) {
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33593
diff changeset
   423
      vtable_index = ik->default_vtable_indices()->at(index);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   424
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   425
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   426
  if (vtable_index == Method::invalid_vtable_index) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   427
    // get vtable_index for miranda methods
46408
70aab0c2ea8b 8178350: klassVtable and klassItable should be ValueObj
iklam
parents: 46329
diff changeset
   428
    klassVtable vt = ik->vtable();
70aab0c2ea8b 8178350: klassVtable and klassItable should be ValueObj
iklam
parents: 46329
diff changeset
   429
    vtable_index = vt.index_of_miranda(name, signature);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   430
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
   431
  return vtable_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   434
Method* LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   435
  InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass());
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   436
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   437
  // Specify 'true' in order to skip default methods when searching the
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   438
  // interfaces.  Function lookup_method_in_klasses() already looked for
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   439
  // the method in the default methods table.
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   440
  return ik->lookup_method_in_all_interfaces(cp_info.name(), cp_info.signature(), Klass::skip_defaults);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   443
Method* LinkResolver::lookup_polymorphic_method(const LinkInfo& link_info,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   444
                                                Handle *appendix_result_or_null,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   445
                                                TRAPS) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   446
  Klass* klass = link_info.resolved_klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   447
  Symbol* name = link_info.name();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   448
  Symbol* full_signature = link_info.signature();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   449
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   450
  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
   451
  if (TraceMethodHandles) {
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   452
    ResourceMark rm(THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   453
    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
   454
                  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
   455
                  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
   456
  }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   457
  if ((klass == SystemDictionary::MethodHandle_klass() ||
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   458
       klass == SystemDictionary::VarHandle_klass()) &&
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   459
      iid != vmIntrinsics::_none) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   460
    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
   461
      // 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
   462
      // 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
   463
      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
   464
      TempNewSymbol basic_signature =
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   465
        MethodHandles::lookup_basic_type_signature(full_signature, keep_last_arg, CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   466
      if (TraceMethodHandles) {
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   467
        ResourceMark rm(THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   468
        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
   469
                      name->as_C_string(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   470
                      full_signature->as_C_string(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   471
                      basic_signature->as_C_string());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   472
      }
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   473
      Method* result = SystemDictionary::find_method_handle_intrinsic(iid,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   474
                                                              basic_signature,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   475
                                                              CHECK_NULL);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   476
      if (result != NULL) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   477
        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
   478
        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
   479
        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
   480
        if (TraceMethodHandles) {
35543
0961315f4016 8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents: 35135
diff changeset
   481
          ttyLocker ttyl;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   482
          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
   483
          result->print_on(tty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   484
        }
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5547
diff changeset
   485
      }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   486
      return result;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   487
    } else if (iid == vmIntrinsics::_invokeGeneric
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 32189
diff changeset
   488
               && THREAD->can_call_java()
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   489
               && appendix_result_or_null != NULL) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   490
      // 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
   491
      // 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
   492
      if (!MethodHandles::enabled()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   493
        // 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
   494
        Klass* natives = SystemDictionary::MethodHandleNatives_klass();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
   495
        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
   496
          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
   497
                                            Handle(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   498
                                            Handle(),
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   499
                                            true,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   500
                                            CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   501
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   502
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   503
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   504
      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
   505
      Handle method_type;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   506
      Method* result = SystemDictionary::find_method_handle_invoker(
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35913
diff changeset
   507
                                                            klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   508
                                                            name,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   509
                                                            full_signature,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   510
                                                            link_info.current_klass(),
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   511
                                                            &appendix,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   512
                                                            CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   513
      if (TraceMethodHandles) {
35543
0961315f4016 8140659: C1: invokedynamic call patching violates JVMS-6.5.invokedynamic
vlivanov
parents: 35135
diff changeset
   514
        ttyLocker ttyl;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   515
        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
   516
        result->print_on(tty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   517
        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
   518
        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
   519
        else                     appendix->print_on(tty);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   520
      }
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   521
      if (result != NULL) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   522
#ifdef ASSERT
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   523
        ResourceMark rm(THREAD);
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
   524
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   525
        TempNewSymbol basic_signature =
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   526
          MethodHandles::lookup_basic_type_signature(full_signature, CHECK_NULL);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   527
        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
   528
        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
   529
        // +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
   530
        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
   531
        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
   532
        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
   533
          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
   534
          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
   535
          result->print();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   536
        }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   537
        assert(actual_size_of_params == expected_size_of_params,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32189
diff changeset
   538
               "%d != %d", actual_size_of_params, expected_size_of_params);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   539
#endif //ASSERT
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   540
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   541
        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
   542
        (*appendix_result_or_null) = appendix;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   543
      }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   544
      return result;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   545
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   546
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   547
  return NULL;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   548
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   549
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   550
void LinkResolver::check_method_accessability(Klass* ref_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   551
                                              Klass* resolved_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   552
                                              Klass* sel_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   553
                                              const methodHandle& sel_method,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
                                              TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  AccessFlags flags = sel_method->access_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   558
  // Special case:  arrays always override "clone". JVMS 2.15.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  // If the resolved klass is an array class, and the declaring class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  // is java.lang.Object and the method is "clone", set the flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  // to public.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  //
22219
4bfd5df70189 8028741: Interface Method Resolution should skip static and non-public methods in j.l.Object
hseigel
parents: 22218
diff changeset
   563
  // 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
   564
  // 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
   565
  if (sel_method->name() == vmSymbols::clone_name() &&
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   566
      sel_klass == SystemDictionary::Object_klass() &&
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   567
      resolved_klass->is_array_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    // 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
   569
    assert(flags.is_protected(), "clone not protected?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    jint new_flags = flags.as_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    new_flags = new_flags & (~JVM_ACC_PROTECTED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    new_flags = new_flags | JVM_ACC_PUBLIC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    flags.set_flags(new_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   575
//  assert(extra_arg_result_or_null != NULL, "must be able to return extra argument");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   577
  bool can_access = Reflection::verify_member_access(ref_klass,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   578
                                                     resolved_klass,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   579
                                                     sel_klass,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   580
                                                     flags,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   581
                                                     true, false, CHECK);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   582
  // Any existing exceptions that may have been thrown, for example LinkageErrors
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   583
  // from nest-host resolution, have been allowed to propagate.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   584
  if (!can_access) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    ResourceMark rm(THREAD);
50761
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50735
diff changeset
   586
    bool same_module = (sel_klass->module() == ref_klass->module());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   589
      vmSymbols::java_lang_IllegalAccessError(),
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   590
      "class %s tried to access %s%s%smethod '%s' (%s%s%s)",
50761
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50735
diff changeset
   591
      ref_klass->external_name(),
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   592
      sel_method->is_abstract()  ? "abstract "  : "",
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   593
      sel_method->is_protected() ? "protected " : "",
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   594
      sel_method->is_private()   ? "private "   : "",
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   595
      sel_method->external_name(),
50761
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50735
diff changeset
   596
      (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50735
diff changeset
   597
      (same_module) ? "" : "; ",
cb07f4b539fc 8169559: Add class loader names to relevant VM messages
lfoltan
parents: 50735
diff changeset
   598
      (same_module) ? "" : sel_klass->class_in_module_of_loader()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   604
Method* LinkResolver::resolve_method_statically(Bytecodes::Code code,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   605
                                                const 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
   606
  // This method is used only
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   607
  // (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
   608
  // and
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   609
  // (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
   610
  // 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
   611
  // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // resolve klass
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   613
  if (code == Bytecodes::_invokedynamic) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   614
    Klass* 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
   615
    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
   616
    Symbol* method_signature = pool->signature_ref_at(index);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   617
    Klass*  current_klass = pool->pool_holder();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   618
    LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass);
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   619
    return resolve_method(link_info, code, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   620
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   621
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   622
  LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   623
  Klass* resolved_klass = link_info.resolved_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   625
  if (pool->has_preresolution()
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   626
      || (resolved_klass == SystemDictionary::MethodHandle_klass() &&
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   627
          MethodHandles::is_signature_polymorphic_name(resolved_klass, link_info.name()))) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   628
    Method* result = ConstantPool::method_at_if_loaded(pool, index);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   629
    if (result != NULL) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   630
      return result;
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   631
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   632
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9967
diff changeset
   633
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   634
  if (code == Bytecodes::_invokeinterface) {
38034
f22f68545fd5 8153115: Move private interface check to linktime
iveresov
parents: 37267
diff changeset
   635
    return resolve_interface_method(link_info, code, THREAD);
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   636
  } else if (code == Bytecodes::_invokevirtual) {
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   637
    return resolve_method(link_info, code, THREAD);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   638
  } else if (!resolved_klass->is_interface()) {
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   639
    return resolve_method(link_info, code, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   640
  } else {
38034
f22f68545fd5 8153115: Move private interface check to linktime
iveresov
parents: 37267
diff changeset
   641
    return resolve_interface_method(link_info, code, THREAD);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   642
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   645
// Check and print a loader constraint violation message for method or interface method
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   646
void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   647
                                                   const methodHandle& resolved_method,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   648
                                                   const char* method_type, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   649
  Handle current_loader(THREAD, link_info.current_klass()->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   650
  Handle resolved_loader(THREAD, resolved_method->method_holder()->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   651
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   652
  ResourceMark rm(THREAD);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   653
  Symbol* failed_type_symbol =
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   654
    SystemDictionary::check_signature_loaders(link_info.signature(), current_loader,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   655
                                              resolved_loader, true, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   656
  if (failed_type_symbol != NULL) {
51097
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   657
    Klass* current_class = link_info.current_klass();
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   658
    ClassLoaderData* current_loader_data = current_class->class_loader_data();
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   659
    assert(current_loader_data != NULL, "current class has no class loader data");
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   660
    Klass* resolved_method_class = resolved_method->method_holder();
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   661
    ClassLoaderData* target_loader_data = resolved_method_class->class_loader_data();
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   662
    assert(target_loader_data != NULL, "resolved method's class has no class loader data");
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   663
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   664
    stringStream ss;
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   665
    ss.print("loader constraint violation: when resolving %s '", method_type);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   666
    Method::print_external_name(&ss, link_info.resolved_klass(), link_info.name(), link_info.signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   667
    ss.print("' the class loader %s of the current class, %s,"
51097
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   668
             " and the class loader %s for the method's defining class, %s, have"
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   669
             " different Class objects for the type %s used in the signature (%s; %s)",
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   670
             current_loader_data->loader_name_and_id(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   671
             current_class->name()->as_C_string(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   672
             target_loader_data->loader_name_and_id(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   673
             resolved_method_class->name()->as_C_string(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   674
             failed_type_symbol->as_C_string(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   675
             current_class->class_in_module_of_loader(false, true),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   676
             resolved_method_class->class_in_module_of_loader(false, true));
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   677
    THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   678
  }
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   679
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   680
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   681
void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   682
                                                  Klass* current_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   683
                                                  Klass* sel_klass, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   684
  Handle ref_loader(THREAD, current_klass->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   685
  Handle sel_loader(THREAD, sel_klass->class_loader());
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   686
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   687
  ResourceMark rm(THREAD);  // needed for check_signature_loaders
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   688
  Symbol* failed_type_symbol =
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   689
    SystemDictionary::check_signature_loaders(sig,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   690
                                              ref_loader, sel_loader,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   691
                                              false,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   692
                                              CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   693
  if (failed_type_symbol != NULL) {
51097
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   694
    stringStream ss;
50325
462453f3c7f6 8202913: loader constraint message for fields specifies incorrect referring class
hseigel
parents: 50036
diff changeset
   695
    const char* failed_type_name = failed_type_symbol->as_klass_external_name();
51097
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   696
53437
fd0e3299326d 8217512: Message of LinkageError: use 'class' etc. instead of 'type'
goetz
parents: 52823
diff changeset
   697
    ss.print("loader constraint violation: when resolving field \"%s\" of type %s, "
fd0e3299326d 8217512: Message of LinkageError: use 'class' etc. instead of 'type'
goetz
parents: 52823
diff changeset
   698
             "the class loader %s of the current class, %s, "
fd0e3299326d 8217512: Message of LinkageError: use 'class' etc. instead of 'type'
goetz
parents: 52823
diff changeset
   699
             "and the class loader %s for the field's defining %s, %s, "
fd0e3299326d 8217512: Message of LinkageError: use 'class' etc. instead of 'type'
goetz
parents: 52823
diff changeset
   700
             "have different Class objects for type %s (%s; %s)",
51097
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   701
             field->as_C_string(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   702
             failed_type_name,
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   703
             current_klass->class_loader_data()->loader_name_and_id(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   704
             current_klass->external_name(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   705
             sel_klass->class_loader_data()->loader_name_and_id(),
53437
fd0e3299326d 8217512: Message of LinkageError: use 'class' etc. instead of 'type'
goetz
parents: 52823
diff changeset
   706
             sel_klass->external_kind(),
51097
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   707
             sel_klass->external_name(),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   708
             failed_type_name,
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   709
             current_klass->class_in_module_of_loader(false, true),
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   710
             sel_klass->class_in_module_of_loader(false, true));
bef02342d179 8205611: Improve the wording of LinkageErrors to include module and class loader information
lfoltan
parents: 50944
diff changeset
   711
    THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   712
  }
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   713
}
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   714
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   715
Method* LinkResolver::resolve_method(const LinkInfo& link_info,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   716
                                     Bytecodes::Code code, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   718
  Handle nested_exception;
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   719
  Klass* resolved_klass = link_info.resolved_klass();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   720
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   721
  // 1. For invokevirtual, cannot call an interface method
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   722
  if (code == Bytecodes::_invokevirtual && resolved_klass->is_interface()) {
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   723
    ResourceMark rm(THREAD);
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   724
    char buf[200];
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   725
    jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected",
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   726
        resolved_klass->external_name());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   727
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
20685
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   728
  }
2feadfa49bb7 8026299: invokespecial gets ICCE when it should get AME.
acorn
parents: 20391
diff changeset
   729
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   730
  // 2. check constant pool tag for called method - must be JVM_CONSTANT_Methodref
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   731
  if (!link_info.tag().is_invalid() && !link_info.tag().is_method()) {
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   732
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   733
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   734
    ss.print("Method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   735
    Method::print_external_name(&ss, link_info.resolved_klass(), link_info.name(), link_info.signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   736
    ss.print("' must be Methodref constant");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   737
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   738
  }
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   739
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   740
  // 3. lookup method in resolved klass and its super klasses
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   741
  methodHandle resolved_method(THREAD, lookup_method_in_klasses(link_info, true, false));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   743
  // 4. lookup method in all the interfaces implemented by the resolved klass
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   744
  if (resolved_method.is_null() && !resolved_klass->is_array_klass()) { // not found in the class hierarchy
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   745
    resolved_method = methodHandle(THREAD, lookup_method_in_interfaces(link_info));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    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
   748
      // JSR 292:  see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   749
      Method* method = lookup_polymorphic_method(link_info, (Handle*)NULL, THREAD);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   750
      resolved_method = methodHandle(THREAD, method);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   751
      if (HAS_PENDING_EXCEPTION) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   752
        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
   753
        CLEAR_PENDING_EXCEPTION;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
   754
      }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   755
    }
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   756
  }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   757
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   758
  // 5. method lookup failed
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   759
  if (resolved_method.is_null()) {
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   760
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   761
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   762
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   763
    Method::print_external_name(&ss, resolved_klass, link_info.name(), link_info.signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   764
    ss.print("'");
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   765
    THROW_MSG_CAUSE_(vmSymbols::java_lang_NoSuchMethodError(),
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   766
                     ss.as_string(), nested_exception, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   769
  // 6. access checks, access checking may be turned off when calling from within the VM.
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   770
  Klass* current_klass = link_info.current_klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   771
  if (link_info.check_access()) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   772
    assert(current_klass != NULL , "current_klass should not be null");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    // check if method can be accessed by the referring class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    check_method_accessability(current_klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
                               resolved_klass,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   777
                               resolved_method->method_holder(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
                               resolved_method,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   779
                               CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    // check loader constraints
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   782
    check_method_loader_constraints(link_info, resolved_method, "method", CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   784
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   785
  return resolved_method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   788
static void trace_method_resolution(const char* prefix,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   789
                                    Klass* klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   790
                                    Klass* resolved_klass,
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   791
                                    Method* method,
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   792
                                    bool logitables,
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   793
                                    int index = -1) {
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   794
#ifndef PRODUCT
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   795
  ResourceMark rm;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   796
  Log(itables) logi;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   797
  LogStream lsi(logi.trace());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   798
  Log(vtables) logv;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   799
  LogStream lsv(logv.trace());
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   800
  outputStream* st;
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   801
  if (logitables) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   802
    st = &lsi;
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   803
  } else {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46630
diff changeset
   804
    st = &lsv;
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   805
  }
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   806
  st->print("%s%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   807
            prefix,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   808
            (klass == NULL ? "<NULL>" : klass->internal_name()),
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   809
            (resolved_klass == NULL ? "<NULL>" : resolved_klass->internal_name()),
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   810
            Method::name_and_sig_as_C_string(resolved_klass,
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   811
                                             method->name(),
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   812
                                             method->signature()),
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   813
            method->method_holder()->internal_name());
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   814
  method->print_linkage_flags(st);
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   815
  if (index != -1) {
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   816
    st->print("vtable_index:%d", index);
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   817
  }
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   818
  st->cr();
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   819
#endif // PRODUCT
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   820
}
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
   821
38034
f22f68545fd5 8153115: Move private interface check to linktime
iveresov
parents: 37267
diff changeset
   822
// Do linktime resolution of a method in the interface within the context of the specied bytecode.
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   823
Method* LinkResolver::resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   824
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   825
  Klass* resolved_klass = link_info.resolved_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
   827
  // check if klass is interface
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  if (!resolved_klass->is_interface()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
   829
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    char buf[200];
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   831
    jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass->external_name());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   832
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   835
  // check constant pool tag for called method - must be JVM_CONSTANT_InterfaceMethodref
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   836
  if (!link_info.tag().is_invalid() && !link_info.tag().is_interface_method()) {
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   837
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   838
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   839
    ss.print("Method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   840
    Method::print_external_name(&ss, link_info.resolved_klass(), link_info.name(), link_info.signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   841
    ss.print("' must be InterfaceMethodref constant");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   842
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   843
  }
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
   844
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  // lookup method in this interface or its super, java.lang.Object
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
   846
  // JDK8: also look for static methods
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   847
  methodHandle resolved_method(THREAD, lookup_method_in_klasses(link_info, false, true));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   849
  if (resolved_method.is_null() && !resolved_klass->is_array_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    // lookup method in all the super-interfaces
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46701
diff changeset
   851
    resolved_method = methodHandle(THREAD, lookup_method_in_interfaces(link_info));
27020
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   852
  }
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   853
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   854
  if (resolved_method.is_null()) {
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   855
    // no method found
a7c8010446c2 8036805: Correct linker method lookup.
lfoltan
parents: 25057
diff changeset
   856
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   857
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   858
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   859
    Method::print_external_name(&ss, resolved_klass, link_info.name(), link_info.signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   860
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   861
    THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), ss.as_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   864
  if (link_info.check_access()) {
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   865
    // JDK8 adds non-public interface methods, and accessability check requirement
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   866
    Klass* current_klass = link_info.current_klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   867
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   868
    assert(current_klass != NULL , "current_klass should not be null");
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   869
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   870
    // 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
   871
    check_method_accessability(current_klass,
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   872
                               resolved_klass,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   873
                               resolved_method->method_holder(),
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   874
                               resolved_method,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   875
                               CHECK_NULL);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   876
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   877
    check_method_loader_constraints(link_info, resolved_method, "interface method", CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   879
38034
f22f68545fd5 8153115: Move private interface check to linktime
iveresov
parents: 37267
diff changeset
   880
  if (code != Bytecodes::_invokestatic && resolved_method->is_static()) {
22521
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   881
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   882
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   883
    ss.print("Expected instance not static method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   884
    Method::print_external_name(&ss, resolved_klass,
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   885
                                resolved_method->name(), resolved_method->signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   886
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
   887
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
22521
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   888
  }
5387725ea99d 8031045: Access checks should precede additional per-instruction checks
hseigel
parents: 22232
diff changeset
   889
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35900
diff changeset
   890
  if (log_develop_is_enabled(Trace, itables)) {
41669
2091069b6851 8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents: 39699
diff changeset
   891
    char buf[200];
2091069b6851 8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents: 39699
diff changeset
   892
    jio_snprintf(buf, sizeof(buf), "%s resolved interface method: caller-class:",
2091069b6851 8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents: 39699
diff changeset
   893
                 Bytecodes::name(code));
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   894
    trace_method_resolution(buf, link_info.current_klass(), resolved_klass, resolved_method(), true);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
   895
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   896
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
   897
  return resolved_method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
// Field resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   903
void LinkResolver::check_field_accessability(Klass* ref_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   904
                                             Klass* resolved_klass,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   905
                                             Klass* sel_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   906
                                             const fieldDescriptor& fd,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
                                             TRAPS) {
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   908
  bool can_access = Reflection::verify_member_access(ref_klass,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   909
                                                     resolved_klass,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   910
                                                     sel_klass,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   911
                                                     fd.access_flags(),
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   912
                                                     true, false, CHECK);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   913
  // Any existing exceptions that may have been thrown, for example LinkageErrors
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   914
  // from nest-host resolution, have been allowed to propagate.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
   915
  if (!can_access) {
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   916
    bool same_module = (sel_klass->module() == ref_klass->module());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   920
      vmSymbols::java_lang_IllegalAccessError(),
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   921
      "class %s tried to access %s%sfield %s.%s (%s%s%s)",
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   922
      ref_klass->external_name(),
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   923
      fd.is_protected() ? "protected " : "",
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   924
      fd.is_private()   ? "private "   : "",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
      sel_klass->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
      fd.name()->as_C_string(),
50816
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   927
      (same_module) ? ref_klass->joint_in_module_of_loader(sel_klass) : ref_klass->class_in_module_of_loader(),
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   928
      (same_module) ? "" : "; ",
a73848f8d0ad 8199940: Print more information about class loaders in IllegalAccessErrors.
goetz
parents: 50761
diff changeset
   929
      (same_module) ? "" : sel_klass->class_in_module_of_loader()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   935
void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) {
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   936
  LinkInfo link_info(pool, index, method, CHECK);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   937
  resolve_field(fd, link_info, byte, true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   940
void LinkResolver::resolve_field(fieldDescriptor& fd,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   941
                                 const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   942
                                 Bytecodes::Code byte, bool initialize_class,
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   943
                                 TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  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
   945
         byte == Bytecodes::_getfield  || byte == Bytecodes::_putfield  ||
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 29081
diff changeset
   946
         byte == Bytecodes::_nofast_getfield  || byte == Bytecodes::_nofast_putfield  ||
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   947
         (byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 29081
diff changeset
   950
  bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  // Check if there's a resolved klass containing the field
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   952
  Klass* resolved_klass = link_info.resolved_klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   953
  Symbol* field = link_info.name();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   954
  Symbol* sig = link_info.signature();
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
   955
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   956
  if (resolved_klass == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  // Resolve instance field
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   962
  Klass* sel_klass = resolved_klass->find_field(field, sig, &fd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  // check if field exists; i.e., if a klass containing the field def has been selected
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   964
  if (sel_klass == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   969
  // Access checking may be turned off when calling from within the VM.
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   970
  Klass* current_klass = link_info.current_klass();
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   971
  if (link_info.check_access()) {
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17024
diff changeset
   972
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   973
    // check access
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   974
    check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   976
    // check for errors
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   977
    if (is_static != fd.is_static()) {
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   978
      ResourceMark rm(THREAD);
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   979
      char msg[200];
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   980
      jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass->external_name(), fd.name()->as_C_string());
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   981
      THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   982
    }
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   983
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   984
    // A final field can be modified only
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   985
    // (1) by methods declared in the class declaring the field and
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   986
    // (2) by the <clinit> method (in case of a static field)
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   987
    //     or by the <init> method (in case of an instance field).
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   988
    if (is_put && fd.access_flags().is_final()) {
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   989
      ResourceMark rm(THREAD);
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   990
      stringStream ss;
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   991
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   992
      if (sel_klass != current_klass) {
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   993
        ss.print("Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class",
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
   994
                 is_static ? "static" : "non-static", resolved_klass->external_name(), fd.name()->as_C_string(),
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   995
                current_klass->external_name());
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   996
        THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string());
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
   997
      }
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   998
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
   999
      if (fd.constants()->pool_holder()->major_version() >= 53) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1000
        Method* m = link_info.current_method();
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1001
        assert(m != NULL, "information about the current method must be available for 'put' bytecodes");
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1002
        bool is_initialized_static_final_update = (byte == Bytecodes::_putstatic &&
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1003
                                                   fd.is_static() &&
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1004
                                                   !m->is_static_initializer());
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1005
        bool is_initialized_instance_final_update = ((byte == Bytecodes::_putfield || byte == Bytecodes::_nofast_putfield) &&
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1006
                                                     !fd.is_static() &&
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1007
                                                     !m->is_object_initializer());
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1008
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1009
        if (is_initialized_static_final_update || is_initialized_instance_final_update) {
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1010
          ss.print("Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s ",
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1011
                   is_static ? "static" : "non-static", resolved_klass->external_name(), fd.name()->as_C_string(),
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1012
                   m->name()->as_C_string(),
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1013
                   is_static ? "<clinit>" : "<init>");
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1014
          THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string());
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1015
        }
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1016
      }
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1017
    }
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1018
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1019
    // initialize resolved_klass if necessary
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1020
    // note 1: the klass which declared the field must be initialized (i.e, sel_klass)
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1021
    //         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1022
    //
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1023
    // note 2: we don't want to force initialization if we are just checking
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1024
    //         if the field access is legal; e.g., during compilation
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1025
    if (is_static && initialize_class) {
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1026
      sel_klass->initialize(CHECK);
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38939
diff changeset
  1027
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
52162
279174cb3a24 8199226: Improve field accesses
hseigel
parents: 52066
diff changeset
  1030
  if ((sel_klass != current_klass) && (current_klass != NULL)) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1031
    check_field_loader_constraints(field, sig, current_klass, sel_klass, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  // return information. note that the klass is set to the actual klass containing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  // field, otherwise access of static fields in superclasses will not work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
// Invoke resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
// Naming conventions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
// resolved_method    the specified method (i.e., static receiver specified via constant pool index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
// sel_method         the selected method  (selected via run-time lookup; e.g., based on dynamic receiver class)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
// resolved_klass     the specified klass  (i.e., specified via constant pool index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
// recv_klass         the receiver klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1050
void LinkResolver::resolve_static_call(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1051
                                       const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1052
                                       bool initialize_class, TRAPS) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1053
  Method* resolved_method = linktime_resolve_static_method(link_info, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1055
  // The resolved class can change as a result of this resolution.
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1056
  Klass* resolved_klass = resolved_method->method_holder();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1057
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  // Initialize klass (this should only happen if everything is ok)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  if (initialize_class && resolved_klass->should_be_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    resolved_klass->initialize(CHECK);
38939
c1b1d1d0e89b 8158397: Crash: assert(save_resolved_method == resolved_method()) failed: does this change?
coleenp
parents: 38719
diff changeset
  1061
    // Use updated LinkInfo to reresolve with resolved method holder
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1062
    LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(),
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
  1063
                      link_info.current_klass(),
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
  1064
                      link_info.check_access() ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1065
    resolved_method = linktime_resolve_static_method(new_info, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  // setup result
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1069
  result.set_static(resolved_klass, methodHandle(THREAD, resolved_method), CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
// throws linktime exceptions
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1073
Method* LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1075
  Klass* resolved_klass = link_info.resolved_klass();
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1076
  Method* resolved_method;
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
  1077
  if (!resolved_klass->is_interface()) {
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
  1078
    resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
  1079
  } else {
38034
f22f68545fd5 8153115: Move private interface check to linktime
iveresov
parents: 37267
diff changeset
  1080
    resolved_method = resolve_interface_method(link_info, Bytecodes::_invokestatic, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
  1081
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  // check if static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  if (!resolved_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1086
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1087
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1088
    ss.print("Expected static method '");
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1089
    resolved_method->print_external_name(&ss);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1090
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1091
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1093
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1097
void LinkResolver::resolve_special_call(CallInfo& result,
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1098
                                        Handle recv,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1099
                                        const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1100
                                        TRAPS) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1101
  Method* resolved_method = linktime_resolve_special_method(link_info, CHECK);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1102
  runtime_resolve_special_method(result, link_info, methodHandle(THREAD, resolved_method), recv, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
// throws linktime exceptions
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1106
Method* LinkResolver::linktime_resolve_special_method(const LinkInfo& link_info, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1108
  // Invokespecial is called for multiple special reasons:
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1109
  // <init>
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1110
  // 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
  1111
  // 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
  1112
  // 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
  1113
  // superinterface.method, which explicitly does not check shadowing
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1114
  Klass* resolved_klass = link_info.resolved_klass();
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1115
  Method* resolved_method;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13929
diff changeset
  1116
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
  1117
  if (!resolved_klass->is_interface()) {
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
  1118
    resolved_method = resolve_method(link_info, Bytecodes::_invokespecial, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
  1119
  } else {
38034
f22f68545fd5 8153115: Move private interface check to linktime
iveresov
parents: 37267
diff changeset
  1120
    resolved_method = resolve_interface_method(link_info, Bytecodes::_invokespecial, CHECK_NULL);
21912
8d2924674592 8026066: ICCE for invokeinterface static
acorn
parents: 21768
diff changeset
  1121
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  // check if method name is <init>, that it is found in same klass as static type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  if (resolved_method->name() == vmSymbols::object_initializer_name() &&
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1125
      resolved_method->method_holder() != resolved_klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1127
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1128
    ss.print("%s: method '", resolved_klass->external_name());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1129
    resolved_method->signature()->print_as_signature_external_return_type(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1130
    ss.print(" %s(", resolved_method->name()->as_C_string());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1131
    resolved_method->signature()->print_as_signature_external_parameters(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1132
    ss.print(")' not found");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    Exceptions::fthrow(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
      THREAD_AND_LOCATION,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
  1135
      vmSymbols::java_lang_NoSuchMethodError(),
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1136
      "%s", ss.as_string());
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1137
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1140
  // ensure that invokespecial's interface method reference is in
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1141
  // a direct superinterface, not an indirect superinterface
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1142
  Klass* current_klass = link_info.current_klass();
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1143
  if (current_klass != NULL && resolved_klass->is_interface()) {
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1144
    InstanceKlass* ck = InstanceKlass::cast(current_klass);
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51097
diff changeset
  1145
    InstanceKlass *klass_to_check = !ck->is_unsafe_anonymous() ?
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1146
                                    ck :
52823
f5d0926026ec 8214728: Unnecessary InstanceKlass::cast at few places
ccheung
parents: 52162
diff changeset
  1147
                                    ck->unsafe_anonymous_host();
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24456
diff changeset
  1148
    // Disable verification for the dynamically-generated reflection bytecodes.
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24456
diff changeset
  1149
    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
  1150
                        SystemDictionary::reflect_MagicAccessorImpl_klass());
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1151
22218
71cff6a30ec1 8029415: java/lang/reflect/Method/invoke/TestPrivateInterfaceMethodReflect.java fails on all platforms with hs25-b61
hseigel
parents: 21913
diff changeset
  1152
    if (!is_reflect &&
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1153
        !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
  1154
      ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1155
      stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1156
      ss.print("Interface method reference: '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1157
      resolved_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1158
      ss.print("', is in an indirect superinterface of %s",
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1159
               current_klass->external_name());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1160
      THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1161
    }
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1162
  }
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 21556
diff changeset
  1163
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  // check if not static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  if (resolved_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1166
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1167
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1168
    ss.print("Expecting non-static method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1169
    resolved_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1170
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1171
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
  }
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1173
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35900
diff changeset
  1174
  if (log_develop_is_enabled(Trace, itables)) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1175
    trace_method_resolution("invokespecial resolved method: caller-class:",
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
  1176
                            current_klass, resolved_klass, resolved_method, true);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1177
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1178
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1179
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
// throws runtime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1183
void LinkResolver::runtime_resolve_special_method(CallInfo& result,
47401
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1184
                                                  const LinkInfo& link_info,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1185
                                                  const methodHandle& resolved_method,
47401
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1186
                                                  Handle recv, TRAPS) {
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1187
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1188
  Klass* resolved_klass = link_info.resolved_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  // 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
  1191
  // for a superclass method
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1192
  // 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
  1193
  // no checks for shadowing
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  methodHandle sel_method(THREAD, resolved_method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
47401
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1196
  if (link_info.check_access() &&
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1197
      // check if the method is not <init>
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1198
      resolved_method->name() != vmSymbols::object_initializer_name()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
47401
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1200
    Klass* current_klass = link_info.current_klass();
50944
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1201
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1202
    // Check if the class of the resolved_klass is a superclass
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1203
    // (not supertype in order to exclude interface classes) of the current class.
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1204
    // This check is not performed for super.invoke for interface methods
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1205
    // in super interfaces.
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1206
    if (current_klass->is_subclass_of(resolved_klass) &&
8cc36fac7f3d 8202737: Obsolete AllowNonVirtualCalls option
coleenp
parents: 50816
diff changeset
  1207
        current_klass != resolved_klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      // Lookup super method
46458
kvn
parents: 46408 44738
diff changeset
  1209
      Klass* super_klass = current_klass->super();
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1210
      Method* instance_method = lookup_instance_method_in_klasses(super_klass,
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1211
                                                     resolved_method->name(),
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1212
                                                     resolved_method->signature(),
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1213
                                                     Klass::find_private, CHECK);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1214
      sel_method = methodHandle(THREAD, instance_method);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1215
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
      // check if found
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
      if (sel_method.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
        ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1219
        stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1220
        ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1221
        resolved_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1222
        ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1223
        THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), ss.as_string());
47401
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1224
      // check loader constraints if found a different method
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1225
      } else if (sel_method() != resolved_method()) {
98e960939ef2 8180711: Better invokespecial checks
hseigel
parents: 47216
diff changeset
  1226
        check_method_loader_constraints(link_info, sel_method, "method", CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    }
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1229
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1230
    // Check that the class of objectref (the receiver) is the current class or interface,
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1231
    // or a subtype of the current class or interface (the sender), otherwise invokespecial
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1232
    // throws IllegalAccessError.
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1233
    // The verifier checks that the sender is a subtype of the class in the I/MR operand.
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1234
    // The verifier also checks that the receiver is a subtype of the sender, if the sender is
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1235
    // a class.  If the sender is an interface, the check has to be performed at runtime.
46458
kvn
parents: 46408 44738
diff changeset
  1236
    InstanceKlass* sender = InstanceKlass::cast(current_klass);
51444
3e5d28e6de32 8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents: 51097
diff changeset
  1237
    sender = sender->is_unsafe_anonymous() ? sender->unsafe_anonymous_host() : sender;
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1238
    if (sender->is_interface() && recv.not_null()) {
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1239
      Klass* receiver_klass = recv->klass();
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1240
      if (!receiver_klass->is_subtype_of(sender)) {
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1241
        ResourceMark rm(THREAD);
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1242
        char buf[500];
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1243
        jio_snprintf(buf, sizeof(buf),
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1244
                     "Receiver class %s must be the current class or a subtype of interface %s",
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1245
                     receiver_klass->external_name(),
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1246
                     sender->external_name());
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1247
        THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), buf);
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1248
      }
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1249
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  // check if not static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  if (sel_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1254
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1255
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1256
    ss.print("Expecting non-static method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1257
    resolved_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1258
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1259
    THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  // check if abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  if (sel_method->is_abstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1265
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1266
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1267
    Method::print_external_name(&ss, resolved_klass, sel_method->name(), sel_method->signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1268
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1269
    THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), ss.as_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35900
diff changeset
  1272
  if (log_develop_is_enabled(Trace, itables)) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1273
    trace_method_resolution("invokespecial selected method: resolved-class:",
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1274
                            resolved_klass, resolved_klass, sel_method(), true);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1275
  }
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1276
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  // setup result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
  result.set_static(resolved_klass, sel_method, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1281
void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, Klass* receiver_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1282
                                        const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1283
                                        bool check_null_and_abstract, TRAPS) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1284
  Method* resolved_method = linktime_resolve_virtual_method(link_info, CHECK);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1285
  runtime_resolve_virtual_method(result, methodHandle(THREAD, resolved_method),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1286
                                 link_info.resolved_klass(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1287
                                 recv, receiver_klass,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1288
                                 check_null_and_abstract, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
// throws linktime exceptions
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1292
Method* LinkResolver::linktime_resolve_virtual_method(const LinkInfo& link_info,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1293
                                                           TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  // normal method resolution
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1295
  Method* resolved_method = resolve_method(link_info, Bytecodes::_invokevirtual, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1300
  // check if private interface method
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1301
  Klass* resolved_klass = link_info.resolved_klass();
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1302
  Klass* current_klass = link_info.current_klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1303
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
  1304
  // This is impossible, if resolve_klass is an interface, we've thrown icce in resolve_method
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1305
  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
  1306
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1307
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1308
    ss.print("private interface method requires invokespecial, not invokevirtual: method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1309
    resolved_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1310
    ss.print("', caller-class: %s",
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1311
             (current_klass == NULL ? "<null>" : current_klass->internal_name()));
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1312
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1313
  }
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1314
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
  // check if not static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
  if (resolved_method->is_static()) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1317
    ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1318
    stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1319
    ss.print("Expecting non-static method '");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1320
    resolved_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1321
    ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1322
    THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1324
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35900
diff changeset
  1325
  if (log_develop_is_enabled(Trace, vtables)) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1326
    trace_method_resolution("invokevirtual resolved method: caller-class:",
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
  1327
                            current_klass, resolved_klass, resolved_method, false);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20284
diff changeset
  1328
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1329
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1330
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
// throws runtime exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
void LinkResolver::runtime_resolve_virtual_method(CallInfo& result,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1335
                                                  const methodHandle& resolved_method,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1336
                                                  Klass* resolved_klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
                                                  Handle recv,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1338
                                                  Klass* recv_klass,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
                                                  bool check_null_and_abstract,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
                                                  TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
  // setup default return values
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1343
  int vtable_index = Method::invalid_vtable_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
  methodHandle selected_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
  // runtime method resolution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
  if (check_null_and_abstract && recv.is_null()) { // check if receiver exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1351
  // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
  // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
  // 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
  1354
  assert(resolved_method->method_holder()->is_linked(), "must be linked");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  // do lookup based on receiver klass using the vtable index
32189
5264b560ab1b 8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents: 31019
diff changeset
  1357
  if (resolved_method->method_holder()->is_interface()) { // default or miranda method
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1358
    vtable_index = vtable_index_of_interface_method(resolved_klass, resolved_method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
    assert(vtable_index >= 0 , "we should have valid vtable index at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
35900
d64cf9290fc4 8148481: Devirtualize Klass::vtable
mgerdin
parents: 35495
diff changeset
  1361
    selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
    // at this point we are sure that resolved_method is virtual and not
32189
5264b560ab1b 8087342: Crash in klassItable::initialize_itable_for_interface
acorn
parents: 31019
diff changeset
  1364
    // a default or 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
  1365
    assert(!resolved_method->has_itable_index(), "");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    vtable_index = resolved_method->vtable_index();
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1367
    // We could get a negative vtable_index of nonvirtual_vtable_index for private
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1368
    // methods, or for final methods. Private methods never appear in the vtable
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1369
    // and never override other methods. As an optimization, final methods are
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1370
    // never put in the vtable, unless they override an existing method.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1371
    // So if we do get nonvirtual_vtable_index, it means the selected method is the
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1372
    // resolved 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
  1373
    if (vtable_index == Method::nonvirtual_vtable_index) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
      assert(resolved_method->can_be_statically_bound(), "cannot override this method");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
      selected_method = resolved_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
    } else {
35900
d64cf9290fc4 8148481: Devirtualize Klass::vtable
mgerdin
parents: 35495
diff changeset
  1377
      selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
  // check if method exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
  if (selected_method.is_null()) {
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1383
    throw_abstract_method_error(resolved_method, recv_klass, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
  // check if abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
  if (check_null_and_abstract && selected_method->is_abstract()) {
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1388
    // Pass arguments for generating a verbose error message.
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1389
    throw_abstract_method_error(resolved_method, selected_method, recv_klass, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35900
diff changeset
  1392
  if (log_develop_is_enabled(Trace, vtables)) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1393
    trace_method_resolution("invokevirtual selected method: receiver-class:",
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1394
                            recv_klass, resolved_klass, selected_method(),
35463
b32e362563bb 8141564: Convert TraceItables and PrintVtables to Unified Logging
rprotacio
parents: 34666
diff changeset
  1395
                            false, vtable_index);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1396
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  // setup result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1401
void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1402
                                          const LinkInfo& link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1403
                                          bool check_null_and_abstract, TRAPS) {
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1404
  // throws linktime exceptions
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1405
  Method* resolved_method = linktime_resolve_interface_method(link_info, CHECK);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1406
  methodHandle mh(THREAD, resolved_method);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1407
  runtime_resolve_interface_method(result, mh, link_info.resolved_klass(),
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1408
                                   recv, recv_klass, check_null_and_abstract, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1411
Method* LinkResolver::linktime_resolve_interface_method(const LinkInfo& link_info,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1412
                                                             TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  // normal interface method resolution
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1414
  Method* resolved_method = resolve_interface_method(link_info, Bytecodes::_invokeinterface, CHECK_NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier");
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1417
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1418
  return resolved_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
// throws runtime exceptions
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1422
void LinkResolver::runtime_resolve_interface_method(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1423
                                                    const methodHandle& resolved_method,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1424
                                                    Klass* resolved_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1425
                                                    Handle recv,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1426
                                                    Klass* recv_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1427
                                                    bool check_null_and_abstract, TRAPS) {
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1428
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  // check if receiver exists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
  if (check_null_and_abstract && recv.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
    THROW(vmSymbols::java_lang_NullPointerException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
  // check if receiver klass implements the resolved interface
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1435
  if (!recv_klass->is_subtype_of(resolved_klass)) {
9425
6da66b869573 6728025: LinkResolver is missing some ResourceMarks
jcoomes
parents: 9116
diff changeset
  1436
    ResourceMark rm(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    char buf[200];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1439
                 recv_klass->external_name(),
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1440
                 resolved_klass->external_name());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
    THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
  }
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 22219
diff changeset
  1443
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1444
  methodHandle selected_method = resolved_method;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1445
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1446
  // resolve the method in the receiver class, unless it is private
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1447
  if (!resolved_method()->is_private()) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1448
    // do lookup based on receiver klass
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1449
    // This search must match the linktime preparation search for itable initialization
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1450
    // to correctly enforce loader constraints for interface method inheritance.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1451
    // Private methods are skipped as the resolved method was not private.
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1452
    Method* method = lookup_instance_method_in_klasses(recv_klass,
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1453
                                                       resolved_method->name(),
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1454
                                                       resolved_method->signature(),
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1455
                                                       Klass::skip_private, CHECK);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1456
    selected_method = methodHandle(THREAD, method);
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1457
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1458
    if (selected_method.is_null() && !check_null_and_abstract) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1459
      // In theory this is a harmless placeholder value, but
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1460
      // in practice leaving in null affects the nsk default method tests.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1461
      // This needs further study.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1462
      selected_method = resolved_method;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1463
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1464
    // check if method exists
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1465
    if (selected_method.is_null()) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1466
      // Pass arguments for generating a verbose error message.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1467
      throw_abstract_method_error(resolved_method, recv_klass, CHECK);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1468
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1469
    // check access
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1470
    // Throw Illegal Access Error if selected_method is not public.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1471
    if (!selected_method->is_public()) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1472
      ResourceMark rm(THREAD);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1473
      stringStream ss;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1474
      ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1475
      Method::print_external_name(&ss, recv_klass, selected_method->name(), selected_method->signature());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1476
      ss.print("'");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1477
      THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string());
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1478
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1479
    // check if abstract
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1480
    if (check_null_and_abstract && selected_method->is_abstract()) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1481
      throw_abstract_method_error(resolved_method, selected_method, recv_klass, CHECK);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1482
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
  }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1484
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35900
diff changeset
  1485
  if (log_develop_is_enabled(Trace, itables)) {
41669
2091069b6851 8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents: 39699
diff changeset
  1486
    trace_method_resolution("invokeinterface selected method: receiver-class:",
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1487
                            recv_klass, resolved_klass, selected_method(), true);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 20282
diff changeset
  1488
  }
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1489
  // setup result
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1490
  if (resolved_method->has_vtable_index()) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1491
    int vtable_index = resolved_method->vtable_index();
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1492
    log_develop_trace(itables)("  -- vtable index: %d", vtable_index);
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1493
    assert(vtable_index == selected_method->vtable_index(), "sanity check");
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1494
    result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK);
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1495
  } else if (resolved_method->has_itable_index()) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1496
    int itable_index = resolved_method()->itable_index();
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1497
    log_develop_trace(itables)("  -- itable index: %d", itable_index);
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1498
    result.set_interface(resolved_klass, recv_klass, resolved_method, selected_method, itable_index, CHECK);
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1499
  } else {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1500
    int index = resolved_method->vtable_index();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1501
    log_develop_trace(itables)("  -- non itable/vtable index: %d", index);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1502
    assert(index == Method::nonvirtual_vtable_index, "Oops hit another case!");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1503
    assert(resolved_method()->is_private() ||
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1504
           (resolved_method()->is_final() && resolved_method->method_holder() == SystemDictionary::Object_klass()),
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1505
           "Should only have non-virtual invokeinterface for private or final-Object methods!");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1506
    assert(resolved_method()->can_be_statically_bound(), "Should only have non-virtual invokeinterface for statically bound methods!");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1507
    // This sets up the nonvirtual form of "virtual" call (as needed for final and private methods)
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents: 50325
diff changeset
  1508
    result.set_virtual(resolved_klass, resolved_klass, resolved_method, resolved_method, index, CHECK);
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21078
diff changeset
  1509
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1513
Method* LinkResolver::linktime_resolve_interface_method_or_null(
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1514
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
  EXCEPTION_MARK;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1516
  Method* method_result = linktime_resolve_interface_method(link_info, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
    CLEAR_PENDING_EXCEPTION;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1519
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
    return method_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1525
Method* LinkResolver::linktime_resolve_virtual_method_or_null(
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1526
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
  EXCEPTION_MARK;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1528
  Method* method_result = linktime_resolve_virtual_method(link_info, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
    CLEAR_PENDING_EXCEPTION;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1531
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    return method_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1537
Method* LinkResolver::resolve_virtual_call_or_null(
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1538
                                                 Klass* receiver_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1539
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1542
  resolve_virtual_call(info, Handle(), receiver_klass, link_info, false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
    CLEAR_PENDING_EXCEPTION;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1545
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1550
Method* LinkResolver::resolve_interface_call_or_null(
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1551
                                                 Klass* receiver_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1552
                                                 const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1555
  resolve_interface_call(info, Handle(), receiver_klass, link_info, false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
    CLEAR_PENDING_EXCEPTION;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1558
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1563
int LinkResolver::resolve_virtual_vtable_index(Klass* receiver_klass,
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1564
                                               const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1567
  resolve_virtual_call(info, Handle(), receiver_klass, link_info,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1568
                       /*check_null_or_abstract*/false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
    CLEAR_PENDING_EXCEPTION;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13396
diff changeset
  1571
    return Method::invalid_vtable_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  return info.vtable_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1576
Method* LinkResolver::resolve_static_call_or_null(const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  CallInfo info;
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1579
  resolve_static_call(info, link_info, /*initialize_class*/false, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
    CLEAR_PENDING_EXCEPTION;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1582
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1587
Method* LinkResolver::resolve_special_call_or_null(const LinkInfo& link_info) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  CallInfo info;
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1590
  resolve_special_call(info, Handle(), link_info, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
  if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
    CLEAR_PENDING_EXCEPTION;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1593
    return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
  return info.selected_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
// ConstantPool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33198
diff changeset
  1603
void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, Bytecodes::Code byte, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  switch (byte) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
    case Bytecodes::_invokestatic   : resolve_invokestatic   (result,       pool, index, CHECK); break;
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1606
    case Bytecodes::_invokespecial  : resolve_invokespecial  (result, recv, pool, index, CHECK); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    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
  1608
    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
  1609
    case Bytecodes::_invokedynamic  : resolve_invokedynamic  (result,       pool, index, CHECK); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
    case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
  1611
    default                         :                                                            break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1616
void LinkResolver::resolve_invoke(CallInfo& result, Handle& recv,
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1617
                             const methodHandle& attached_method,
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1618
                             Bytecodes::Code byte, TRAPS) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1619
  Klass* defc = attached_method->method_holder();
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1620
  Symbol* name = attached_method->name();
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1621
  Symbol* type = attached_method->signature();
38719
133bf85c3f36 8145148: InterfaceMethod CP entry pointing to a class should cause ICCE
coleenp
parents: 38139
diff changeset
  1622
  LinkInfo link_info(defc, name, type);
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1623
  switch(byte) {
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1624
    case Bytecodes::_invokevirtual:
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1625
      resolve_virtual_call(result, recv, recv->klass(), link_info,
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1626
                           /*check_null_and_abstract=*/true, CHECK);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1627
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1628
    case Bytecodes::_invokeinterface:
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1629
      resolve_interface_call(result, recv, recv->klass(), link_info,
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1630
                             /*check_null_and_abstract=*/true, CHECK);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1631
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1632
    case Bytecodes::_invokestatic:
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1633
      resolve_static_call(result, link_info, /*initialize_class=*/false, CHECK);
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1634
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1635
    case Bytecodes::_invokespecial:
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1636
      resolve_special_call(result, recv, link_info, CHECK);
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1637
      break;
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1638
    default:
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1639
      fatal("bad call: %s", Bytecodes::name(byte));
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46560
diff changeset
  1640
      break;
35086
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1641
  }
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1642
}
bbf32241d851 8072008: Emit direct call instead of linkTo* for recursive indy/MH.invoke* calls
vlivanov
parents: 34238
diff changeset
  1643
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33198
diff changeset
  1644
void LinkResolver::resolve_invokestatic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1645
  LinkInfo link_info(pool, index, CHECK);
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1646
  resolve_static_call(result, link_info, /*initialize_class*/true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1650
void LinkResolver::resolve_invokespecial(CallInfo& result, Handle recv,
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1651
                                         const constantPoolHandle& pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1652
  LinkInfo link_info(pool, index, CHECK);
44738
11431bbc9549 8168699: Validate special case invocations
coleenp
parents: 42074
diff changeset
  1653
  resolve_special_call(result, recv, link_info, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33198
diff changeset
  1658
                                          const constantPoolHandle& pool, int index,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
                                          TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1661
  LinkInfo link_info(pool, index, CHECK);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1662
  Klass* recvrKlass = recv.is_null() ? (Klass*)NULL : recv->klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1663
  resolve_virtual_call(result, recv, recvrKlass, link_info, /*check_null_or_abstract*/true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33198
diff changeset
  1667
void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, TRAPS) {
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1668
  LinkInfo link_info(pool, index, CHECK);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1669
  Klass* recvrKlass = recv.is_null() ? (Klass*)NULL : recv->klass();
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1670
  resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1673
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 33198
diff changeset
  1674
void LinkResolver::resolve_invokehandle(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1675
  // This guy is reached from InterpreterRuntime::resolve_invokehandle.
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1676
  LinkInfo link_info(pool, index, CHECK);
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
  1677
  if (TraceMethodHandles) {
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
  1678
    ResourceMark rm(THREAD);
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1679
    tty->print_cr("resolve_invokehandle %s %s", link_info.name()->as_C_string(),
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1680
                  link_info.signature()->as_C_string());
16691
c117eee6d38a 8011952: Missing ResourceMarks in TraceMethodHandles
kmo
parents: 16591
diff changeset
  1681
  }
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1682
  resolve_handle_call(result, link_info, CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1683
}
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1684
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1685
void LinkResolver::resolve_handle_call(CallInfo& result,
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1686
                                       const LinkInfo& link_info,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1687
                                       TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1688
  // JSR 292:  this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1689
  Klass* resolved_klass = link_info.resolved_klass();
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1690
  assert(resolved_klass == SystemDictionary::MethodHandle_klass() ||
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46262
diff changeset
  1691
         resolved_klass == SystemDictionary::VarHandle_klass(), "");
31019
d05fcdd70109 8029567: Clean up linkResolver code
coleenp
parents: 30773
diff changeset
  1692
  assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 13732
diff changeset
  1693
  Handle       resolved_appendix;
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1694
  Method* resolved_method = lookup_polymorphic_method(link_info, &resolved_appendix, CHECK);
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 58545
diff changeset
  1695
  result.set_handle(resolved_klass, methodHandle(THREAD, resolved_method), resolved_appendix, CHECK);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1696
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1697
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1698
void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int indy_index, TRAPS) {
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1699
  ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(indy_index);
47684
c3c04b6e14f8 8174954: Parameter target type is allowed access after a module read edge or a package export has occurred after failed resolution
hseigel
parents: 47216
diff changeset
  1700
  int pool_index = cpce->constant_pool_index();
c3c04b6e14f8 8174954: Parameter target type is allowed access after a module read edge or a package export has occurred after failed resolution
hseigel
parents: 47216
diff changeset
  1701
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1702
  // Resolve the bootstrap specifier (BSM + optional arguments).
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1703
  BootstrapInfo bootstrap_specifier(pool, pool_index, indy_index);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1704
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1705
  // Check if CallSite has been bound already or failed already, and short circuit:
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1706
  {
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1707
    bool is_done = bootstrap_specifier.resolve_previously_linked_invokedynamic(result, CHECK);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1708
    if (is_done) return;
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1709
  }
47684
c3c04b6e14f8 8174954: Parameter target type is allowed access after a module read edge or a package export has occurred after failed resolution
hseigel
parents: 47216
diff changeset
  1710
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1711
  // The initial step in Call Site Specifier Resolution is to resolve the symbolic
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1712
  // reference to a method handle which will be the bootstrap method for a dynamic
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1713
  // call site.  If resolution for the java.lang.invoke.MethodHandle for the bootstrap
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1714
  // method fails, then a MethodHandleInError is stored at the corresponding bootstrap
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1715
  // method's CP index for the CONSTANT_MethodHandle_info.  So, there is no need to
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1716
  // set the indy_rf flag since any subsequent invokedynamic instruction which shares
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1717
  // this bootstrap method will encounter the resolution of MethodHandleInError.
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1718
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1719
  resolve_dynamic_call(result, bootstrap_specifier, CHECK);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1720
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1721
  if (TraceMethodHandles) {
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1722
    bootstrap_specifier.print_msg_on(tty, "resolve_invokedynamic");
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1723
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1724
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1725
  // The returned linkage result is provisional up to the moment
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1726
  // the interpreter or runtime performs a serialized check of
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1727
  // the relevant CPCE::f1 field.  This is done by the caller
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1728
  // of this method, via CPCE::set_dynamic_call, which uses
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1729
  // an ObjectLocker to do the final serialization of updates
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1730
  // to CPCE state, including f1.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1731
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1732
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1733
void LinkResolver::resolve_dynamic_call(CallInfo& result,
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1734
                                        BootstrapInfo& bootstrap_specifier,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1735
                                        TRAPS) {
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1736
  // JSR 292:  this must resolve to an implicitly generated method
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1737
  // such as MH.linkToCallSite(*...) or some other call-site shape.
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10565
diff changeset
  1738
  // The appendix argument is likely to be a freshly-created CallSite.
54600
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1739
  // It may also be a MethodHandle from an unwrapped ConstantCallSite,
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1740
  // or any other reference.  The resolved_method as well as the appendix
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1741
  // are both recorded together via CallInfo::set_handle.
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1742
  SystemDictionary::invoke_bootstrap_method(bootstrap_specifier, THREAD);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1743
  Exceptions::wrap_dynamic_exception(THREAD);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1744
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1745
  if (HAS_PENDING_EXCEPTION) {
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1746
    if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1747
      // Let any random low-level IE or SOE or OOME just bleed through.
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1748
      // Basically we pretend that the bootstrap method was never called,
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1749
      // if it fails this way:  We neither record a successful linkage,
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1750
      // nor do we memorize a LE for posterity.
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1751
      return;
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1752
    }
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1753
    // JVMS 5.4.3 says: If an attempt by the Java Virtual Machine to resolve
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1754
    // a symbolic reference fails because an error is thrown that is an
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1755
    // instance of LinkageError (or a subclass), then subsequent attempts to
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1756
    // resolve the reference always fail with the same error that was thrown
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1757
    // as a result of the initial resolution attempt.
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1758
     bool recorded_res_status = bootstrap_specifier.save_and_throw_indy_exc(CHECK);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1759
     if (!recorded_res_status) {
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1760
       // Another thread got here just before we did.  So, either use the method
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1761
       // that it resolved or throw the LinkageError exception that it threw.
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1762
       bool is_done = bootstrap_specifier.resolve_previously_linked_invokedynamic(result, CHECK);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1763
       if (is_done) return;
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1764
     }
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1765
     assert(bootstrap_specifier.invokedynamic_cp_cache_entry()->indy_resolution_failed(),
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1766
            "Resolution failure flag wasn't set");
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1767
  }
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1768
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1769
  bootstrap_specifier.resolve_newly_linked_invokedynamic(result, CHECK);
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1770
  // Exceptions::wrap_dynamic_exception not used because
69cfd80f8706 8218994: Consolidate indy and condy JVM information within a BootstrapInfo data structure
lfoltan
parents: 54432
diff changeset
  1771
  // set_handle doesn't throw linkage errors
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
  1772
}
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1773
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1774
// Selected method is abstract.
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1775
void LinkResolver::throw_abstract_method_error(const methodHandle& resolved_method,
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1776
                                               const methodHandle& selected_method,
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1777
                                               Klass *recv_klass, TRAPS) {
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1778
  Klass *resolved_klass = resolved_method->method_holder();
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1779
  ResourceMark rm(THREAD);
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1780
  stringStream ss;
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1781
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1782
  if (recv_klass != NULL) {
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1783
    ss.print("Receiver class %s does not define or inherit an "
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1784
             "implementation of the",
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1785
             recv_klass->external_name());
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1786
  } else {
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1787
    ss.print("Missing implementation of");
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1788
  }
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1789
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1790
  assert(resolved_method.not_null(), "Sanity");
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1791
  ss.print(" resolved method '%s%s",
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1792
           resolved_method->is_abstract() ? "abstract " : "",
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1793
           resolved_method->is_private()  ? "private "  : "");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1794
  resolved_method->signature()->print_as_signature_external_return_type(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1795
  ss.print(" %s(", resolved_method->name()->as_C_string());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1796
  resolved_method->signature()->print_as_signature_external_parameters(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1797
  ss.print(")' of %s %s.",
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1798
           resolved_klass->external_kind(),
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1799
           resolved_klass->external_name());
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1800
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1801
  if (selected_method.not_null() && !(resolved_method == selected_method)) {
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1802
    ss.print(" Selected method is '%s%s",
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1803
             selected_method->is_abstract() ? "abstract " : "",
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1804
             selected_method->is_private()  ? "private "  : "");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1805
    selected_method->print_external_name(&ss);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53838
diff changeset
  1806
    ss.print("'.");
49368
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1807
  }
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1808
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1809
  THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), ss.as_string());
2ed1c37df3a5 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
goetz
parents: 49359
diff changeset
  1810
}