hotspot/src/share/vm/oops/constantPoolOop.cpp
author twisti
Tue, 24 Jul 2012 10:51:00 -0700
changeset 13391 30245956af37
parent 11626 7423003cc783
permissions -rw-r--r--
7023639: JSR 292 method handle invocation needs a fast path for compiled code 6984705: JSR 292 method handle creation should not go through JNI Summary: remove assembly code for JDK 7 chained method handles Reviewed-by: jrose, twisti, kvn, mhaupt Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
11626
7423003cc783 7140882: Don't return booleans from methods returning pointers
brutisso
parents: 10565
diff changeset
     2
 * Copyright (c) 1997, 2012, 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: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
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: 4571
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: 7114
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    26
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    27
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    28
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    29
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    30
#include "interpreter/linkResolver.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    31
#include "memory/oopFactory.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    32
#include "memory/universe.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    33
#include "oops/constantPoolOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    34
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    35
#include "oops/objArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    36
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    37
#include "runtime/fieldType.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    38
#include "runtime/init.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    39
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7114
diff changeset
    40
#include "runtime/vframe.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    42
void constantPoolOopDesc::set_flag_at(FlagBit fb) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    43
  const int MAX_STATE_CHANGES = 2;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    44
  for (int i = MAX_STATE_CHANGES + 10; i > 0; i--) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    45
    int oflags = _flags;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    46
    int nflags = oflags | (1 << (int)fb);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    47
    if (Atomic::cmpxchg(nflags, &_flags, oflags) == oflags)
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    48
      return;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    49
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    50
  assert(false, "failed to cmpxchg flags");
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    51
  _flags |= (1 << (int)fb);     // better than nothing
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    52
}
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
    53
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    55
  // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // tag is not updated atomicly.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    58
  CPSlot entry = this_oop->slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    59
  if (entry.is_oop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    60
    assert(entry.get_oop()->is_klass(), "must be");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    // Already resolved - return entry.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    62
    return (klassOop)entry.get_oop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Acquire lock on constant oop while doing update. After we get the lock, we check if another object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // already has updated the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(THREAD->is_Java_thread(), "must be a Java thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  bool do_resolve = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  bool in_error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    71
  Symbol* name = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  Handle       loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  { ObjectLocker ol(this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    if (this_oop->tag_at(which).is_unresolved_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        in_error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        do_resolve = true;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    80
        name   = this_oop->unresolved_klass_at(which);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
        loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  } // unlocking constantPool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // The original attempt to resolve this constant pool entry failed so find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // original error and throw it again (JVMS 5.4.3).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  if (in_error) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    90
    Symbol* error = SystemDictionary::find_resolution_error(this_oop, which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    91
    guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    // exception text will be the class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    THROW_MSG_0(error, className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if (do_resolve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // this_oop must be unlocked during resolve_or_fail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    Handle h_prot (THREAD, protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    klassOop k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    KlassHandle k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (!HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      k = KlassHandle(THREAD, k_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      // Do access check for klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      verify_constant_pool_resolve(this_oop, k, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    // Failed to resolve class. We must record the errors so that subsequent attempts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      ResourceMark rm;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   114
      Symbol* error = PENDING_EXCEPTION->klass()->klass_part()->name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      bool throw_orig_error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        ObjectLocker ol (this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        // some other thread has beaten us and has resolved the class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        if (this_oop->tag_at(which).is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
          CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
          entry = this_oop->resolved_klass_at(which);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   124
          return (klassOop)entry.get_oop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        if (!PENDING_EXCEPTION->
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4429
diff changeset
   128
              is_a(SystemDictionary::LinkageError_klass())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
          // Just throw the exception and don't prevent these classes from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
          // being loaded due to virtual machine errors like StackOverflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
          // and OutOfMemoryError, etc, or if the thread was hit by stop()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
          // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
          SystemDictionary::add_resolution_error(this_oop, which, error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
          this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
          // some other thread has put the class in error state.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   139
          error = SystemDictionary::find_resolution_error(this_oop, which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   140
          assert(error != NULL, "checking");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
          throw_orig_error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      } // unlocked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      if (throw_orig_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        THROW_MSG_0(error, className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (TraceClassResolution && !k()->klass_part()->oop_is_array()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      // skip resolving the constant pool so that this code get's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      // called the next time some bytecodes refer to this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      int line_number = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      const char * source_file = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      if (JavaThread::current()->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        // try to identify the method which called this function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        vframeStream vfst(JavaThread::current());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        if (!vfst.at_end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
          line_number = vfst.method()->line_number_from_bci(vfst.bci());
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   166
          Symbol* s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
          if (s != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
            source_file = s->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      if (k() != this_oop->pool_holder()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        // only print something if the classes are different
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        if (source_file != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
          tty->print("RESOLVE %s %s %s:%d\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                     instanceKlass::cast(this_oop->pool_holder())->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
                     instanceKlass::cast(k())->external_name(), source_file, line_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
          tty->print("RESOLVE %s %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
                     instanceKlass::cast(this_oop->pool_holder())->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
                     instanceKlass::cast(k())->external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      ObjectLocker ol (this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      // Only updated constant pool - if it is resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      do_resolve = this_oop->tag_at(which).is_unresolved_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      if (do_resolve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        this_oop->klass_at_put(which, k());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  entry = this_oop->resolved_klass_at(which);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   196
  assert(entry.is_oop() && entry.get_oop()->is_klass(), "must be resolved at this point");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   197
  return (klassOop)entry.get_oop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
// Does not update constantPoolOop - to avoid any exception throwing. Used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// by compiler and exception handling.  Also used to avoid classloads for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// instanceof operations. Returns NULL if the class has not been loaded or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
// if the verification of constant pool failed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   206
  CPSlot entry = this_oop->slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   207
  if (entry.is_oop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   208
    assert(entry.get_oop()->is_klass(), "must be");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   209
    return (klassOop)entry.get_oop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  } else {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   211
    assert(entry.is_metadata(), "must be either symbol or klass");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    Thread *thread = Thread::current();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   213
    Symbol* name = entry.get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    Handle h_prot (thread, protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    Handle h_loader (thread, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      // Make sure that resolving is legal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      KlassHandle klass(THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      // return NULL if verification fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      verify_constant_pool_resolve(this_oop, klass, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      return klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
klassOop constantPoolOopDesc::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// This is an interface for the compiler that allows accessing non-resolved entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// in the constant pool - but still performs the validations tests. Must be used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// in a pre-parse of the compiler - to determine what it can do and not do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// Note: We cannot update the ConstantPool from the vm_thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  int which = this_oop->klass_ref_index_at(index);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   249
  CPSlot entry = this_oop->slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   250
  if (entry.is_oop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   251
    assert(entry.get_oop()->is_klass(), "must be");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   252
    return (klassOop)entry.get_oop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  } else {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   254
    assert(entry.is_metadata(), "must be either symbol or klass");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   255
    Symbol*  name  = entry.get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    Handle h_loader(THREAD, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    Handle h_prot  (THREAD, protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    // Do access check for klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   269
methodOop constantPoolOopDesc::method_at_if_loaded(constantPoolHandle cpool,
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   270
                                                   int which) {
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   271
  assert(!constantPoolCacheOopDesc::is_secondary_index(which), "no indy instruction here");
11626
7423003cc783 7140882: Don't return booleans from methods returning pointers
brutisso
parents: 10565
diff changeset
   272
  if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   273
  int cache_index = get_cpcache_index(which);
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   274
  if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   275
    if (PrintMiscellaneous && (Verbose||WizardMode)) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   276
      tty->print_cr("bad operand %d in:", which); cpool->print();
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   277
    }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   278
    return NULL;
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   279
  }
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   280
  ConstantPoolCacheEntry* e = cpool->cache()->entry_at(cache_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   281
  return e->method_if_resolved(cpool);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   282
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   283
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   284
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   285
bool constantPoolOopDesc::has_appendix_at_if_loaded(constantPoolHandle cpool, int which) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   286
  if (cpool->cache() == NULL)  return false;  // nothing to load yet
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   287
  // XXX Is there a simpler way to get to the secondary entry?
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   288
  ConstantPoolCacheEntry* e;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   289
  if (constantPoolCacheOopDesc::is_secondary_index(which)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   290
    e = cpool->cache()->secondary_entry_at(which);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   291
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   292
    int cache_index = get_cpcache_index(which);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   293
    if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   294
      if (PrintMiscellaneous && (Verbose||WizardMode)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   295
        tty->print_cr("bad operand %d in:", which); cpool->print();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   296
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   297
      return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   298
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   299
    e = cpool->cache()->entry_at(cache_index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   300
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   301
  return e->has_appendix();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   302
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   303
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   304
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   305
oop constantPoolOopDesc::appendix_at_if_loaded(constantPoolHandle cpool, int which) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   306
  if (cpool->cache() == NULL)  return NULL;  // nothing to load yet
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   307
  // XXX Is there a simpler way to get to the secondary entry?
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   308
  ConstantPoolCacheEntry* e;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   309
  if (constantPoolCacheOopDesc::is_secondary_index(which)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   310
    e = cpool->cache()->secondary_entry_at(which);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   311
  } else {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   312
    int cache_index = get_cpcache_index(which);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   313
    if (!(cache_index >= 0 && cache_index < cpool->cache()->length())) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   314
      if (PrintMiscellaneous && (Verbose||WizardMode)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   315
        tty->print_cr("bad operand %d in:", which); cpool->print();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   316
      }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   317
      return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   318
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   319
    e = cpool->cache()->entry_at(cache_index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   320
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   321
  if (!e->has_appendix()) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   322
    return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   323
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   324
  return e->f1_as_instance();
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   325
}
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   326
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 9116
diff changeset
   327
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   328
Symbol* constantPoolOopDesc::impl_name_ref_at(int which, bool uncached) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   329
  int name_index = name_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  return symbol_at(name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   334
Symbol* constantPoolOopDesc::impl_signature_ref_at(int which, bool uncached) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   335
  int signature_index = signature_ref_index_at(impl_name_and_type_ref_index_at(which, uncached));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  return symbol_at(signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   340
int constantPoolOopDesc::impl_name_and_type_ref_index_at(int which, bool uncached) {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   341
  int i = which;
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   342
  if (!uncached && cache() != NULL) {
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   343
    if (constantPoolCacheOopDesc::is_secondary_index(which)) {
7111
ac1a0346bc0f 6981788: GC map generator sometimes picks up the wrong kind of instruction operand
jrose
parents: 6463
diff changeset
   344
      // Invokedynamic index.
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   345
      int pool_index = cache()->main_entry_at(which)->constant_pool_index();
9116
9bc44be338d6 6981791: remove experimental code for JSR 292
jrose
parents: 8725
diff changeset
   346
      pool_index = invoke_dynamic_name_and_type_ref_index_at(pool_index);
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   347
      assert(tag_at(pool_index).is_name_and_type(), "");
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   348
      return pool_index;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   349
    }
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   350
    // change byte-ordering and go via cache
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   351
    i = remap_instruction_operand_from_cache(which);
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   352
  } else {
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   353
    if (tag_at(which).is_invoke_dynamic()) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   354
      int pool_index = invoke_dynamic_name_and_type_ref_index_at(which);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   355
      assert(tag_at(pool_index).is_name_and_type(), "");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   356
      return pool_index;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   357
    }
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   358
  }
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   359
  assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   360
  assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above");
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   361
  jint ref_index = *int_at_addr(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  return extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   366
int constantPoolOopDesc::impl_klass_ref_index_at(int which, bool uncached) {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   367
  guarantee(!constantPoolCacheOopDesc::is_secondary_index(which),
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   368
            "an invokedynamic instruction does not have a klass");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   369
  int i = which;
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   370
  if (!uncached && cache() != NULL) {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   371
    // change byte-ordering and go via cache
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   372
    i = remap_instruction_operand_from_cache(which);
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   373
  }
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   374
  assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   375
  jint ref_index = *int_at_addr(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  return extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   380
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   381
int constantPoolOopDesc::remap_instruction_operand_from_cache(int operand) {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4571
diff changeset
   382
  int cpc_index = operand;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4571
diff changeset
   383
  DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4571
diff changeset
   384
  assert((int)(u2)cpc_index == cpc_index, "clean u2");
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   385
  int member_index = cache()->entry_at(cpc_index)->constant_pool_index();
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 2860
diff changeset
   386
  return member_index;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   387
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   388
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   389
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
 if (k->oop_is_instance() || k->oop_is_objArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    instanceKlassHandle holder (THREAD, this_oop->pool_holder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    KlassHandle element (THREAD, elem_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    // The element type could be a typeArray - we only need the access check if it is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    // an reference to another class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    if (element->oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      LinkResolver::check_klass_accessability(holder, element, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   405
int constantPoolOopDesc::name_ref_index_at(int which_nt) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   406
  jint ref_index = name_and_type_at(which_nt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  return extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   411
int constantPoolOopDesc::signature_ref_index_at(int which_nt) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   412
  jint ref_index = name_and_type_at(which_nt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  return extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  return klass_at(klass_ref_index_at(which), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   422
Symbol* constantPoolOopDesc::klass_name_at(int which) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
         "Corrupted constant pool");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   425
  // A resolved constantPool entry will contain a klassOop, otherwise a Symbol*.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  // It is not safe to rely on the tag bit's here, since we don't have a lock, and the entry and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  // tag is not updated atomicly.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   428
  CPSlot entry = slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   429
  if (entry.is_oop()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    // Already resolved - return entry's name.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   431
    assert(entry.get_oop()->is_klass(), "must be");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   432
    return klassOop(entry.get_oop())->klass_part()->name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  } else {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   434
    assert(entry.is_metadata(), "must be either symbol or klass");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   435
    return entry.get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   439
Symbol* constantPoolOopDesc::klass_ref_at_noresolve(int which) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  jint ref_index = klass_ref_index_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  return klass_at_noresolve(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   444
Symbol* constantPoolOopDesc::uncached_klass_ref_at_noresolve(int which) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   445
  jint ref_index = uncached_klass_ref_index_at(which);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   446
  return klass_at_noresolve(ref_index);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   447
}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   448
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
char* constantPoolOopDesc::string_at_noresolve(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  // Test entry type in case string is resolved while in here.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   451
  CPSlot entry = slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   452
  if (entry.is_metadata()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   453
    return (entry.get_symbol())->as_C_string();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   454
  } else if (java_lang_String::is_instance(entry.get_oop())) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   455
    return java_lang_String::as_utf8_string(entry.get_oop());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  } else {
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   457
    return (char*)"<pseudo-string>";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  return FieldType::basic_type(symbol_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    if (this_oop->tag_at(index).is_unresolved_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      this_oop->string_at(index, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   475
// A resolved constant value in the CP cache is represented as a non-null
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   476
// value.  As a special case, this value can be a 'systemObjArray'
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   477
// which masks an exception object to throw.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   478
// This allows a MethodHandle constant reference to throw a consistent
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   479
// exception every time, if it fails to resolve.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   480
static oop decode_exception_from_f1(oop result_oop, TRAPS) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   481
  if (result_oop->klass() != Universe::systemObjArrayKlassObj())
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   482
    return result_oop;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   483
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   484
  // Special cases here:  Masked null, saved exception.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   485
  objArrayOop sys_array = (objArrayOop) result_oop;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   486
  assert(sys_array->length() == 1, "bad system array");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   487
  if (sys_array->length() == 1) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   488
    THROW_OOP_(sys_array->obj_at(0), NULL);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   489
  }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   490
  return NULL;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   491
}
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   492
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   493
oop constantPoolOopDesc::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   494
  oop result_oop = NULL;
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   495
  Handle throw_exception;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   496
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   497
  if (cache_index == _possible_index_sentinel) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   498
    // It is possible that this constant is one which is cached in the CP cache.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   499
    // We'll do a linear search.  This should be OK because this usage is rare.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   500
    assert(index > 0, "valid index");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   501
    constantPoolCacheOop cache = this_oop()->cache();
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   502
    for (int i = 0, len = cache->length(); i < len; i++) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   503
      ConstantPoolCacheEntry* cpc_entry = cache->entry_at(i);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   504
      if (!cpc_entry->is_secondary_entry() && cpc_entry->constant_pool_index() == index) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   505
        // Switch the query to use this CPC entry.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   506
        cache_index = i;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   507
        index = _no_index_sentinel;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   508
        break;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   509
      }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   510
    }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   511
    if (cache_index == _possible_index_sentinel)
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   512
      cache_index = _no_index_sentinel;  // not found
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   513
  }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   514
  assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   515
  assert(index == _no_index_sentinel || index >= 0, "");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   516
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   517
  if (cache_index >= 0) {
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   518
    assert(index == _no_index_sentinel, "only one kind of index at a time");
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   519
    ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   520
    result_oop = cpc_entry->f1_as_instance();
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   521
    if (result_oop != NULL) {
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   522
      return decode_exception_from_f1(result_oop, THREAD);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   523
      // That was easy...
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   524
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   525
    index = cpc_entry->constant_pool_index();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   526
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   527
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   528
  jvalue prim_value;  // temp used only in a few cases below
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   529
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   530
  int tag_value = this_oop->tag_at(index).value();
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   531
  switch (tag_value) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   532
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   533
  case JVM_CONSTANT_UnresolvedClass:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   534
  case JVM_CONSTANT_UnresolvedClassInError:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   535
  case JVM_CONSTANT_Class:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   536
    {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   537
      klassOop resolved = klass_at_impl(this_oop, index, CHECK_NULL);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   538
      // ldc wants the java mirror.
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8651
diff changeset
   539
      result_oop = resolved->java_mirror();
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   540
      break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   541
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   542
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   543
  case JVM_CONSTANT_String:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   544
  case JVM_CONSTANT_UnresolvedString:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   545
    if (this_oop->is_pseudo_string_at(index)) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   546
      result_oop = this_oop->pseudo_string_at(index);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   547
      break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   548
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   549
    result_oop = string_at_impl(this_oop, index, CHECK_NULL);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   550
    break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   551
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   552
  case JVM_CONSTANT_Object:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   553
    result_oop = this_oop->object_at(index);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   554
    break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   555
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   556
  case JVM_CONSTANT_MethodHandle:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   557
    {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   558
      int ref_kind                 = this_oop->method_handle_ref_kind_at(index);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   559
      int callee_index             = this_oop->method_handle_klass_index_at(index);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   560
      Symbol*  name =      this_oop->method_handle_name_ref_at(index);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   561
      Symbol*  signature = this_oop->method_handle_signature_ref_at(index);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   562
      if (PrintMiscellaneous)
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   563
        tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   564
                      ref_kind, index, this_oop->method_handle_index_at(index),
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   565
                      callee_index, name->as_C_string(), signature->as_C_string());
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   566
      KlassHandle callee;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   567
      { klassOop k = klass_at_impl(this_oop, callee_index, CHECK_NULL);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   568
        callee = KlassHandle(THREAD, k);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   569
      }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   570
      KlassHandle klass(THREAD, this_oop->pool_holder());
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   571
      Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   572
                                                                   callee, name, signature,
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   573
                                                                   THREAD);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   574
      if (HAS_PENDING_EXCEPTION) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   575
        throw_exception = Handle(THREAD, PENDING_EXCEPTION);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   576
        CLEAR_PENDING_EXCEPTION;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   577
        break;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   578
      }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   579
      result_oop = value();
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   580
      assert(result_oop != NULL, "");
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   581
      break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   582
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   583
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   584
  case JVM_CONSTANT_MethodType:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   585
    {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   586
      Symbol*  signature = this_oop->method_type_signature_at(index);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   587
      if (PrintMiscellaneous)
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   588
        tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   589
                      index, this_oop->method_type_index_at(index),
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   590
                      signature->as_C_string());
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   591
      KlassHandle klass(THREAD, this_oop->pool_holder());
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   592
      Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   593
      if (HAS_PENDING_EXCEPTION) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   594
        throw_exception = Handle(THREAD, PENDING_EXCEPTION);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   595
        CLEAR_PENDING_EXCEPTION;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   596
        break;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   597
      }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   598
      result_oop = value();
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   599
      assert(result_oop != NULL, "");
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   600
      break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   601
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   602
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   603
  case JVM_CONSTANT_Integer:
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   604
    prim_value.i = this_oop->int_at(index);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   605
    result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   606
    break;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   607
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   608
  case JVM_CONSTANT_Float:
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   609
    prim_value.f = this_oop->float_at(index);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   610
    result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   611
    break;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   612
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   613
  case JVM_CONSTANT_Long:
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   614
    prim_value.j = this_oop->long_at(index);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   615
    result_oop = java_lang_boxing_object::create(T_LONG, &prim_value, CHECK_NULL);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   616
    break;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   617
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   618
  case JVM_CONSTANT_Double:
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   619
    prim_value.d = this_oop->double_at(index);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   620
    result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   621
    break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   622
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   623
  default:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   624
    DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   625
                              this_oop(), index, cache_index, tag_value) );
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   626
    assert(false, "unexpected constant tag");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   627
    break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   628
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   629
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   630
  if (cache_index >= 0) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   631
    // Cache the oop here also.
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   632
    if (throw_exception.not_null()) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   633
      objArrayOop sys_array = oopFactory::new_system_objArray(1, CHECK_NULL);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   634
      sys_array->obj_at_put(0, throw_exception());
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   635
      result_oop = sys_array;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   636
      throw_exception = Handle();  // be tidy
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   637
    }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   638
    Handle result_handle(THREAD, result_oop);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   639
    result_oop = NULL;  // safety
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   640
    ObjectLocker ol(this_oop, THREAD);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   641
    ConstantPoolCacheEntry* cpc_entry = this_oop->cache()->entry_at(cache_index);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   642
    result_oop = cpc_entry->f1_as_instance();
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   643
    // Benign race condition:  f1 may already be filled in while we were trying to lock.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   644
    // The important thing here is that all threads pick up the same result.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   645
    // It doesn't matter which racing thread wins, as long as only one
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   646
    // result is used by all threads, and all future queries.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   647
    // That result may be either a resolved constant or a failure exception.
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   648
    if (result_oop == NULL) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   649
      result_oop = result_handle();
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   650
      cpc_entry->set_f1(result_oop);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   651
    }
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   652
    return decode_exception_from_f1(result_oop, THREAD);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   653
  } else {
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   654
    if (throw_exception.not_null()) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   655
      THROW_HANDLE_(throw_exception, NULL);
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   656
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   657
    return result_oop;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   658
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   659
}
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
   660
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   661
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   662
oop constantPoolOopDesc::resolve_bootstrap_specifier_at_impl(constantPoolHandle this_oop, int index, TRAPS) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   663
  assert(this_oop->tag_at(index).is_invoke_dynamic(), "Corrupted constant pool");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   664
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   665
  Handle bsm;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   666
  int argc;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   667
  {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   668
    // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&type], plus optional arguments
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   669
    // The bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   670
    // It is accompanied by the optional arguments.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   671
    int bsm_index = this_oop->invoke_dynamic_bootstrap_method_ref_index_at(index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   672
    oop bsm_oop = this_oop->resolve_possibly_cached_constant_at(bsm_index, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   673
    if (!java_lang_invoke_MethodHandle::is_instance(bsm_oop)) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   674
      THROW_MSG_NULL(vmSymbols::java_lang_LinkageError(), "BSM not an MethodHandle");
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   675
    }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   676
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   677
    // Extract the optional static arguments.
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   678
    argc = this_oop->invoke_dynamic_argument_count_at(index);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   679
    if (argc == 0)  return bsm_oop;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   680
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   681
    bsm = Handle(THREAD, bsm_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   682
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   683
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   684
  objArrayHandle info;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   685
  {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   686
    objArrayOop info_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), 1+argc, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   687
    info = objArrayHandle(THREAD, info_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   688
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   689
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   690
  info->obj_at_put(0, bsm());
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   691
  for (int i = 0; i < argc; i++) {
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   692
    int arg_index = this_oop->invoke_dynamic_argument_index_at(index, i);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   693
    oop arg_oop = this_oop->resolve_possibly_cached_constant_at(arg_index, CHECK_NULL);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   694
    info->obj_at_put(1+i, arg_oop);
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   695
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   696
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   697
  return info();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   698
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 11626
diff changeset
   699
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   701
  oop str = NULL;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   702
  CPSlot entry = this_oop->slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   703
  if (entry.is_metadata()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    ObjectLocker ol(this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    if (this_oop->tag_at(which).is_unresolved_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
      // Intern string
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   707
      Symbol* sym = this_oop->unresolved_string_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   708
      str = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   709
      this_oop->string_at_put(which, str);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      // Another thread beat us and interned string, read string from constant pool
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   712
      str = this_oop->resolved_string_at(which);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   714
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   715
    str = entry.get_oop();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   717
  assert(java_lang_String::is_instance(str), "must be string");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   718
  return str;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   722
bool constantPoolOopDesc::is_pseudo_string_at(int which) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   723
  CPSlot entry = slot_at(which);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   724
  if (entry.is_metadata())
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   725
    // Not yet resolved, but it will resolve to a string.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   726
    return false;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   727
  else if (java_lang_String::is_instance(entry.get_oop()))
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   728
    return false; // actually, it might be a non-interned or non-perm string
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   729
  else
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   730
    // truly pseudo
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   731
    return true;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   732
}
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   733
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1
diff changeset
   734
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
                                                int which) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   737
  // Names are interned, so we can compare Symbol*s directly
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   738
  Symbol* cp_name = klass_name_at(which);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  return (cp_name == k->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    if (tag_at(index).is_unresolved_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
      // Intern string
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   749
      Symbol* sym = unresolved_string_at(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      oop entry = StringTable::intern(sym, CHECK_(-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
      string_at_put(index, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  return count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   757
// Iterate over symbols and decrement ones which are Symbol*s.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   758
// This is done during GC so do not need to lock constantPool unless we
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   759
// have per-thread safepoints.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   760
// Only decrement the UTF8 symbols. Unresolved classes and strings point to
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   761
// these symbols but didn't increment the reference count.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   762
void constantPoolOopDesc::unreference_symbols() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   763
  for (int index = 1; index < length(); index++) { // Index 0 is unused
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   764
    constantTag tag = tag_at(index);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   765
    if (tag.is_symbol()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   766
      symbol_at(index)->decrement_refcount();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   767
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   768
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   769
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
// Iterate over symbols which are used as class, field, method names and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
// signatures (in preparation for writing to the shared archive).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   774
void constantPoolOopDesc::shared_symbols_iterate(SymbolClosure* closure) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  for (int index = 1; index < length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    switch (tag_at(index).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    case JVM_CONSTANT_UnresolvedClass:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   779
    case JVM_CONSTANT_UnresolvedString:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   780
    case JVM_CONSTANT_Utf8:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   781
      assert(slot_at(index).is_metadata(), "must be symbol");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   782
      closure->do_symbol(symbol_at_addr(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
        int i = *int_at_addr(index);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   788
        closure->do_symbol(symbol_at_addr((unsigned)i >> 16));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   789
        closure->do_symbol(symbol_at_addr((unsigned)i & 0xffff));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
      // Do nothing!  Not an oop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
      // These constant types do not reference symbols at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
      // Do nothing!  Not a symbol.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      // Do nothing!  Not an oop. (But takes two pool entries.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
// Iterate over the [one] tags array (in preparation for writing to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
// shared archive).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  closure->do_oop(tags_addr());
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
   826
  closure->do_oop(operands_addr());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
// Iterate over String objects (in preparation for writing to the shared
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
// archive).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  for (int index = 1; index < length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    switch (tag_at(index).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
      // Do nothing!  Not a String.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
      // Do nothing!  Not an oop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
      // These constant types do not reference symbols at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
    case JVM_CONSTANT_String:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   853
      closure->do_oop(obj_at_addr_raw(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      // These constants are symbols, but unless these symbols are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      // actually to be used for something, we don't want to mark them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
      // Do nothing!  Not an oop. (But takes two pool entries.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
// Compare this constant pool's entry at index1 to the constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
// cp2's entry at index2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
       int index2, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  jbyte t1 = tag_at(index1).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  jbyte t2 = cp2->tag_at(index2).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  // when comparing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  if (t1 == JVM_CONSTANT_UnresolvedClassInError) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    t1 = JVM_CONSTANT_UnresolvedClass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  if (t2 == JVM_CONSTANT_UnresolvedClassInError) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    t2 = JVM_CONSTANT_UnresolvedClass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  if (t1 != t2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
    // Not the same entry type so there is nothing else to check. Note
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    // that this style of checking will consider resolved/unresolved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    // class pairs and resolved/unresolved string pairs as different.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    // From the constantPoolOop API point of view, this is correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    // behavior. See constantPoolKlass::merge() to see how this plays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    // out in the context of constantPoolOop merging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  switch (t1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
    klassOop k1 = klass_at(index1, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    klassOop k2 = cp2->klass_at(index2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    if (k1 == k2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
    int recur1 = klass_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    int recur2 = cp2->klass_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
    jdouble d1 = double_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    jdouble d2 = cp2->double_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    if (d1 == d2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    int recur1 = uncached_klass_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
    int recur2 = cp2->uncached_klass_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
      recur1 = uncached_name_and_type_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
      recur2 = cp2->uncached_name_and_type_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
      match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
      if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    jfloat f1 = float_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    jfloat f2 = cp2->float_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    if (f1 == f2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    jint i1 = int_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    jint i2 = cp2->int_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    if (i1 == i2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    jlong l1 = long_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    jlong l2 = cp2->long_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
    if (l1 == l2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    int recur1 = name_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    int recur2 = cp2->name_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
      recur1 = signature_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
      recur2 = cp2->signature_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
      match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
      if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    oop s1 = string_at(index1, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    oop s2 = cp2->string_at(index2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    if (s1 == s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    int recur1 = string_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    int recur2 = cp2->string_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1013
    Symbol* k1 = unresolved_klass_at(index1);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1014
    Symbol* k2 = cp2->unresolved_klass_at(index2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    if (k1 == k2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1020
  case JVM_CONSTANT_MethodType:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1021
  {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1022
    int k1 = method_type_index_at(index1);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1023
    int k2 = cp2->method_type_index_at(index2);
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1024
    bool match = compare_entry_to(k1, cp2, k2, CHECK_false);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1025
    if (match) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1026
      return true;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1027
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1028
  } break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1029
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1030
  case JVM_CONSTANT_MethodHandle:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1031
  {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1032
    int k1 = method_handle_ref_kind_at(index1);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1033
    int k2 = cp2->method_handle_ref_kind_at(index2);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1034
    if (k1 == k2) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1035
      int i1 = method_handle_index_at(index1);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1036
      int i2 = cp2->method_handle_index_at(index2);
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1037
      bool match = compare_entry_to(i1, cp2, i2, CHECK_false);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1038
      if (match) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1039
        return true;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1040
      }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1041
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1042
  } break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1043
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1044
  case JVM_CONSTANT_InvokeDynamic:
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1045
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1046
    int k1 = invoke_dynamic_bootstrap_method_ref_index_at(index1);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1047
    int k2 = cp2->invoke_dynamic_bootstrap_method_ref_index_at(index2);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1048
    bool match = compare_entry_to(k1, cp2, k2, CHECK_false);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1049
    if (!match)  return false;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1050
    k1 = invoke_dynamic_name_and_type_ref_index_at(index1);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1051
    k2 = cp2->invoke_dynamic_name_and_type_ref_index_at(index2);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1052
    match = compare_entry_to(k1, cp2, k2, CHECK_false);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1053
    if (!match)  return false;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1054
    int argc = invoke_dynamic_argument_count_at(index1);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1055
    if (argc == cp2->invoke_dynamic_argument_count_at(index2)) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1056
      for (int j = 0; j < argc; j++) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1057
        k1 = invoke_dynamic_argument_index_at(index1, j);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1058
        k2 = cp2->invoke_dynamic_argument_index_at(index2, j);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1059
        match = compare_entry_to(k1, cp2, k2, CHECK_false);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1060
        if (!match)  return false;
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
  1061
      }
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1062
      return true;           // got through loop; all elements equal
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1063
    }
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1064
  } break;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1065
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1068
    Symbol* s1 = unresolved_string_at(index1);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1069
    Symbol* s2 = cp2->unresolved_string_at(index2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    if (s1 == s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1077
    Symbol* s1 = symbol_at(index1);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1078
    Symbol* s2 = cp2->symbol_at(index2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    if (s1 == s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  // Invalid is used as the tag for the second constant pool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  // not be seen by itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  case JVM_CONSTANT_Invalid: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
} // end compare_entry_to()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
// Copy this constant pool's entries at start_i to end_i (inclusive)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
// to the constant pool to_cp's entries starting at to_i. A total of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
// (end_i - start_i) + 1 entries are copied.
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1101
void constantPoolOopDesc::copy_cp_to_impl(constantPoolHandle from_cp, int start_i, int end_i,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
       constantPoolHandle to_cp, int to_i, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  int dest_i = to_i;  // leave original alone for debug purposes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1106
  for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1107
    copy_entry_to(from_cp, src_i, to_cp, dest_i, CHECK);
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
  1108
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1109
    switch (from_cp->tag_at(src_i).value()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
      // double and long take two constant pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
      src_i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
      dest_i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
      // all others take one constant pool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
      src_i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
      dest_i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
  }
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1124
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1125
  int from_oplen = operand_array_length(from_cp->operands());
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1126
  int old_oplen  = operand_array_length(to_cp->operands());
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1127
  if (from_oplen != 0) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1128
    // append my operands to the target's operands array
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1129
    if (old_oplen == 0) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1130
      to_cp->set_operands(from_cp->operands());  // reuse; do not merge
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1131
    } else {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1132
      int old_len  = to_cp->operands()->length();
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1133
      int from_len = from_cp->operands()->length();
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1134
      int old_off  = old_oplen * sizeof(u2);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1135
      int from_off = from_oplen * sizeof(u2);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1136
      typeArrayHandle new_operands = oopFactory::new_permanent_shortArray(old_len + from_len, CHECK);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1137
      int fillp = 0, len = 0;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1138
      // first part of dest
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1139
      Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1140
                                   new_operands->short_at_addr(fillp),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1141
                                   (len = old_off) * sizeof(u2));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1142
      fillp += len;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1143
      // first part of src
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1144
      Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(0),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1145
                                   new_operands->short_at_addr(fillp),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1146
                                   (len = from_off) * sizeof(u2));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1147
      fillp += len;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1148
      // second part of dest
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1149
      Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(old_off),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1150
                                   new_operands->short_at_addr(fillp),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1151
                                   (len = old_len - old_off) * sizeof(u2));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1152
      fillp += len;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1153
      // second part of src
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1154
      Copy::conjoint_memory_atomic(to_cp->operands()->short_at_addr(from_off),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1155
                                   new_operands->short_at_addr(fillp),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1156
                                   (len = from_len - from_off) * sizeof(u2));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1157
      fillp += len;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1158
      assert(fillp == new_operands->length(), "");
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1159
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1160
      // Adjust indexes in the first part of the copied operands array.
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1161
      for (int j = 0; j < from_oplen; j++) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1162
        int offset = operand_offset_at(new_operands(), old_oplen + j);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1163
        assert(offset == operand_offset_at(from_cp->operands(), j), "correct copy");
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1164
        offset += old_len;  // every new tuple is preceded by old_len extra u2's
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1165
        operand_offset_at_put(new_operands(), old_oplen + j, offset);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1166
      }
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1167
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1168
      // replace target operands array with combined array
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1169
      to_cp->set_operands(new_operands());
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1170
    }
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1171
  }
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1172
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
} // end copy_cp_to()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
// Copy this constant pool's entry at from_i to the constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
// to_cp's entry at to_i.
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1178
void constantPoolOopDesc::copy_entry_to(constantPoolHandle from_cp, int from_i,
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1179
                                        constantPoolHandle to_cp, int to_i,
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1180
                                        TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1182
  int tag = from_cp->tag_at(from_i).value();
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1183
  switch (tag) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1186
    klassOop k = from_cp->klass_at(from_i, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
    to_cp->klass_at_put(to_i, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1192
    jint ki = from_cp->klass_index_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
    to_cp->klass_index_at_put(to_i, ki);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1198
    jdouble d = from_cp->double_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    to_cp->double_at_put(to_i, d);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    // double takes two constant pool entries so init second entry's tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
  case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1206
    int class_index = from_cp->uncached_klass_ref_index_at(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1207
    int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    to_cp->field_at_put(to_i, class_index, name_and_type_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1213
    jfloat f = from_cp->float_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
    to_cp->float_at_put(to_i, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1219
    jint i = from_cp->int_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    to_cp->int_at_put(to_i, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
  case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1225
    int class_index = from_cp->uncached_klass_ref_index_at(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1226
    int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    to_cp->interface_method_at_put(to_i, class_index, name_and_type_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1232
    jlong l = from_cp->long_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    to_cp->long_at_put(to_i, l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    // long takes two constant pool entries so init second entry's tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1240
    int class_index = from_cp->uncached_klass_ref_index_at(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1241
    int name_and_type_index = from_cp->uncached_name_and_type_ref_index_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    to_cp->method_at_put(to_i, class_index, name_and_type_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1247
    int name_ref_index = from_cp->name_ref_index_at(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1248
    int signature_ref_index = from_cp->signature_ref_index_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
    to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1254
    oop s = from_cp->string_at(from_i, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
    to_cp->string_at_put(to_i, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1260
    jint si = from_cp->string_index_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    to_cp->string_index_at_put(to_i, si);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  {
8651
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1266
    // Can be resolved after checking tag, so check the slot first.
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1267
    CPSlot entry = from_cp->slot_at(from_i);
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1268
    if (entry.is_oop()) {
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1269
      assert(entry.get_oop()->is_klass(), "must be");
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1270
      // Already resolved
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1271
      to_cp->klass_at_put(to_i, (klassOop)entry.get_oop());
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1272
    } else {
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1273
      to_cp->unresolved_klass_at_put(to_i, entry.get_symbol());
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1274
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  case JVM_CONSTANT_UnresolvedClassInError:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
  {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1279
    Symbol* k = from_cp->unresolved_klass_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
    to_cp->unresolved_klass_at_put(to_i, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
    to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  {
8651
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1287
    // Can be resolved after checking tag, so check the slot first.
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1288
    CPSlot entry = from_cp->slot_at(from_i);
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1289
    if (entry.is_oop()) {
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1290
      // Already resolved (either string or pseudo-string)
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1291
      to_cp->string_at_put(to_i, entry.get_oop());
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1292
    } else {
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1293
      to_cp->unresolved_string_at_put(to_i, entry.get_symbol());
81b517a9249f 6512830: Error: assert(tag_at(which).is_unresolved_klass(), "Corrupted constant pool")
coleenp
parents: 8076
diff changeset
  1294
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1299
    Symbol* s = from_cp->symbol_at(from_i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    to_cp->symbol_at_put(to_i, s);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1301
    // This constantPool has the same lifetime as the original, so don't
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1302
    // increase reference counts for the copy.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1305
  case JVM_CONSTANT_MethodType:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1306
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1307
    jint k = from_cp->method_type_index_at(from_i);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1308
    to_cp->method_type_index_at_put(to_i, k);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1309
  } break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1310
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1311
  case JVM_CONSTANT_MethodHandle:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1312
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1313
    int k1 = from_cp->method_handle_ref_kind_at(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1314
    int k2 = from_cp->method_handle_index_at(from_i);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1315
    to_cp->method_handle_index_at_put(to_i, k1, k2);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1316
  } break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1317
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1318
  case JVM_CONSTANT_InvokeDynamic:
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1319
  {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1320
    int k1 = from_cp->invoke_dynamic_bootstrap_specifier_index(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1321
    int k2 = from_cp->invoke_dynamic_name_and_type_ref_index_at(from_i);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1322
    k1 += operand_array_length(to_cp->operands());  // to_cp might already have operands
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1323
    to_cp->invoke_dynamic_at_put(to_i, k1, k2);
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1324
  } break;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1325
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
  // Invalid is used as the tag for the second constant pool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
  // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  // not be seen by itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
  case JVM_CONSTANT_Invalid: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
} // end copy_entry_to()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
// Search constant pool search_cp for an entry that matches this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
// constant pool's entry at pattern_i. Returns the index of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
// matching entry or zero (0) if there is no matching entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
int constantPoolOopDesc::find_matching_entry(int pattern_i,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
      constantPoolHandle search_cp, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
  // index zero (0) is not used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
  for (int i = 1; i < search_cp->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    if (found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
      return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
  return 0;  // entry not found; return unused index zero (0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
} // end find_matching_entry()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
const char* constantPoolOopDesc::printable_name_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  constantTag tag = tag_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  if (tag.is_unresolved_string() || tag.is_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
    return string_at_noresolve(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
  } else if (tag.is_klass() || tag.is_unresolved_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    return klass_name_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
  } else if (tag.is_symbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    return symbol_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  return "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
// JVMTI GetConstantPool support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
// For temporary use until code is stable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
#define DBG(code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
static const char* WARN_MSG = "Must not be such entry!";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
static void print_cpool_bytes(jint cnt, u1 *bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
  jint size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
  u2   idx1, idx2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
  for (jint idx = 1; idx < cnt; idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
    jint ent_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    u1   tag  = *bytes++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
    size++;                       // count tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    printf("const #%03d, tag: %02d ", idx, tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
    switch(tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
      case JVM_CONSTANT_Invalid: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
        printf("Invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      case JVM_CONSTANT_Unicode: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
        printf("Unicode      %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
      case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
        u2 len = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
        char str[128];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
        if (len > 127) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
           len = 127;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
        strncpy(str, (char *) (bytes+2), len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
        str[len] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
        printf("Utf8          \"%s\"", str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
        ent_size = 2 + len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
      case JVM_CONSTANT_Integer: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
        u4 val = Bytes::get_Java_u4(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
        printf("int          %d", *(int *) &val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
      case JVM_CONSTANT_Float: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
        u4 val = Bytes::get_Java_u4(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
        printf("float        %5.3ff", *(float *) &val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
      case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
        u8 val = Bytes::get_Java_u8(bytes);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 10008
diff changeset
  1428
        printf("long         "INT64_FORMAT, (int64_t) *(jlong *) &val);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
        ent_size = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
        idx++; // Long takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
      case JVM_CONSTANT_Double: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
        u8 val = Bytes::get_Java_u8(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
        printf("double       %5.3fd", *(jdouble *)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
        ent_size = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
        idx++; // Double takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
      case JVM_CONSTANT_Class: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
        printf("class        #%03d", idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
        ent_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
      case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
        printf("String       #%03d", idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
        ent_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
      case JVM_CONSTANT_Fieldref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
        printf("Field        #%03d, #%03d", (int) idx1, (int) idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
      case JVM_CONSTANT_Methodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
        printf("Method       #%03d, #%03d", idx1, idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
      case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
        printf("InterfMethod #%03d, #%03d", idx1, idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
      case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
        printf("NameAndType  #%03d, #%03d", idx1, idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
      case JVM_CONSTANT_ClassIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
        printf("ClassIndex  %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
      case JVM_CONSTANT_UnresolvedClass: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
        printf("UnresolvedClass: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
      case JVM_CONSTANT_UnresolvedClassInError: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
        printf("UnresolvedClassInErr: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
      case JVM_CONSTANT_StringIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
        printf("StringIndex: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
      case JVM_CONSTANT_UnresolvedString: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
        printf("UnresolvedString: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
    printf(";\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
    bytes += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    size  += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
  printf("Cpool size: %d\n", size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
  fflush(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
} /* end print_cpool_bytes */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
// Returns size of constant pool entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
jint constantPoolOopDesc::cpool_entry_size(jint idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
  switch(tag_at(idx).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
    case JVM_CONSTANT_Invalid:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
    case JVM_CONSTANT_Unicode:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
      return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
    case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
      return 3 + symbol_at(idx)->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
    case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
    case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
    case JVM_CONSTANT_UnresolvedClassInError:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
    case JVM_CONSTANT_UnresolvedString:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1528
    case JVM_CONSTANT_MethodType:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
      return 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1531
    case JVM_CONSTANT_MethodHandle:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1532
      return 4; //tag, ref_kind, ref_index
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1533
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
    case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
    case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
    case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
    case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
    case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
    case JVM_CONSTANT_NameAndType:
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
  1540
      return 5;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 7111
diff changeset
  1541
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1542
    case JVM_CONSTANT_InvokeDynamic:
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1543
      // u1 tag, u2 bsm, u2 nt
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1544
      return 5;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
      return 9;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
  assert(false, "cpool_entry_size: Invalid constant pool entry tag");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
  return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
} /* end cpool_entry_size */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
// SymbolHashMap is used to find a constant pool index from a string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
// This function fills in SymbolHashMaps, one for utf8s and one for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
// class names, returns size of the cpool raw bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
                                          SymbolHashMap *classmap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
  jint size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
  for (u2 idx = 1; idx < length(); idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
    u2 tag = tag_at(idx).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
    size += cpool_entry_size(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
    switch(tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
      case JVM_CONSTANT_Utf8: {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1568
        Symbol* sym = symbol_at(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
        symmap->add_entry(sym, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
        DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
      case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
      case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
      case JVM_CONSTANT_UnresolvedClassInError: {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1576
        Symbol* sym = klass_name_at(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
        classmap->add_entry(sym, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
        DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
      case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
      case JVM_CONSTANT_Double: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
        idx++; // Both Long and Double take two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
  return size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
} /* end hash_utf8_entries_to */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
// Copy cpool bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
// Returns:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
//    0, in case of OutOfMemoryError
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
//   -1, in case of internal error
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
//  > 0, count of the raw cpool bytes that have been copied
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
int constantPoolOopDesc::copy_cpool_bytes(int cpool_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
                                          SymbolHashMap* tbl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
                                          unsigned char *bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  u2   idx1, idx2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
  jint size  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  jint cnt   = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
  unsigned char *start_bytes = bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  for (jint idx = 1; idx < cnt; idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
    u1   tag      = tag_at(idx).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    jint ent_size = cpool_entry_size(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
    assert(size + ent_size <= cpool_size, "Size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
    *bytes = tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
    DBG(printf("#%03hd tag=%03hd, ", idx, tag));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
    switch(tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
      case JVM_CONSTANT_Invalid: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
        DBG(printf("JVM_CONSTANT_Invalid"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
      case JVM_CONSTANT_Unicode: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
        assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
        DBG(printf("JVM_CONSTANT_Unicode"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
      case JVM_CONSTANT_Utf8: {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1624
        Symbol* sym = symbol_at(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
        char*     str = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
        // Warning! It's crashing on x86 with len = sym->utf8_length()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
        int       len = (int) strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
        Bytes::put_Java_u2((address) (bytes+1), (u2) len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
        for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
            bytes[3+i] = (u1) str[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
        DBG(printf("JVM_CONSTANT_Utf8: %s ", str));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
      case JVM_CONSTANT_Integer: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
        jint val = int_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
        Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
      case JVM_CONSTANT_Float: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
        jfloat val = float_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
        Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
      case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
        jlong val = long_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
        Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
        idx++;             // Long takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
      case JVM_CONSTANT_Double: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
        jdouble val = double_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
        Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
        idx++;             // Double takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
      case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
      case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
      case JVM_CONSTANT_UnresolvedClassInError: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
        *bytes = JVM_CONSTANT_Class;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1661
        Symbol* sym = klass_name_at(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
        idx1 = tbl->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
        assert(idx1 != 0, "Have not found a hashtable entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
        DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
      case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
        unsigned int hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
        char *str = string_at_noresolve(idx);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1671
        TempNewSymbol sym = SymbolTable::lookup_only(str, (int) strlen(str), hash);
2860
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1672
        if (sym == NULL) {
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1673
          // sym can be NULL if string refers to incorrectly encoded JVM_CONSTANT_Utf8
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1674
          // this can happen with JVM TI; see CR 6839599 for more details
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1675
          oop string = *(obj_at_addr_raw(idx));
2860
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1676
          assert(java_lang_String::is_instance(string),"Not a String");
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1677
          DBG(printf("Error #%03hd tag=%03hd\n", idx, tag));
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1678
          idx1 = 0;
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1679
          for (int j = 0; j < tbl->table_size() && idx1 == 0; j++) {
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1680
            for (SymbolHashMapEntry* cur = tbl->bucket(j); cur != NULL; cur = cur->next()) {
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1681
              int length;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1682
              Symbol* s = cur->symbol();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1683
              jchar* chars = s->as_unicode(length);
2860
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1684
              if (java_lang_String::equals(string, chars, length)) {
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1685
                idx1 = cur->value();
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1686
                DBG(printf("Index found: %d\n",idx1));
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1687
                break;
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1688
              }
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1689
            }
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1690
          }
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1691
        } else {
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1692
          idx1 = tbl->symbol_to_value(sym);
cf13b84eb2f9 6839599: JVM crash while profiling Tomcat and Liferay
thurka
parents: 2570
diff changeset
  1693
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
        assert(idx1 != 0, "Have not found a hashtable entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
        DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
      case JVM_CONSTANT_UnresolvedString: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
        *bytes = JVM_CONSTANT_String;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1701
        Symbol* sym = unresolved_string_at(idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
        idx1 = tbl->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
        assert(idx1 != 0, "Have not found a hashtable entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
        DBG(char *str = sym->as_utf8());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
        DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
      case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
      case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
      case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
        idx1 = uncached_klass_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
        idx2 = uncached_name_and_type_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
        Bytes::put_Java_u2((address) (bytes+3), idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
        DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
      case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
        idx1 = name_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
        idx2 = signature_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
        Bytes::put_Java_u2((address) (bytes+3), idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
        DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
      case JVM_CONSTANT_ClassIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
        *bytes = JVM_CONSTANT_Class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
        idx1 = klass_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
        DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
      case JVM_CONSTANT_StringIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
        *bytes = JVM_CONSTANT_String;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
        idx1 = string_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
        DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
      }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1741
      case JVM_CONSTANT_MethodHandle: {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1742
        *bytes = JVM_CONSTANT_MethodHandle;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1743
        int kind = method_handle_ref_kind_at(idx);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1744
        idx1 = method_handle_index_at(idx);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1745
        *(bytes+1) = (unsigned char) kind;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1746
        Bytes::put_Java_u2((address) (bytes+2), idx1);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1747
        DBG(printf("JVM_CONSTANT_MethodHandle: %d %hd", kind, idx1));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1748
        break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1749
      }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1750
      case JVM_CONSTANT_MethodType: {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1751
        *bytes = JVM_CONSTANT_MethodType;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1752
        idx1 = method_type_index_at(idx);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1753
        Bytes::put_Java_u2((address) (bytes+1), idx1);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1754
        DBG(printf("JVM_CONSTANT_MethodType: %hd", idx1));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1755
        break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
  1756
      }
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1757
      case JVM_CONSTANT_InvokeDynamic: {
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1758
        *bytes = tag;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1759
        idx1 = extract_low_short_from_int(*int_at_addr(idx));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1760
        idx2 = extract_high_short_from_int(*int_at_addr(idx));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1761
        assert(idx2 == invoke_dynamic_name_and_type_ref_index_at(idx), "correct half of u4");
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1762
        Bytes::put_Java_u2((address) (bytes+1), idx1);
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1763
        Bytes::put_Java_u2((address) (bytes+3), idx2);
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7397
diff changeset
  1764
        DBG(printf("JVM_CONSTANT_InvokeDynamic: %hd %hd", idx1, idx2));
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1765
        break;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
  1766
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
    DBG(printf("\n"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
    bytes += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
    size  += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  assert(size == cpool_size, "Size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
  // Keep temorarily for debugging until it's stable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  DBG(print_cpool_bytes(cnt, start_bytes));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  return (int)(bytes - start_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
} /* end copy_cpool_bytes */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1780
void SymbolHashMap::add_entry(Symbol* sym, u2 value) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
  char *str = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  unsigned int hash = compute_hash(str, sym->utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
  unsigned int index = hash % table_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  // check if already in map
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  // we prefer the first entry since it is more likely to be what was used in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
  // the class file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
  for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
    assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
    if (en->hash() == hash && en->symbol() == sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
        return;  // already there
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
  SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  entry->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
  _buckets[index].set_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
  1801
SymbolHashMapEntry* SymbolHashMap::find_entry(Symbol* sym) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
  assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
  char *str = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
  int   len = sym->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
  unsigned int hash = SymbolHashMap::compute_hash(str, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
  unsigned int index = hash % table_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
  for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
    assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
    if (en->hash() == hash && en->symbol() == sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
      return en;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
}