src/hotspot/share/interpreter/rewriter.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 53838 c8c9bd65c198
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
/*
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 51592
diff changeset
     2
 * Copyright (c) 1998, 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: 4567
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
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: 4567
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: 6062
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    26
#include "interpreter/bytecodes.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    27
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    28
#include "interpreter/rewriter.hpp"
46741
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
    29
#include "memory/metadataFactory.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    30
#include "memory/resourceArea.hpp"
53838
c8c9bd65c198 8219229: Make ConstantPool::tag_at and release_tag_at_put inlineable
redestad
parents: 53746
diff changeset
    31
#include "oops/constantPool.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    32
#include "oops/generateOopMap.hpp"
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
    33
#include "prims/methodHandles.hpp"
51467
12997ebbc0d8 8209647: constantPoolHandle::constantPoolHandle(ConstantPool*) when precompiled header is disabled
iklam
parents: 49594
diff changeset
    34
#include "runtime/fieldDescriptor.inline.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49372
diff changeset
    35
#include "runtime/handles.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    37
// Computes a CPC map (new_index -> original_index) for constant pool entries
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// that are referred to by the interpreter at runtime via the constant pool cache.
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    39
// Also computes a CP map (original_index -> new_index).
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    40
// Marks entries in CP which require additional processing.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    41
void Rewriter::compute_index_maps() {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    42
  const int length  = _pool->length();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    43
  init_maps(length);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
    44
  bool saw_mh_symbol = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  for (int i = 0; i < length; i++) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    46
    int tag = _pool->tag_at(i).value();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    47
    switch (tag) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    48
      case JVM_CONSTANT_InterfaceMethodref:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      case JVM_CONSTANT_Fieldref          : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      case JVM_CONSTANT_Methodref         : // fall through
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    51
        add_cp_cache_entry(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    52
        break;
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
    53
      case JVM_CONSTANT_Dynamic:
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
    54
        assert(_pool->has_dynamic_constant(), "constant pool's _has_dynamic_constant flag not set");
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
    55
        add_resolved_references_entry(i);
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
    56
        break;
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
    57
      case JVM_CONSTANT_String            : // fall through
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    58
      case JVM_CONSTANT_MethodHandle      : // fall through
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    59
      case JVM_CONSTANT_MethodType        : // fall through
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    60
        add_resolved_references_entry(i);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    61
        break;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
    62
      case JVM_CONSTANT_Utf8:
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
    63
        if (_pool->symbol_at(i) == vmSymbols::java_lang_invoke_MethodHandle() ||
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
    64
            _pool->symbol_at(i) == vmSymbols::java_lang_invoke_VarHandle()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
    65
          saw_mh_symbol = true;
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
    66
        }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
    67
        break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    70
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    71
  // Record limits of resolved reference map for constant pool cache indices
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    72
  record_map_limits();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    73
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
    74
  guarantee((int) _cp_cache_map.length() - 1 <= (int) ((u2)-1),
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    75
            "all cp cache indexes fit in a u2");
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    76
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
    77
  if (saw_mh_symbol) {
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
    78
    _method_handle_invokers.at_grow(length, 0);
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
    79
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
    82
// Unrewrite the bytecodes if an error occurs.
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
    83
void Rewriter::restore_bytecodes(Thread* thread) {
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
    84
  int len = _methods->length();
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
    85
  bool invokespecial_error = false;
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
    86
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
    87
  for (int i = len-1; i >= 0; i--) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    88
    Method* method = _methods->at(i);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
    89
    scan_method(thread, method, true, &invokespecial_error);
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
    90
    assert(!invokespecial_error, "reversing should not get an invokespecial error");
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
    91
  }
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
    92
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    94
// Creates a constant pool cache given a CPC map
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    95
void Rewriter::make_constant_pool_cache(TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    96
  ClassLoaderData* loader_data = _pool->pool_holder()->class_loader_data();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    97
  ConstantPoolCache* cache =
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
    98
      ConstantPoolCache::allocate(loader_data, _cp_cache_map,
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
    99
                                  _invokedynamic_cp_cache_map,
15928
f9d5c6e4107f 8003553: NPG: metaspace objects should be zeroed in constructors
coleenp
parents: 15799
diff changeset
   100
                                  _invokedynamic_references_map, CHECK);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   101
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   102
  // initialize object cache in constant pool
46427
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 46362
diff changeset
   103
  _pool->set_cache(cache);
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 46362
diff changeset
   104
  cache->set_constant_pool(_pool());
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 46362
diff changeset
   105
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 46362
diff changeset
   106
  // _resolved_references is stored in pool->cache(), so need to be done after
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 46362
diff changeset
   107
  // the above lines.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   108
  _pool->initialize_resolved_references(loader_data, _resolved_references_map,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   109
                                        _resolved_reference_limit,
46741
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   110
                                        THREAD);
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   111
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   112
  // Clean up constant pool cache if initialize_resolved_references() failed.
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   113
  if (HAS_PENDING_EXCEPTION) {
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   114
    MetadataFactory::free_metadata(loader_data, cache);
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   115
    _pool->set_cache(NULL);  // so the verifier isn't confused
49372
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 48826
diff changeset
   116
  } else {
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 48826
diff changeset
   117
    DEBUG_ONLY(
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 48826
diff changeset
   118
    if (DumpSharedSpaces) {
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 48826
diff changeset
   119
      cache->verify_just_initialized();
3bb8b00832d0 8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)"
ccheung
parents: 48826
diff changeset
   120
    })
46741
d5a7407108b4 8180627: gc/gctests/Steal/steal001: guarantee(cp->cache() == NULL) failed
hseigel
parents: 46727
diff changeset
   121
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// The new finalization semantics says that registration of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// finalizable objects must be performed on successful return from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// Object.<init> constructor.  We could implement this trivially if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// <init> were never rewritten but since JVMTI allows this to occur, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// more complicated solution is required.  A special return bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// is used only by Object.<init> to signal the finalization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// registration point.  Additionally local 0 must be preserved so it's
31587
e48945b7849c 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 30764
diff changeset
   133
// available to pass to the registration function.  For simplicity we
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// require that local 0 is never overwritten so it's available as an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// argument for registration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   137
void Rewriter::rewrite_Object_init(const methodHandle& method, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  RawBytecodeStream bcs(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  while (!bcs.is_last_bytecode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    Bytecodes::Code opcode = bcs.raw_next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    switch (opcode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      case Bytecodes::_istore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      case Bytecodes::_lstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      case Bytecodes::_fstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      case Bytecodes::_dstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      case Bytecodes::_astore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        if (bcs.get_index() != 0) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      case Bytecodes::_istore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      case Bytecodes::_lstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      case Bytecodes::_fstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      case Bytecodes::_dstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      case Bytecodes::_astore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                  "can't overwrite local 0 in Object.<init>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46427
diff changeset
   160
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46427
diff changeset
   161
      default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46427
diff changeset
   162
        break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   168
// Rewrite a classfile-order CP index into a native-order CPC index.
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   169
void Rewriter::rewrite_member_reference(address bcp, int offset, bool reverse) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   170
  address p = bcp + offset;
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   171
  if (!reverse) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   172
    int  cp_index    = Bytes::get_Java_u2(p);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   173
    int  cache_index = cp_entry_to_cp_cache(cp_index);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   174
    Bytes::put_native_u2(p, cache_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   175
    if (!_method_handle_invokers.is_empty())
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   176
      maybe_rewrite_invokehandle(p - 1, cp_index, cache_index, reverse);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   177
  } else {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   178
    int cache_index = Bytes::get_native_u2(p);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   179
    int pool_index = cp_cache_entry_pool_index(cache_index);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   180
    Bytes::put_Java_u2(p, pool_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   181
    if (!_method_handle_invokers.is_empty())
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   182
      maybe_rewrite_invokehandle(p - 1, pool_index, cache_index, reverse);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   183
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   184
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   185
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   186
// If the constant pool entry for invokespecial is InterfaceMethodref,
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   187
// we need to add a separate cpCache entry for its resolution, because it is
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   188
// different than the resolution for invokeinterface with InterfaceMethodref.
46362
974737822190 8168438: Fix comment in rewriter
coleenp
parents: 46329
diff changeset
   189
// These cannot share cpCache entries.
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   190
void Rewriter::rewrite_invokespecial(address bcp, int offset, bool reverse, bool* invokespecial_error) {
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   191
  address p = bcp + offset;
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   192
  if (!reverse) {
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   193
    int cp_index = Bytes::get_Java_u2(p);
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   194
    if (_pool->tag_at(cp_index).is_interface_method()) {
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   195
      int cache_index = add_invokespecial_cp_cache_entry(cp_index);
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   196
      if (cache_index != (int)(jushort) cache_index) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   197
        *invokespecial_error = true;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   198
      }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   199
      Bytes::put_native_u2(p, cache_index);
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   200
    } else {
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   201
      rewrite_member_reference(bcp, offset, reverse);
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   202
    }
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   203
  } else {
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   204
    rewrite_member_reference(bcp, offset, reverse);
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   205
  }
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   206
}
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   207
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   208
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   209
// Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   210
void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   211
  if (!reverse) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   212
    if ((*opc) == (u1)Bytecodes::_invokevirtual ||
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   213
        // allow invokespecial as an alias, although it would be very odd:
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   214
        (*opc) == (u1)Bytecodes::_invokespecial) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   215
      assert(_pool->tag_at(cp_index).is_method(), "wrong index");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   216
      // Determine whether this is a signature-polymorphic method.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   217
      if (cp_index >= _method_handle_invokers.length())  return;
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   218
      int status = _method_handle_invokers.at(cp_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   219
      assert(status >= -1 && status <= 1, "oob tri-state");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   220
      if (status == 0) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   221
        if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   222
            MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   223
                                                         _pool->name_ref_at(cp_index))) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   224
          // we may need a resolved_refs entry for the appendix
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 51592
diff changeset
   225
          add_invokedynamic_resolved_references_entry(cp_index, cache_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   226
          status = +1;
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
   227
        } else if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() &&
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
   228
                   MethodHandles::is_signature_polymorphic_name(SystemDictionary::VarHandle_klass(),
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
   229
                                                                _pool->name_ref_at(cp_index))) {
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
   230
          // we may need a resolved_refs entry for the appendix
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 51592
diff changeset
   231
          add_invokedynamic_resolved_references_entry(cp_index, cache_index);
36819
bca375d368ed 8149644: Integrate VarHandles
psandoz
parents: 35492
diff changeset
   232
          status = +1;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   233
        } else {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   234
          status = -1;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   235
        }
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   236
        _method_handle_invokers.at(cp_index) = status;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   237
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   238
      // We use a special internal bytecode for such methods (if non-static).
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   239
      // The basic reason for this is that such methods need an extra "appendix" argument
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   240
      // to transmit the call site's intended call type.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   241
      if (status > 0) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   242
        (*opc) = (u1)Bytecodes::_invokehandle;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   243
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   244
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   245
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   246
    // Do not need to look at cp_index.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   247
    if ((*opc) == (u1)Bytecodes::_invokehandle) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   248
      (*opc) = (u1)Bytecodes::_invokevirtual;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   249
      // Ignore corner case of original _invokespecial instruction.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   250
      // This is safe because (a) the signature polymorphic method was final, and
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   251
      // (b) the implementation of MethodHandle will not call invokespecial on it.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 9971
diff changeset
   252
    }
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   253
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   254
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   255
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   256
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   257
void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   258
  address p = bcp + offset;
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   259
  assert(p[-1] == Bytecodes::_invokedynamic, "not invokedynamic bytecode");
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   260
  if (!reverse) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   261
    int cp_index = Bytes::get_Java_u2(p);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   262
    int cache_index = add_invokedynamic_cp_cache_entry(cp_index);
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 51592
diff changeset
   263
    int resolved_index = add_invokedynamic_resolved_references_entry(cp_index, cache_index);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   264
    // Replace the trailing four bytes with a CPC index for the dynamic
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   265
    // call site.  Unlike other CPC entries, there is one per bytecode,
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   266
    // not just one per distinct CP entry.  In other words, the
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   267
    // CPC-to-CP relation is many-to-one for invokedynamic entries.
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   268
    // This means we must use a larger index size than u2 to address
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   269
    // all these entries.  That is the main reason invokedynamic
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   270
    // must have a five-byte instruction format.  (Of course, other JVM
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   271
    // implementations can use the bytes for other purposes.)
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   272
    // Note: We use native_u4 format exclusively for 4-byte indexes.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   273
    Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index));
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   274
    // add the bcp in case we need to patch this bytecode if we also find a
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   275
    // invokespecial/InterfaceMethodref in the bytecode stream
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   276
    _patch_invokedynamic_bcps->push(p);
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   277
    _patch_invokedynamic_refs->push(resolved_index);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   278
  } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   279
    int cache_index = ConstantPool::decode_invokedynamic_index(
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   280
                        Bytes::get_native_u4(p));
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   281
    // We will reverse the bytecode rewriting _after_ adjusting them.
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   282
    // Adjust the cache index by offset to the invokedynamic entries in the
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   283
    // cpCache plus the delta if the invokedynamic bytecodes were adjusted.
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   284
    int adjustment = cp_cache_delta() + _first_iteration_cp_cache_limit;
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   285
    int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index - adjustment);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   286
    assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index");
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   287
    // zero out 4 bytes
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   288
    Bytes::put_Java_u4(p, 0);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   289
    Bytes::put_Java_u2(p, cp_index);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   290
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   291
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   292
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   293
void Rewriter::patch_invokedynamic_bytecodes() {
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   294
  // If the end of the cp_cache is the same as after initializing with the
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   295
  // cpool, nothing needs to be done.  Invokedynamic bytecodes are at the
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   296
  // correct offsets. ie. no invokespecials added
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   297
  int delta = cp_cache_delta();
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   298
  if (delta > 0) {
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   299
    int length = _patch_invokedynamic_bcps->length();
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   300
    assert(length == _patch_invokedynamic_refs->length(),
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   301
           "lengths should match");
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   302
    for (int i = 0; i < length; i++) {
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   303
      address p = _patch_invokedynamic_bcps->at(i);
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   304
      int cache_index = ConstantPool::decode_invokedynamic_index(
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   305
                          Bytes::get_native_u4(p));
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   306
      Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index + delta));
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   307
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   308
      // invokedynamic resolved references map also points to cp cache and must
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   309
      // add delta to each.
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   310
      int resolved_index = _patch_invokedynamic_refs->at(i);
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 51592
diff changeset
   311
        assert(_invokedynamic_references_map.at(resolved_index) == cache_index,
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   312
             "should be the same index");
53746
bdccafc038a2 8217998: Remove method_type field associated with the appendix field of an indy or method handle call
lfoltan
parents: 51592
diff changeset
   313
        _invokedynamic_references_map.at_put(resolved_index, cache_index + delta);
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   314
    }
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   315
  }
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   316
}
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   317
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   318
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   319
// Rewrite some ldc bytecodes to _fast_aldc
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   320
void Rewriter::maybe_rewrite_ldc(address bcp, int offset, bool is_wide,
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   321
                                 bool reverse) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   322
  if (!reverse) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   323
    assert((*bcp) == (is_wide ? Bytecodes::_ldc_w : Bytecodes::_ldc), "not ldc bytecode");
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   324
    address p = bcp + offset;
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   325
    int cp_index = is_wide ? Bytes::get_Java_u2(p) : (u1)(*p);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   326
    constantTag tag = _pool->tag_at(cp_index).value();
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   327
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   328
    if (tag.is_method_handle() ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   329
        tag.is_method_type() ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   330
        tag.is_string() ||
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   331
        (tag.is_dynamic_constant() &&
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   332
         // keep regular ldc interpreter logic for condy primitives
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   333
         is_reference_type(FieldType::basic_type(_pool->uncached_signature_ref_at(cp_index))))
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 48794
diff changeset
   334
        ) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   335
      int ref_index = cp_entry_to_resolved_references(cp_index);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   336
      if (is_wide) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   337
        (*bcp) = Bytecodes::_fast_aldc_w;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   338
        assert(ref_index == (u2)ref_index, "index overflow");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   339
        Bytes::put_native_u2(p, ref_index);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   340
      } else {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   341
        (*bcp) = Bytecodes::_fast_aldc;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   342
        assert(ref_index == (u1)ref_index, "index overflow");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   343
        (*p) = (u1)ref_index;
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   344
      }
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   345
    }
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   346
  } else {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   347
    Bytecodes::Code rewritten_bc =
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   348
              (is_wide ? Bytecodes::_fast_aldc_w : Bytecodes::_fast_aldc);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   349
    if ((*bcp) == rewritten_bc) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   350
      address p = bcp + offset;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   351
      int ref_index = is_wide ? Bytes::get_native_u2(p) : (u1)(*p);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   352
      int pool_index = resolved_references_entry_to_pool_index(ref_index);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   353
      if (is_wide) {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   354
        (*bcp) = Bytecodes::_ldc_w;
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   355
        assert(pool_index == (u2)pool_index, "index overflow");
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   356
        Bytes::put_Java_u2(p, pool_index);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   357
      } else {
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   358
        (*bcp) = Bytecodes::_ldc;
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   359
        assert(pool_index == (u1)pool_index, "index overflow");
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   360
        (*p) = (u1)pool_index;
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   361
      }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   362
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   363
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   364
}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   365
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   366
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// Rewrites a method given the index_map information
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   368
void Rewriter::scan_method(Thread* thread, Method* method, bool reverse, bool* invokespecial_error) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  int nof_jsrs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  bool has_monitor_bytecodes = false;
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   372
  Bytecodes::Code c;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   374
  // Bytecodes and their length
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   375
  const address code_base = method->code_base();
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   376
  const int code_length = method->code_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   378
  int bc_length;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   379
  for (int bci = 0; bci < code_length; bci += bc_length) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   380
    address bcp = code_base + bci;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   381
    int prefix_length = 0;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   382
    c = (Bytecodes::Code)(*bcp);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   383
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   384
    // Since we have the code, see if we can get the length
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   385
    // directly. Some more complicated bytecodes will report
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   386
    // a length of zero, meaning we need to make another method
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   387
    // call to calculate the length.
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   388
    bc_length = Bytecodes::length_for(c);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   389
    if (bc_length == 0) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   390
      bc_length = Bytecodes::length_at(method, bcp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   392
      // length_at will put us at the bytecode after the one modified
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   393
      // by 'wide'. We don't currently examine any of the bytecodes
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   394
      // modified by wide, but in case we do in the future...
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   395
      if (c == Bytecodes::_wide) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   396
        prefix_length = 1;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   397
        c = (Bytecodes::Code)bcp[1];
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   398
      }
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   399
    }
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   400
51592
1ddd1ec04431 8210168: JCK test .vm.classfmt.ins.code__002.code__00201m1.code__00201m1 hangs with -noverify
hseigel
parents: 51467
diff changeset
   401
    // Continuing with an invalid bytecode will fail in the loop below.
1ddd1ec04431 8210168: JCK test .vm.classfmt.ins.code__002.code__00201m1.code__00201m1 hangs with -noverify
hseigel
parents: 51467
diff changeset
   402
    // So guarantee here.
1ddd1ec04431 8210168: JCK test .vm.classfmt.ins.code__002.code__00201m1.code__00201m1 hangs with -noverify
hseigel
parents: 51467
diff changeset
   403
    guarantee(bc_length > 0, "Verifier should have caught this invalid bytecode");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   405
    switch (c) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   406
      case Bytecodes::_lookupswitch   : {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   407
#ifndef CC_INTERP
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   408
        Bytecode_lookupswitch bc(method, bcp);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   409
        (*bcp) = (
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   410
          bc.number_of_pairs() < BinarySwitchThreshold
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   411
          ? Bytecodes::_fast_linearswitch
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   412
          : Bytecodes::_fast_binaryswitch
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   413
        );
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   414
#endif
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   415
        break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   416
      }
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   417
      case Bytecodes::_fast_linearswitch:
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   418
      case Bytecodes::_fast_binaryswitch: {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   419
#ifndef CC_INTERP
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   420
        (*bcp) = Bytecodes::_lookupswitch;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   421
#endif
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   422
        break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   425
      case Bytecodes::_invokespecial  : {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   426
        rewrite_invokespecial(bcp, prefix_length+1, reverse, invokespecial_error);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   427
        break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   428
      }
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   429
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   430
      case Bytecodes::_putstatic      :
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   431
      case Bytecodes::_putfield       : {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   432
        if (!reverse) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   433
          // Check if any final field of the class given as parameter is modified
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   434
          // outside of initializer methods of the class. Fields that are modified
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   435
          // are marked with a flag. For marked fields, the compilers do not perform
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   436
          // constant folding (as the field can be changed after initialization).
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   437
          //
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   438
          // The check is performed after verification and only if verification has
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   439
          // succeeded. Therefore, the class is guaranteed to be well-formed.
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   440
          InstanceKlass* klass = method->method_holder();
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   441
          u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   442
          constantPoolHandle cp(thread, method->constants());
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   443
          Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index));
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   444
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   445
          if (klass->name() == ref_class_name) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   446
            Symbol* field_name = cp->name_ref_at(bc_index);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   447
            Symbol* field_sig = cp->signature_ref_at(bc_index);
39619
905b6eee37b3 8160551: assert(c == Bytecodes::_putfield) failed: must be putfield
coleenp
parents: 39421
diff changeset
   448
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   449
            fieldDescriptor fd;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   450
            if (klass->find_field(field_name, field_sig, &fd) != NULL) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   451
              if (fd.access_flags().is_final()) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   452
                if (fd.access_flags().is_static()) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   453
                  if (!method->is_static_initializer()) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   454
                    fd.set_has_initialized_final_update(true);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   455
                  }
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   456
                } else {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   457
                  if (!method->is_object_initializer()) {
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   458
                    fd.set_has_initialized_final_update(true);
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   459
                  }
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   460
                }
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   461
              }
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   462
            }
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   463
          }
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 38031
diff changeset
   464
        }
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   465
      }
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   466
      // fall through
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   467
      case Bytecodes::_getstatic      : // fall through
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   468
      case Bytecodes::_getfield       : // fall through
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   469
      case Bytecodes::_invokevirtual  : // fall through
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   470
      case Bytecodes::_invokestatic   :
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   471
      case Bytecodes::_invokeinterface:
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   472
      case Bytecodes::_invokehandle   : // if reverse=true
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   473
        rewrite_member_reference(bcp, prefix_length+1, reverse);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   474
        break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   475
      case Bytecodes::_invokedynamic:
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   476
        rewrite_invokedynamic(bcp, prefix_length+1, reverse);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   477
        break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   478
      case Bytecodes::_ldc:
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   479
      case Bytecodes::_fast_aldc:  // if reverse=true
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   480
        maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   481
        break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   482
      case Bytecodes::_ldc_w:
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   483
      case Bytecodes::_fast_aldc_w:  // if reverse=true
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   484
        maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse);
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   485
        break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   486
      case Bytecodes::_jsr            : // fall through
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   487
      case Bytecodes::_jsr_w          : nof_jsrs++;                   break;
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   488
      case Bytecodes::_monitorenter   : // fall through
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   489
      case Bytecodes::_monitorexit    : has_monitor_bytecodes = true; break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46427
diff changeset
   490
46783
bfa353c0d440 8068317: No_Safepoint_Verifier is not necessary in Rewriter::scan_method
coleenp
parents: 46741
diff changeset
   491
      default: break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  // Update access flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  if (has_monitor_bytecodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    method->set_has_monitor_bytecodes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  // The present of a jsr bytecode implies that the method might potentially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  // have to be rewritten, so we run the oopMapGenerator on the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  if (nof_jsrs > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    method->set_has_jsrs();
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   504
    // Second pass will revisit this method.
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   505
    assert(method->has_jsrs(), "didn't we just set this?");
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   506
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   507
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   509
// After constant pool is created, revisit methods containing jsrs.
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   510
methodHandle Rewriter::rewrite_jsrs(const methodHandle& method, TRAPS) {
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   511
  ResourceMark rm(THREAD);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   512
  ResolveOopMapConflicts romc(method);
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   513
  methodHandle new_method = romc.do_potential_rewrite(CHECK_(methodHandle()));
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   514
  // Update monitor matching info.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   515
  if (romc.monitor_safe()) {
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   516
    new_method->set_guaranteed_monitor_matching();
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   517
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
46727
6e4a84748e2c 8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents: 46630
diff changeset
   519
  return new_method;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   522
void Rewriter::rewrite_bytecodes(TRAPS) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   523
  assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   525
  // determine index maps for Method* rewriting
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   526
  compute_index_maps();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   528
  if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) {
3273
6acf7084b1d3 6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents: 2570
diff changeset
   529
    bool did_rewrite = false;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   530
    int i = _methods->length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    while (i-- > 0) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   532
      Method* method = _methods->at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      if (method->intrinsic_id() == vmIntrinsics::_Object_init) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
        // rewrite the return bytecodes of Object.<init> to register the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
        // object for finalization if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
        methodHandle m(THREAD, method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
        rewrite_Object_init(m, CHECK);
3273
6acf7084b1d3 6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents: 2570
diff changeset
   538
        did_rewrite = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    }
3273
6acf7084b1d3 6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents: 2570
diff changeset
   542
    assert(did_rewrite, "must find Object::<init> to rewrite it");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   545
  // rewrite methods, in two passes
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   546
  int len = _methods->length();
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   547
  bool invokespecial_error = false;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   548
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   549
  for (int i = len-1; i >= 0; i--) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   550
    Method* method = _methods->at(i);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   551
    scan_method(THREAD, method, false, &invokespecial_error);
21734
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   552
    if (invokespecial_error) {
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   553
      // If you get an error here, there is no reversing bytecodes
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   554
      // This exception is stored for this class and no further attempt is
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   555
      // made at verifying or rewriting.
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   556
      THROW_MSG(vmSymbols::java_lang_InternalError(),
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   557
                "This classfile overflows invokespecial for interfaces "
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   558
                "and cannot be loaded");
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   559
      return;
440a9598dc23 8028347: Rewriter::scan_method asserts with array oob in RT_Baseline
coleenp
parents: 21557
diff changeset
   560
     }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   561
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   562
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   563
  // May have to fix invokedynamic bytecodes if invokestatic/InterfaceMethodref
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   564
  // entries had to be added.
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   565
  patch_invokedynamic_bytecodes();
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   566
}
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   567
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42870
diff changeset
   568
void Rewriter::rewrite(InstanceKlass* klass, TRAPS) {
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   569
  if (!DumpSharedSpaces) {
48794
ea0d0781c63c 8178351: Simplify MetaspaceShared::is_in_shared_space and MetaspaceObj::is_shared
iklam
parents: 47216
diff changeset
   570
    assert(!klass->is_shared(), "archive methods must not be rewritten at run time");
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 22750
diff changeset
   571
  }
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   572
  ResourceMark rm(THREAD);
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   573
  constantPoolHandle cpool(THREAD, klass->constants());
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   574
  Rewriter     rw(klass, cpool, klass->methods(), CHECK);
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   575
  // (That's all, folks.)
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   576
}
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   577
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 42870
diff changeset
   578
Rewriter::Rewriter(InstanceKlass* klass, const constantPoolHandle& cpool, Array<Method*>* methods, TRAPS)
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   579
  : _klass(klass),
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   580
    _pool(cpool),
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   581
    _methods(methods),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   582
    _cp_map(cpool->length()),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   583
    _cp_cache_map(cpool->length() / 2),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   584
    _reference_map(cpool->length()),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   585
    _resolved_references_map(cpool->length() / 2),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   586
    _invokedynamic_references_map(cpool->length() / 2),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   587
    _method_handle_invokers(cpool->length()),
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36819
diff changeset
   588
    _invokedynamic_cp_cache_map(cpool->length() / 4)
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   589
{
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   590
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   591
  // Rewrite bytecodes - exception here exits.
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   592
  rewrite_bytecodes(CHECK);
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   593
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   594
  // Stress restoring bytecodes
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   595
  if (StressRewriter) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   596
    restore_bytecodes(THREAD);
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   597
    rewrite_bytecodes(CHECK);
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   598
  }
21557
55115e0708f1 8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
coleenp
parents: 15928
diff changeset
   599
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   600
  // allocate constant pool cache, now that we've seen all the bytecodes
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   601
  make_constant_pool_cache(THREAD);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   602
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   603
  // Restore bytecodes to their unrewritten state if there are exceptions
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   604
  // rewriting bytecodes or allocating the cpCache
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   605
  if (HAS_PENDING_EXCEPTION) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   606
    restore_bytecodes(THREAD);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   607
    return;
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   608
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   609
15099
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   610
  // Relocate after everything, but still do this under the is_rewritten flag,
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   611
  // so methods with jsrs in custom class lists in aren't attempted to be
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   612
  // rewritten in the RO section of the shared archive.
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   613
  // Relocated bytecodes don't have to be restored, only the cp cache entries
22750
a3c879b18f22 8033528: assert(0 <= i && i < length()) failed: index out of bounds
coleenp
parents: 21734
diff changeset
   614
  int len = _methods->length();
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 9116
diff changeset
   615
  for (int i = len-1; i >= 0; i--) {
15099
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   616
    methodHandle m(THREAD, _methods->at(i));
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   617
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   618
    if (m->has_jsrs()) {
15099
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   619
      m = rewrite_jsrs(m, THREAD);
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   620
      // Restore bytecodes to their unrewritten state if there are exceptions
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   621
      // relocating bytecodes.  If some are relocated, that is ok because that
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   622
      // doesn't affect constant pool to cpCache rewriting.
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   623
      if (HAS_PENDING_EXCEPTION) {
59056
15936b142f86 8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents: 53838
diff changeset
   624
        restore_bytecodes(THREAD);
15099
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   625
        return;
b31d40895bbb 8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents: 13929
diff changeset
   626
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      // Method might have gotten rewritten.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   628
      methods->at_put(i, m());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
}