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