hotspot/src/share/vm/classfile/dictionary.cpp
author jrose
Tue, 11 May 2010 15:19:19 -0700
changeset 5426 470c15eda401
parent 5402 c51fd0c1d005
parent 5420 586d3988e72b
child 5547 f4b087cbb361
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
     2
 * Copyright 2003-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
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/_dictionary.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
DictionaryEntry*  Dictionary::_current_class_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
int               Dictionary::_current_class_index =    0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
Dictionary::Dictionary(int table_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  : TwoOopHashtable(table_size, sizeof(DictionaryEntry)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _current_class_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  _current_class_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
Dictionary::Dictionary(int table_size, HashtableBucket* t,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
                       int number_of_entries)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  : TwoOopHashtable(table_size, sizeof(DictionaryEntry), t, number_of_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _current_class_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _current_class_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
DictionaryEntry* Dictionary::new_entry(unsigned int hash, klassOop klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                                       oop loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  DictionaryEntry* entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  entry = (DictionaryEntry*)Hashtable::new_entry(hash, klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  entry->set_loader(loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  entry->set_pd_set(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
DictionaryEntry* Dictionary::new_entry() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  DictionaryEntry* entry = (DictionaryEntry*)Hashtable::new_entry(0L, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  entry->set_loader(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  entry->set_pd_set(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
void Dictionary::free_entry(DictionaryEntry* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // avoid recursion when deleting linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  while (entry->pd_set() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    ProtectionDomainEntry* to_delete = entry->pd_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    entry->set_pd_set(to_delete->next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    delete to_delete;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  Hashtable::free_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  if (protection_domain == instanceKlass::cast(klass())->protection_domain()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    // Ensure this doesn't show up in the pd_set (invariant)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    bool in_pd_set = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
                                current = current->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      if (current->protection_domain() == protection_domain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
        in_pd_set = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (in_pd_set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      assert(false, "A klass's protection domain should not show up "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                    "in its sys. dict. PD set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#endif /* ASSERT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if (protection_domain == instanceKlass::cast(klass())->protection_domain()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // Succeeds trivially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                              current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                              current = current->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    if (current->protection_domain() == protection_domain) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
void DictionaryEntry::add_protection_domain(oop protection_domain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (!contains_protection_domain(protection_domain)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    ProtectionDomainEntry* new_head =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
                new ProtectionDomainEntry(protection_domain, _pd_set);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    // Warning: Preserve store ordering.  The SystemDictionary is read
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    //          without locks.  The new ProtectionDomainEntry must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    //          complete before other threads can be allowed to see it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    //          via a store to _pd_set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    OrderAccess::release_store_ptr(&_pd_set, new_head);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  if (TraceProtectionDomainVerification && WizardMode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
bool Dictionary::do_unloading(BoolObjectClosure* is_alive) {
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 2534
diff changeset
   130
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  bool class_was_unloaded = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  int  index = 0; // Defined here for portability! Do not move
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Remove unloadable entries and classes from system dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // The placeholder array has been handled in always_strong_oops_do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  DictionaryEntry* probe = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  for (index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      probe = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      klassOop e = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      oop class_loader = probe->loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      instanceKlass* ik = instanceKlass::cast(e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      if (ik->previous_versions() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        // This klass has previous versions so see what we can cleanup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        // while it is safe to do so.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        int gc_count = 0;    // leave debugging breadcrumbs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        int live_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        // RC_TRACE macro has an embedded ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
          ik->external_name(), ik->previous_versions()->length()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
          // check the previous versions array for GC'ed weak refs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
          PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
220
e6ef4818c49d 6497639: 4/3 Profiling Swing application caused JVM crash
dcubed
parents: 1
diff changeset
   158
          jobject cp_ref = pv_node->prev_constant_pool();
e6ef4818c49d 6497639: 4/3 Profiling Swing application caused JVM crash
dcubed
parents: 1
diff changeset
   159
          assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
          if (cp_ref == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
            delete pv_node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
            ik->previous_versions()->remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
            // Since we are traversing the array backwards, we don't have to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
            // do anything special with the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
            continue;  // robustness
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
          constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
          if (pvcp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
            // this entry has been GC'ed so remove it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
            delete pv_node;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
            ik->previous_versions()->remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
            // Since we are traversing the array backwards, we don't have to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
            // do anything special with the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
            gc_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
            RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
            if (is_alive->do_object_b(pvcp)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
              live_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
              guarantee(false, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
          GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          if (method_refs != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
            RC_TRACE(0x00000200, ("unload: previous methods length=%d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
              method_refs->length()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
            for (int j = method_refs->length() - 1; j >= 0; j--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
              jweak method_ref = method_refs->at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
              assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
              if (method_ref == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                method_refs->remove_at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                // Since we are traversing the array backwards, we don't have to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                // do anything special with the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                continue;  // robustness
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
              methodOop method = (methodOop)JNIHandles::resolve(method_ref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
              if (method == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
                // this method entry has been GC'ed so remove it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
                JNIHandles::destroy_weak_global(method_ref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                method_refs->remove_at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
              } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                // RC_TRACE macro has an embedded ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
                RC_TRACE(0x00000200,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
                  ("unload: %s(%s): prev method @%d in version @%d is alive",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
                  method->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
                  method->signature()->as_C_string(), j, i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
              }
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
        assert(ik->previous_versions()->length() == live_count, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        RC_TRACE(0x00000200,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
          ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
          gc_count));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      // Non-unloadable classes were handled in always_strong_oops_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      if (!is_strongly_reachable(class_loader, e)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        // Entry was not visited in phase1 (negated test from phase1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        assert(class_loader != NULL, "unloading entry with null class loader");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        oop k_def_class_loader = ik->class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        // Do we need to delete this system dictionary entry?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        bool purge_entry = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        // Do we need to delete this system dictionary entry?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        if (!is_alive->do_object_b(class_loader)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          // If the loader is not live this entry should always be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
          // removed (will never be looked up again). Note that this is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          // not the same as unloading the referred class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
          if (k_def_class_loader == class_loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
            // This is the defining entry, so the referred class is about
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
            // to be unloaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
            // Notify the debugger and clean up the class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
            guarantee(!is_alive->do_object_b(e),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
                      "klass should not be live if defining loader is not");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
            class_was_unloaded = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
            // notify the debugger
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
            if (JvmtiExport::should_post_class_unload()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
              JvmtiExport::post_class_unload(ik->as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
            // notify ClassLoadingService of class unload
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
            ClassLoadingService::notify_class_unloaded(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
            // Clean up C heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
            ik->release_C_heap_structures();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
          // Also remove this system dictionary entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
          purge_entry = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
          // The loader in this entry is alive. If the klass is dead,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
          // the loader must be an initiating loader (rather than the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
          // defining loader). Remove this entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
          if (!is_alive->do_object_b(e)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
            guarantee(!is_alive->do_object_b(k_def_class_loader),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
                      "defining loader should not be live if klass is not");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
            // If we get here, the class_loader must not be the defining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
            // loader, it must be an initiating one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
            assert(k_def_class_loader != class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
                   "cannot have live defining loader and unreachable klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
            // Loader is live, but class and its defining loader are dead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
            // Remove the entry. The class is going away.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
            purge_entry = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
        if (purge_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
          *p = probe->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
          if (probe == _current_class_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
            _current_class_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          free_entry(probe);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
          continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      p = probe->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  return class_was_unloaded;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
void Dictionary::always_strong_classes_do(OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  // Follow all system classes and temporary placeholders in dictionary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    for (DictionaryEntry *probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      oop e = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      oop class_loader = probe->loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      if (is_strongly_reachable(class_loader, e)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        blk->do_oop((oop*)probe->klass_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
        if (class_loader != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
          blk->do_oop(probe->loader_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
        probe->protection_domain_set_oops_do(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
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
//   Just the classes from defining class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
void Dictionary::classes_do(void f(klassOop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      klassOop k = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        f(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
// Added for initialize_itable_for_klass to handle exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
//   Just the classes from defining class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      klassOop k = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
        f(k, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
//   All classes, and their class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
//   (added for helpers that use HandleMarks and ResourceMarks)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// Don't iterate over placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
void Dictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      klassOop k = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      f(k, probe->loader(), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
//   All classes, and their class loaders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
// Don't iterate over placeholders
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
void Dictionary::classes_do(void f(klassOop, oop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      klassOop k = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      f(k, probe->loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    }
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
void Dictionary::oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      f->do_oop((oop*)probe->klass_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      if (probe->loader() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        f->do_oop(probe->loader_addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      probe->protection_domain_set_oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
void Dictionary::methods_do(void f(methodOop)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      klassOop k = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
        // only take klass is we have the entry with the defining class loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        instanceKlass::cast(k)->methods_do(f);
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
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
klassOop Dictionary::try_get_next_class() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    if (_current_class_entry != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      klassOop k = _current_class_entry->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      _current_class_entry = _current_class_entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    _current_class_index = (_current_class_index + 1) % table_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    _current_class_entry = bucket(_current_class_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // never reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
// Add a loaded class to the system dictionary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
// Readers of the SystemDictionary aren't always locked, so _buckets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
// is volatile. The store of the next field in the constructor is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
// also cast to volatile;  we do this to ensure store order is maintained
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
// by the compilers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
void Dictionary::add_klass(symbolHandle class_name, Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
                           KlassHandle obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  assert(obj() != NULL, "adding NULL obj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  assert(Klass::cast(obj())->name() == class_name(), "sanity check on name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  unsigned int hash = compute_hash(class_name, class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  DictionaryEntry* entry = new_entry(hash, obj(), class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  add_entry(index, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
// This routine does not lock the system dictionary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
// Since readers don't hold a lock, we must make sure that system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
// dictionary entries are only removed at a safepoint (when only one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
// thread is running), and are added to in a safe way (all links must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
// be updated in an MT-safe manner).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
// Callers should be aware that an entry could be added just after
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
// _buckets[index] is read here, so the caller will not see the new entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
                                       symbolHandle class_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
                                       Handle class_loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  symbolOop name_ = class_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  oop loader_ = class_loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  debug_only(_lookup_count++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  for (DictionaryEntry* entry = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
                        entry != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                        entry = entry->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    if (entry->hash() == hash && entry->equals(name_, loader_)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    debug_only(_lookup_length++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
klassOop Dictionary::find(int index, unsigned int hash, symbolHandle name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
                          Handle loader, Handle protection_domain, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  DictionaryEntry* entry = get_entry(index, hash, name, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    return entry->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
klassOop Dictionary::find_class(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
                                symbolHandle name, Handle loader) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  assert (index == index_for(name, loader), "incorrect index?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  DictionaryEntry* entry = get_entry(index, hash, name, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  return (entry != NULL) ? entry->klass() : (klassOop)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
// Variant of find_class for shared classes.  No locking required, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
// that table is static.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
klassOop Dictionary::find_shared_class(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
                                       symbolHandle name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  assert (index == index_for(name, Handle()), "incorrect index?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  DictionaryEntry* entry = get_entry(index, hash, name, Handle());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  return (entry != NULL) ? entry->klass() : (klassOop)NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
void Dictionary::add_protection_domain(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
                                       instanceKlassHandle klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
                                       Handle loader, Handle protection_domain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
                                       TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  symbolHandle klass_name(THREAD, klass->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  DictionaryEntry* entry = get_entry(index, hash, klass_name, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  assert(entry != NULL,"entry must be present, we just created it");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  assert(protection_domain() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
         "real protection domain should be present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  entry->add_protection_domain(protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  assert(entry->contains_protection_domain(protection_domain()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
         "now protection domain should be present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
                                            symbolHandle name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
                                            Handle loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
                                            Handle protection_domain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  DictionaryEntry* entry = get_entry(index, hash, name, loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  return entry->is_valid_protection_domain(protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
void Dictionary::reorder_dictionary() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  // Copy all the dictionary entries into a single master list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  DictionaryEntry* master_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  for (int i = 0; i < table_size(); ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    DictionaryEntry* p = bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    while (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      DictionaryEntry* tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      tmp = p->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      p->set_next(master_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      master_list = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      p = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    set_entry(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  // Add the dictionary entries back to the list in the correct buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  while (master_list != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    DictionaryEntry* p = master_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    master_list = master_list->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    p->set_next(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    symbolHandle class_name (thread, instanceKlass::cast((klassOop)(p->klass()))->name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    unsigned int hash = compute_hash(class_name, Handle(thread, p->loader()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    p->set_hash(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    p->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    set_entry(index, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   552
SymbolPropertyTable::SymbolPropertyTable(int table_size)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   553
  : Hashtable(table_size, sizeof(SymbolPropertyEntry))
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   554
{
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   555
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   556
SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket* t,
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   557
                                         int number_of_entries)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   558
  : Hashtable(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries)
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   559
{
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   560
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   561
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   562
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   563
SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash,
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   564
                                                     symbolHandle sym,
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   565
                                                     intptr_t sym_mode) {
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   566
  assert(index == index_for(sym, sym_mode), "incorrect index?");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   567
  for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   568
    if (p->hash() == hash && p->symbol() == sym() && p->symbol_mode() == sym_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   569
      return p;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   570
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   571
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   572
  return NULL;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   573
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   574
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   575
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   576
SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash,
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   577
                                                    symbolHandle sym, intptr_t sym_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   578
  assert_locked_or_safepoint(SystemDictionary_lock);
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   579
  assert(index == index_for(sym, sym_mode), "incorrect index?");
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   580
  assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   581
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   582
  SymbolPropertyEntry* p = new_entry(hash, sym(), sym_mode);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   583
  Hashtable::add_entry(index, p);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   584
  return p;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   585
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   586
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   587
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   588
void SymbolPropertyTable::oops_do(OopClosure* f) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   589
  for (int index = 0; index < table_size(); index++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   590
    for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   591
      f->do_oop((oop*) p->symbol_addr());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   592
      if (p->property_oop() != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   593
        f->do_oop(p->property_oop_addr());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   594
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   595
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   596
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   597
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   598
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   599
void SymbolPropertyTable::methods_do(void f(methodOop)) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   600
  for (int index = 0; index < table_size(); index++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   601
    for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   602
      oop prop = p->property_oop();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   603
      if (prop != NULL && prop->is_method()) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   604
        f((methodOop)prop);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   605
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   606
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   607
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   608
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   609
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
void Dictionary::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  HandleMark   hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  tty->print_cr("Java system dictionary (classes=%d)", number_of_entries());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  tty->print_cr("^ indicates that initiating loader is different from "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
                "defining loader");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      if (Verbose) tty->print("%4d: ", index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      klassOop e = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
      oop class_loader =  probe->loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      bool is_defining_class =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
         (class_loader == instanceKlass::cast(e)->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
      tty->print("%s%s", is_defining_class ? " " : "^",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
                   Klass::cast(e)->external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
      if (class_loader != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
        tty->print(", loader ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
        class_loader->print_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
void Dictionary::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  int element_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
                          probe = probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
      klassOop e = probe->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
      oop class_loader = probe->loader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
      guarantee(Klass::cast(e)->oop_is_instance(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
                              "Verify of system dictionary failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      // class loader must be present;  a null class loader is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
      // boostrap loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      guarantee(class_loader == NULL || class_loader->is_instance(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
                "checking type of class_loader");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
      e->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      probe->verify_protection_domain_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      element_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  guarantee(number_of_entries() == element_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
            "Verify of system dictionary failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
}