hotspot/src/share/vm/oops/constantPoolOop.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 1550 be2fc37a817f
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
klassOop constantPoolOopDesc::klass_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // 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
    31
  // tag is not updated atomicly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  oop entry = *(this_oop->obj_at_addr(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  if (entry->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    // Already resolved - return entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    return (klassOop)entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // 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
    39
  // already has updated the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  assert(THREAD->is_Java_thread(), "must be a Java thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  bool do_resolve = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  bool in_error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  symbolHandle name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  Handle       loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  { ObjectLocker ol(this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    if (this_oop->tag_at(which).is_unresolved_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
        in_error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
        do_resolve = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
        name   = symbolHandle(THREAD, this_oop->unresolved_klass_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
        loader = Handle(THREAD, instanceKlass::cast(this_oop->pool_holder())->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  } // unlocking constantPool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // The original attempt to resolve this constant pool entry failed so find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // original error and throw it again (JVMS 5.4.3).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  if (in_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    symbolOop error = SystemDictionary::find_resolution_error(this_oop, which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    guarantee(error != (symbolOop)NULL, "tag mismatch with resolution error table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    // exception text will be the class name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    THROW_MSG_0(error, className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  if (do_resolve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    // this_oop must be unlocked during resolve_or_fail
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    Handle h_prot (THREAD, protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    klassOop k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    KlassHandle k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    if (!HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      k = KlassHandle(THREAD, k_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      // Do access check for klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      verify_constant_pool_resolve(this_oop, k, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // Failed to resolve class. We must record the errors so that subsequent attempts
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      symbolHandle error(PENDING_EXCEPTION->klass()->klass_part()->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      bool throw_orig_error = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        ObjectLocker ol (this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        // some other thread has beaten us and has resolved the class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        if (this_oop->tag_at(which).is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
          CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
          entry = this_oop->resolved_klass_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
          return (klassOop)entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        if (!PENDING_EXCEPTION->
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
              is_a(SystemDictionary::linkageError_klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
          // Just throw the exception and don't prevent these classes from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
          // being loaded due to virtual machine errors like StackOverflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
          // and OutOfMemoryError, etc, or if the thread was hit by stop()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
          // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
          SystemDictionary::add_resolution_error(this_oop, which, error);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
          this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
          // some other thread has put the class in error state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
          error = symbolHandle(SystemDictionary::find_resolution_error(this_oop, which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
          assert(!error.is_null(), "checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
          throw_orig_error = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      } // unlocked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      if (throw_orig_error) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        THROW_MSG_0(error, className);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    if (TraceClassResolution && !k()->klass_part()->oop_is_array()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      // skip resolving the constant pool so that this code get's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      // called the next time some bytecodes refer to this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      int line_number = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      const char * source_file = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      if (JavaThread::current()->has_last_Java_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        // try to identify the method which called this function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        vframeStream vfst(JavaThread::current());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        if (!vfst.at_end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
          line_number = vfst.method()->line_number_from_bci(vfst.bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
          symbolOop s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
          if (s != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
            source_file = s->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      if (k() != this_oop->pool_holder()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        // only print something if the classes are different
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        if (source_file != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
          tty->print("RESOLVE %s %s %s:%d\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
                     instanceKlass::cast(this_oop->pool_holder())->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
                     instanceKlass::cast(k())->external_name(), source_file, line_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
          tty->print("RESOLVE %s %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
                     instanceKlass::cast(this_oop->pool_holder())->external_name(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                     instanceKlass::cast(k())->external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      ObjectLocker ol (this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      // Only updated constant pool - if it is resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      do_resolve = this_oop->tag_at(which).is_unresolved_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      if (do_resolve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        this_oop->klass_at_put(which, k());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  entry = this_oop->resolved_klass_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  assert(entry->is_klass(), "must be resolved at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return (klassOop)entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// Does not update constantPoolOop - to avoid any exception throwing. Used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// by compiler and exception handling.  Also used to avoid classloads for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// instanceof operations. Returns NULL if the class has not been loaded or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// if the verification of constant pool failed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
klassOop constantPoolOopDesc::klass_at_if_loaded(constantPoolHandle this_oop, int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  oop entry = *this_oop->obj_at_addr(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if (entry->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    return (klassOop)entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    assert(entry->is_symbol(), "must be either symbol or klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    symbolHandle name (thread, (symbolOop)entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    Handle h_prot (thread, protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    Handle h_loader (thread, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    klassOop k = SystemDictionary::find(name, h_loader, h_prot, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      // Make sure that resolving is legal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      KlassHandle klass(THREAD, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      // return NULL if verification fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      verify_constant_pool_resolve(this_oop, klass, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
        return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      return klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
klassOop constantPoolOopDesc::klass_ref_at_if_loaded(constantPoolHandle this_oop, int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  return klass_at_if_loaded(this_oop, this_oop->klass_ref_index_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
// This is an interface for the compiler that allows accessing non-resolved entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
// in the constant pool - but still performs the validations tests. Must be used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// in a pre-parse of the compiler - to determine what it can do and not do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
// Note: We cannot update the ConstantPool from the vm_thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
klassOop constantPoolOopDesc::klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int index, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  int which = this_oop->klass_ref_index_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  oop entry = *this_oop->obj_at_addr(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (entry->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return (klassOop)entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    assert(entry->is_symbol(), "must be either symbol or klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    symbolHandle name (THREAD, (symbolOop)entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    oop loader = instanceKlass::cast(this_oop->pool_holder())->class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    oop protection_domain = Klass::cast(this_oop->pool_holder())->protection_domain();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    Handle h_loader(THREAD, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    Handle h_prot  (THREAD, protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    KlassHandle k(THREAD, SystemDictionary::find(name, h_loader, h_prot, THREAD));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    // Do access check for klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    if( k.not_null() ) verify_constant_pool_resolve(this_oop, k, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    return k();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
symbolOop constantPoolOopDesc::uncached_name_ref_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  jint ref_index = name_and_type_at(uncached_name_and_type_ref_index_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  int name_index = extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  return symbol_at(name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
symbolOop constantPoolOopDesc::uncached_signature_ref_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  jint ref_index = name_and_type_at(uncached_name_and_type_ref_index_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  int signature_index = extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  return symbol_at(signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
int constantPoolOopDesc::uncached_name_and_type_ref_index_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  jint ref_index = field_or_method_at(which, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  return extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
int constantPoolOopDesc::uncached_klass_ref_index_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  jint ref_index = field_or_method_at(which, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  return extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
void constantPoolOopDesc::verify_constant_pool_resolve(constantPoolHandle this_oop, KlassHandle k, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
 if (k->oop_is_instance() || k->oop_is_objArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    instanceKlassHandle holder (THREAD, this_oop->pool_holder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    klassOop elem_oop = k->oop_is_instance() ? k() : objArrayKlass::cast(k())->bottom_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    KlassHandle element (THREAD, elem_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    // The element type could be a typeArray - we only need the access check if it is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    // an reference to another class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (element->oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      LinkResolver::check_klass_accessability(holder, element, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
int constantPoolOopDesc::klass_ref_index_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  jint ref_index = field_or_method_at(which, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  return extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
int constantPoolOopDesc::name_and_type_ref_index_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  jint ref_index = field_or_method_at(which, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  return extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
int constantPoolOopDesc::name_ref_index_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  jint ref_index = name_and_type_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  return extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
int constantPoolOopDesc::signature_ref_index_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  jint ref_index = name_and_type_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  return extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
klassOop constantPoolOopDesc::klass_ref_at(int which, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  return klass_at(klass_ref_index_at(which), CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
symbolOop constantPoolOopDesc::klass_name_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  assert(tag_at(which).is_unresolved_klass() || tag_at(which).is_klass(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
         "Corrupted constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  // A resolved constantPool entry will contain a klassOop, otherwise a symbolOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  // 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
   315
  // tag is not updated atomicly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  oop entry = *(obj_at_addr(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  if (entry->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    // Already resolved - return entry's name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    return klassOop(entry)->klass_part()->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    assert(entry->is_symbol(), "must be either symbol or klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    return (symbolOop)entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
symbolOop constantPoolOopDesc::klass_ref_at_noresolve(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  jint ref_index = klass_ref_index_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  return klass_at_noresolve(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
char* constantPoolOopDesc::string_at_noresolve(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // Test entry type in case string is resolved while in here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  oop entry = *(obj_at_addr(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  if (entry->is_symbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    return ((symbolOop)entry)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    return java_lang_String::as_utf8_string(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
symbolOop constantPoolOopDesc::name_ref_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  jint ref_index = name_and_type_at(name_and_type_ref_index_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  int name_index = extract_low_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  return symbol_at(name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
symbolOop constantPoolOopDesc::signature_ref_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  jint ref_index = name_and_type_at(name_and_type_ref_index_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  int signature_index = extract_high_short_from_int(ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  return symbol_at(signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
BasicType constantPoolOopDesc::basic_type_for_signature_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  return FieldType::basic_type(symbol_at(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
void constantPoolOopDesc::resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  for (int index = 1; index < this_oop->length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    if (this_oop->tag_at(index).is_unresolved_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      this_oop->string_at(index, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
oop constantPoolOopDesc::string_at_impl(constantPoolHandle this_oop, int which, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  oop entry = *(this_oop->obj_at_addr(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  if (entry->is_symbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    ObjectLocker ol(this_oop, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if (this_oop->tag_at(which).is_unresolved_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      // Intern string
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      symbolOop sym = this_oop->unresolved_string_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      entry = StringTable::intern(sym, CHECK_(constantPoolOop(NULL)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      this_oop->string_at_put(which, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      // Another thread beat us and interned string, read string from constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      entry = this_oop->resolved_string_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  assert(java_lang_String::is_instance(entry), "must be string");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  return entry;
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
bool constantPoolOopDesc::klass_name_at_matches(instanceKlassHandle k,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
                                                int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // Names are interned, so we can compare symbolOops directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  symbolOop cp_name = klass_name_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  return (cp_name == k->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
int constantPoolOopDesc::pre_resolve_shared_klasses(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  for (int index = 1; index < tags()->length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    if (tag_at(index).is_unresolved_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      // Intern string
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      symbolOop sym = unresolved_string_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      oop entry = StringTable::intern(sym, CHECK_(-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      string_at_put(index, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  return count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// Iterate over symbols which are used as class, field, method names and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
// signatures (in preparation for writing to the shared archive).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
void constantPoolOopDesc::shared_symbols_iterate(OopClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  for (int index = 1; index < length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    switch (tag_at(index).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      closure->do_oop(obj_at_addr(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        int i = *int_at_addr(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        closure->do_oop(obj_at_addr((unsigned)i >> 16));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        closure->do_oop(obj_at_addr((unsigned)i & 0xffff));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      // Do nothing!  Not an oop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      // These constant types do not reference symbols at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      // Do nothing!  Not a symbol.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      // These constants are symbols, but unless these symbols are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      // actually to be used for something, we don't want to mark them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      // Do nothing!  Not an oop. (But takes two pool entries.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
// Iterate over the [one] tags array (in preparation for writing to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
// shared archive).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
void constantPoolOopDesc::shared_tags_iterate(OopClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  closure->do_oop(tags_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
// Iterate over String objects (in preparation for writing to the shared
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
// archive).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
void constantPoolOopDesc::shared_strings_iterate(OopClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  for (int index = 1; index < length(); index++) { // Index 0 is unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    switch (tag_at(index).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      // Do nothing!  Not a String.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
      // Do nothing!  Not an oop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      // These constant types do not reference symbols at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
      closure->do_oop(obj_at_addr(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
      // These constants are symbols, but unless these symbols are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
      // actually to be used for something, we don't want to mark them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
      // Do nothing!  Not an oop. (But takes two pool entries.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
// Compare this constant pool's entry at index1 to the constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
// cp2's entry at index2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
bool constantPoolOopDesc::compare_entry_to(int index1, constantPoolHandle cp2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
       int index2, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  jbyte t1 = tag_at(index1).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  jbyte t2 = cp2->tag_at(index2).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  // JVM_CONSTANT_UnresolvedClassInError is equal to JVM_CONSTANT_UnresolvedClass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // when comparing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  if (t1 == JVM_CONSTANT_UnresolvedClassInError) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    t1 = JVM_CONSTANT_UnresolvedClass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  if (t2 == JVM_CONSTANT_UnresolvedClassInError) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    t2 = JVM_CONSTANT_UnresolvedClass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  if (t1 != t2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    // Not the same entry type so there is nothing else to check. Note
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    // that this style of checking will consider resolved/unresolved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    // class pairs and resolved/unresolved string pairs as different.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    // From the constantPoolOop API point of view, this is correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    // behavior. See constantPoolKlass::merge() to see how this plays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    // out in the context of constantPoolOop merging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  switch (t1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    klassOop k1 = klass_at(index1, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    klassOop k2 = cp2->klass_at(index2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    if (k1 == k2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    int recur1 = klass_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    int recur2 = cp2->klass_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    jdouble d1 = double_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
    jdouble d2 = cp2->double_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    if (d1 == d2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    int recur1 = uncached_klass_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    int recur2 = cp2->uncached_klass_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
      recur1 = uncached_name_and_type_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
      recur2 = cp2->uncached_name_and_type_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    jfloat f1 = float_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    jfloat f2 = cp2->float_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    if (f1 == f2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    jint i1 = int_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    jint i2 = cp2->int_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    if (i1 == i2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
    jlong l1 = long_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    jlong l2 = cp2->long_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    if (l1 == l2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    int recur1 = name_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    int recur2 = cp2->name_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
      recur1 = signature_ref_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      recur2 = cp2->signature_ref_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
      if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    oop s1 = string_at(index1, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    oop s2 = cp2->string_at(index2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    if (s1 == s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    int recur1 = string_index_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    int recur2 = cp2->string_index_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    bool match = compare_entry_to(recur1, cp2, recur2, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    symbolOop k1 = unresolved_klass_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    symbolOop k2 = cp2->unresolved_klass_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    if (k1 == k2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    symbolOop s1 = unresolved_string_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    symbolOop s2 = cp2->unresolved_string_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    if (s1 == s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    symbolOop s1 = symbol_at(index1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    symbolOop s2 = cp2->symbol_at(index2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    if (s1 == s2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  // Invalid is used as the tag for the second constant pool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  // not be seen by itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  case JVM_CONSTANT_Invalid: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
} // end compare_entry_to()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
// Copy this constant pool's entries at start_i to end_i (inclusive)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
// to the constant pool to_cp's entries starting at to_i. A total of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
// (end_i - start_i) + 1 entries are copied.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
void constantPoolOopDesc::copy_cp_to(int start_i, int end_i,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
       constantPoolHandle to_cp, int to_i, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  int dest_i = to_i;  // leave original alone for debug purposes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  for (int src_i = start_i; src_i <= end_i; /* see loop bottom */ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    copy_entry_to(src_i, to_cp, dest_i, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    switch (tag_at(src_i).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      // double and long take two constant pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
      src_i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
      dest_i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
      // all others take one constant pool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
      src_i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
      dest_i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
} // end copy_cp_to()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
// Copy this constant pool's entry at from_i to the constant pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
// to_cp's entry at to_i.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
void constantPoolOopDesc::copy_entry_to(int from_i, constantPoolHandle to_cp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
       int to_i, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  switch (tag_at(from_i).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    klassOop k = klass_at(from_i, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
    to_cp->klass_at_put(to_i, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    jint ki = klass_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    to_cp->klass_index_at_put(to_i, ki);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    jdouble d = double_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    to_cp->double_at_put(to_i, d);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    // double takes two constant pool entries so init second entry's tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    int class_index = uncached_klass_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
    int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    to_cp->field_at_put(to_i, class_index, name_and_type_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    jfloat f = float_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    to_cp->float_at_put(to_i, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    jint i = int_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    to_cp->int_at_put(to_i, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    int class_index = uncached_klass_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    to_cp->interface_method_at_put(to_i, class_index, name_and_type_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    jlong l = long_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    to_cp->long_at_put(to_i, l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    // long takes two constant pool entries so init second entry's tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    to_cp->tag_at_put(to_i + 1, JVM_CONSTANT_Invalid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    int class_index = uncached_klass_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    int name_and_type_index = uncached_name_and_type_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    to_cp->method_at_put(to_i, class_index, name_and_type_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    int name_ref_index = name_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    int signature_ref_index = signature_ref_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    to_cp->name_and_type_at_put(to_i, name_ref_index, signature_ref_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    oop s = string_at(from_i, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    to_cp->string_at_put(to_i, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    jint si = string_index_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    to_cp->string_index_at_put(to_i, si);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
    symbolOop k = unresolved_klass_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    to_cp->unresolved_klass_at_put(to_i, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  case JVM_CONSTANT_UnresolvedClassInError:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    symbolOop k = unresolved_klass_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    to_cp->unresolved_klass_at_put(to_i, k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
    to_cp->tag_at_put(to_i, JVM_CONSTANT_UnresolvedClassInError);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    symbolOop s = unresolved_string_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    to_cp->unresolved_string_at_put(to_i, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    symbolOop s = symbol_at(from_i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    to_cp->symbol_at_put(to_i, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  // Invalid is used as the tag for the second constant pool entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  // not be seen by itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  case JVM_CONSTANT_Invalid: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    jbyte bad_value = tag_at(from_i).value(); // leave a breadcrumb
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  } break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
} // end copy_entry_to()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
// Search constant pool search_cp for an entry that matches this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
// constant pool's entry at pattern_i. Returns the index of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
// matching entry or zero (0) if there is no matching entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
int constantPoolOopDesc::find_matching_entry(int pattern_i,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
      constantPoolHandle search_cp, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // index zero (0) is not used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  for (int i = 1; i < search_cp->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    bool found = compare_entry_to(pattern_i, search_cp, i, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    if (found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  return 0;  // entry not found; return unused index zero (0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
} // end find_matching_entry()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
const char* constantPoolOopDesc::printable_name_at(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  constantTag tag = tag_at(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  if (tag.is_unresolved_string() || tag.is_string()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    return string_at_noresolve(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  } else if (tag.is_klass() || tag.is_unresolved_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    return klass_name_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  } else if (tag.is_symbol()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    return symbol_at(which)->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  return "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
// JVMTI GetConstantPool support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
// For temporary use until code is stable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
#define DBG(code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
static const char* WARN_MSG = "Must not be such entry!";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
static void print_cpool_bytes(jint cnt, u1 *bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  jint size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  u2   idx1, idx2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  for (jint idx = 1; idx < cnt; idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    jint ent_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    u1   tag  = *bytes++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    size++;                       // count tag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    printf("const #%03d, tag: %02d ", idx, tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
    switch(tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
      case JVM_CONSTANT_Invalid: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
        printf("Invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
      case JVM_CONSTANT_Unicode: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
        printf("Unicode      %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
        u2 len = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
        char str[128];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
        if (len > 127) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
           len = 127;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
        strncpy(str, (char *) (bytes+2), len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
        str[len] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
        printf("Utf8          \"%s\"", str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
        ent_size = 2 + len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
      case JVM_CONSTANT_Integer: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
        u4 val = Bytes::get_Java_u4(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
        printf("int          %d", *(int *) &val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      case JVM_CONSTANT_Float: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
        u4 val = Bytes::get_Java_u4(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
        printf("float        %5.3ff", *(float *) &val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
      case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
        u8 val = Bytes::get_Java_u8(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
        printf("long         %lldl", *(jlong *) &val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
        ent_size = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
        idx++; // Long takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
      case JVM_CONSTANT_Double: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
        u8 val = Bytes::get_Java_u8(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
        printf("double       %5.3fd", *(jdouble *)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
        ent_size = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
        idx++; // Double takes two cpool slots
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_Class: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
        printf("class        #%03d", idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
        ent_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
        printf("String       #%03d", idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
        ent_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
      case JVM_CONSTANT_Fieldref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
        printf("Field        #%03d, #%03d", (int) idx1, (int) idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
      case JVM_CONSTANT_Methodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
        printf("Method       #%03d, #%03d", idx1, idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
        printf("InterfMethod #%03d, #%03d", idx1, idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
      case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
        idx1 = Bytes::get_Java_u2(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
        idx2 = Bytes::get_Java_u2(bytes+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
        printf("NameAndType  #%03d, #%03d", idx1, idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
        ent_size = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      case JVM_CONSTANT_ClassIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
        printf("ClassIndex  %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
      case JVM_CONSTANT_UnresolvedClass: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
        printf("UnresolvedClass: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
      case JVM_CONSTANT_UnresolvedClassInError: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
        printf("UnresolvedClassInErr: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
      case JVM_CONSTANT_StringIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
        printf("StringIndex: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      case JVM_CONSTANT_UnresolvedString: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
        printf("UnresolvedString: %s", WARN_MSG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    printf(";\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    bytes += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
    size  += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  printf("Cpool size: %d\n", size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  fflush(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
} /* end print_cpool_bytes */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
// Returns size of constant pool entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
jint constantPoolOopDesc::cpool_entry_size(jint idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  switch(tag_at(idx).value()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    case JVM_CONSTANT_Invalid:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    case JVM_CONSTANT_Unicode:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
      return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
      return 3 + symbol_at(idx)->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    case JVM_CONSTANT_String:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    case JVM_CONSTANT_UnresolvedClassInError:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
      return 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
      return 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
      return 9;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
  assert(false, "cpool_entry_size: Invalid constant pool entry tag");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
} /* end cpool_entry_size */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
// SymbolHashMap is used to find a constant pool index from a string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
// This function fills in SymbolHashMaps, one for utf8s and one for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
// class names, returns size of the cpool raw bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
jint constantPoolOopDesc::hash_entries_to(SymbolHashMap *symmap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
                                          SymbolHashMap *classmap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  jint size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  for (u2 idx = 1; idx < length(); idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    u2 tag = tag_at(idx).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    size += cpool_entry_size(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    switch(tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
        symbolOop sym = symbol_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
        symmap->add_entry(sym, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
        DBG(printf("adding symbol entry %s = %d\n", sym->as_utf8(), idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
      case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
      case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
      case JVM_CONSTANT_UnresolvedClassInError: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
        symbolOop sym = klass_name_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
        classmap->add_entry(sym, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
        DBG(printf("adding class entry %s = %d\n", sym->as_utf8(), idx));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
      case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
      case JVM_CONSTANT_Double: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
        idx++; // Both Long and Double take two cpool slots
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
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
  return size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
} /* end hash_utf8_entries_to */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
// Copy cpool bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
// Returns:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
//    0, in case of OutOfMemoryError
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
//   -1, in case of internal error
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
//  > 0, count of the raw cpool bytes that have been copied
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
int constantPoolOopDesc::copy_cpool_bytes(int cpool_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
                                          SymbolHashMap* tbl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
                                          unsigned char *bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
  u2   idx1, idx2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
  jint size  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  jint cnt   = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  unsigned char *start_bytes = bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  for (jint idx = 1; idx < cnt; idx++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    u1   tag      = tag_at(idx).value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
    jint ent_size = cpool_entry_size(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
    assert(size + ent_size <= cpool_size, "Size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
    *bytes = tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
    DBG(printf("#%03hd tag=%03hd, ", idx, tag));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
    switch(tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      case JVM_CONSTANT_Invalid: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
        DBG(printf("JVM_CONSTANT_Invalid"));
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_Unicode: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
        assert(false, "Wrong constant pool tag: JVM_CONSTANT_Unicode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
        DBG(printf("JVM_CONSTANT_Unicode"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
      case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
        symbolOop sym = symbol_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
        char*     str = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
        // Warning! It's crashing on x86 with len = sym->utf8_length()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
        int       len = (int) strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
        Bytes::put_Java_u2((address) (bytes+1), (u2) len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
        for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
            bytes[3+i] = (u1) str[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
        DBG(printf("JVM_CONSTANT_Utf8: %s ", str));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
      case JVM_CONSTANT_Integer: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
        jint val = int_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
        Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
      case JVM_CONSTANT_Float: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
        jfloat val = float_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
        Bytes::put_Java_u4((address) (bytes+1), *(u4*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
      case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
        jlong val = long_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
        Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
        idx++;             // Long takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      case JVM_CONSTANT_Double: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
        jdouble val = double_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
        Bytes::put_Java_u8((address) (bytes+1), *(u8*)&val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
        idx++;             // Double takes two cpool slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
      case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
      case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
      case JVM_CONSTANT_UnresolvedClassInError: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
        *bytes = JVM_CONSTANT_Class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
        symbolOop sym = klass_name_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
        idx1 = tbl->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
        assert(idx1 != 0, "Have not found a hashtable entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
        DBG(printf("JVM_CONSTANT_Class: idx=#%03hd, %s", idx1, sym->as_utf8()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
      case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
        unsigned int hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
        char *str = string_at_noresolve(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
        symbolOop sym = SymbolTable::lookup_only(str, (int) strlen(str), hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
        idx1 = tbl->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
        assert(idx1 != 0, "Have not found a hashtable entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
        DBG(printf("JVM_CONSTANT_String: idx=#%03hd, %s", idx1, str));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
      case JVM_CONSTANT_UnresolvedString: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
        *bytes = JVM_CONSTANT_String;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
        symbolOop sym = unresolved_string_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
        idx1 = tbl->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
        assert(idx1 != 0, "Have not found a hashtable entry");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
        DBG(char *str = sym->as_utf8());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
        DBG(printf("JVM_CONSTANT_UnresolvedString: idx=#%03hd, %s", idx1, str));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
      case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
      case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
      case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
        idx1 = uncached_klass_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
        idx2 = uncached_name_and_type_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
        Bytes::put_Java_u2((address) (bytes+3), idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
        DBG(printf("JVM_CONSTANT_Methodref: %hd %hd", idx1, idx2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
      case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
        idx1 = name_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
        idx2 = signature_ref_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
        Bytes::put_Java_u2((address) (bytes+3), idx2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
        DBG(printf("JVM_CONSTANT_NameAndType: %hd %hd", idx1, idx2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      case JVM_CONSTANT_ClassIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
        *bytes = JVM_CONSTANT_Class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
        idx1 = klass_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
        DBG(printf("JVM_CONSTANT_ClassIndex: %hd", idx1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
      case JVM_CONSTANT_StringIndex: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
        *bytes = JVM_CONSTANT_String;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
        idx1 = string_index_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
        Bytes::put_Java_u2((address) (bytes+1), idx1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
        DBG(printf("JVM_CONSTANT_StringIndex: %hd", idx1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    DBG(printf("\n"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    bytes += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    size  += ent_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  assert(size == cpool_size, "Size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  // Keep temorarily for debugging until it's stable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  DBG(print_cpool_bytes(cnt, start_bytes));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  return (int)(bytes - start_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
} /* end copy_cpool_bytes */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
void SymbolHashMap::add_entry(symbolOop sym, u2 value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  char *str = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
  unsigned int hash = compute_hash(str, sym->utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  unsigned int index = hash % table_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  // check if already in map
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  // we prefer the first entry since it is more likely to be what was used in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
  // the class file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    if (en->hash() == hash && en->symbol() == sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
        return;  // already there
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  SymbolHashMapEntry* entry = new SymbolHashMapEntry(hash, sym, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  entry->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  _buckets[index].set_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  assert(entry->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
SymbolHashMapEntry* SymbolHashMap::find_entry(symbolOop sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  assert(sym != NULL, "SymbolHashMap::find_entry - symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  char *str = sym->as_utf8();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  int   len = sym->utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  unsigned int hash = SymbolHashMap::compute_hash(str, len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  unsigned int index = hash % table_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  for (SymbolHashMapEntry *en = bucket(index); en != NULL; en = en->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    assert(en->symbol() != NULL, "SymbolHashMapEntry symbol is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    if (en->hash() == hash && en->symbol() == sym) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
      return en;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
}