src/hotspot/share/classfile/dictionary.cpp
author coleenp
Wed, 06 Jun 2018 10:45:40 -0400
changeset 50429 83aec1d357d4
parent 50039 9fec54fe663d
child 50634 c349d409262a
permissions -rw-r--r--
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files Summary: move orderAccess.inline.hpp into orderAccess.hpp and remove os.hpp inclusion and conditional os::is_MP() for fence on x86 platforms Reviewed-by: dholmes, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
48781
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47774
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5426
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5426
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5426
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 34257
diff changeset
    26
#include "classfile/classLoaderData.inline.hpp"
49340
4e82736053ae 8191102: Incorrect include file use in classLoader.hpp
hseigel
parents: 49329
diff changeset
    27
#include "classfile/dictionary.inline.hpp"
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents: 46380
diff changeset
    28
#include "classfile/protectionDomainCache.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/systemDictionary.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    30
#include "classfile/systemDictionaryShared.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
    31
#include "logging/log.hpp"
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
    32
#include "logging/logStream.hpp"
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 18439
diff changeset
    33
#include "memory/iterator.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    34
#include "memory/metaspaceClosure.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37242
diff changeset
    35
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "oops/oop.inline.hpp"
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    37
#include "runtime/atomic.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 50039
diff changeset
    38
#include "runtime/orderAccess.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49348
diff changeset
    39
#include "runtime/safepointVerifiers.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "utilities/hashtable.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    42
// Optimization: if any dictionary needs resizing, we set this flag,
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    43
// so that we dont't have to walk all dictionaries to check if any actually
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    44
// needs resizing, which is costly to do at Safepoint.
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    45
bool Dictionary::_some_dictionary_needs_resizing = false;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    46
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    47
size_t Dictionary::entry_size() {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    48
  if (DumpSharedSpaces) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    49
    return SystemDictionaryShared::dictionary_entry_size();
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    50
  } else {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    51
    return sizeof(DictionaryEntry);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    52
  }
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    53
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    55
Dictionary::Dictionary(ClassLoaderData* loader_data, int table_size, bool resizable)
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    56
  : _loader_data(loader_data), _resizable(resizable), _needs_resizing(false),
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    57
  Hashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    61
Dictionary::Dictionary(ClassLoaderData* loader_data,
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    62
                       int table_size, HashtableBucket<mtClass>* t,
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    63
                       int number_of_entries, bool resizable)
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    64
  : _loader_data(loader_data), _resizable(resizable), _needs_resizing(false),
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
    65
  Hashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    68
Dictionary::~Dictionary() {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    69
  DictionaryEntry* probe = NULL;
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    70
  for (int index = 0; index < table_size(); index++) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    71
    for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    72
      probe = *p;
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    73
      *p = probe->next();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    74
      free_entry(probe);
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    75
    }
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    76
  }
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    77
  assert(number_of_entries() == 0, "should have removed all entries");
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    78
  assert(new_entry_free_list() == NULL, "entry present on Dictionary's free list");
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    79
  free_buckets();
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 18439
diff changeset
    80
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    82
DictionaryEntry* Dictionary::new_entry(unsigned int hash, InstanceKlass* klass) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
    83
  DictionaryEntry* entry = (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::allocate_new_entry(hash, klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  entry->set_pd_set(NULL);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
    85
  assert(klass->is_instance_klass(), "Must be");
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    86
  if (DumpSharedSpaces) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    87
    SystemDictionaryShared::init_shared_dictionary_entry(klass, entry);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33611
diff changeset
    88
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
void Dictionary::free_entry(DictionaryEntry* entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // avoid recursion when deleting linked list
47098
e704f55561c3 8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents: 46746
diff changeset
    95
  // pd_set is accessed during a safepoint.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  while (entry->pd_set() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    ProtectionDomainEntry* to_delete = entry->pd_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    entry->set_pd_set(to_delete->next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    delete to_delete;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   101
  // Unlink from the Hashtable prior to freeing
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   102
  unlink_entry(entry);
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   103
  FREE_C_HEAP_ARRAY(char, entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   106
const int _resize_load_trigger = 5;       // load factor that will trigger the resize
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   107
const double _resize_factor    = 2.0;     // by how much we will resize using current number of entries
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   108
const int _resize_max_size     = 40423;   // the max dictionary size allowed
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   109
const int _primelist[] = {107, 1009, 2017, 4049, 5051, 10103, 20201, _resize_max_size};
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   110
const int _prime_array_size = sizeof(_primelist)/sizeof(int);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   111
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   112
// Calculate next "good" dictionary size based on requested count
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   113
static int calculate_dictionary_size(int requested) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   114
  int newsize = _primelist[0];
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   115
  int index = 0;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   116
  for (newsize = _primelist[index]; index < (_prime_array_size - 1);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   117
       newsize = _primelist[++index]) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   118
    if (requested <= newsize) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   119
      break;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   120
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   121
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   122
  return newsize;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   123
}
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   124
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   125
bool Dictionary::does_any_dictionary_needs_resizing() {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   126
  return Dictionary::_some_dictionary_needs_resizing;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   127
}
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   128
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   129
void Dictionary::check_if_needs_resize() {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   130
  if (_resizable == true) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   131
    if (number_of_entries() > (_resize_load_trigger*table_size())) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   132
      _needs_resizing = true;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   133
      Dictionary::_some_dictionary_needs_resizing = true;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   134
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   135
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   136
}
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   137
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   138
bool Dictionary::resize_if_needed() {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   139
  int desired_size = 0;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   140
  if (_needs_resizing == true) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   141
    desired_size = calculate_dictionary_size((int)(_resize_factor*number_of_entries()));
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   142
    if (desired_size >= _resize_max_size) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   143
      desired_size = _resize_max_size;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   144
      // We have reached the limit, turn resizing off
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   145
      _resizable = false;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   146
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   147
    if ((desired_size != 0) && (desired_size != table_size())) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   148
      if (!resize(desired_size)) {
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   149
        // Something went wrong, turn resizing off
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   150
        _resizable = false;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   151
      }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   152
    }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   153
  }
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   154
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   155
  _needs_resizing = false;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   156
  Dictionary::_some_dictionary_needs_resizing = false;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   157
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   158
  return (desired_size != 0);
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   159
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
#ifdef ASSERT
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49594
diff changeset
   163
  if (oopDesc::equals(protection_domain, instance_klass()->protection_domain())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    // Ensure this doesn't show up in the pd_set (invariant)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    bool in_pd_set = false;
47098
e704f55561c3 8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents: 46746
diff changeset
   166
    for (ProtectionDomainEntry* current = pd_set_acquire();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                                current = current->next()) {
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49594
diff changeset
   169
      if (oopDesc::equals(current->object_no_keepalive(), protection_domain)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        in_pd_set = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    if (in_pd_set) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      assert(false, "A klass's protection domain should not show up "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                    "in its sys. dict. PD set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
#endif /* ASSERT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49594
diff changeset
   181
  if (oopDesc::equals(protection_domain, instance_klass()->protection_domain())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    // Succeeds trivially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
47098
e704f55561c3 8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents: 46746
diff changeset
   186
  for (ProtectionDomainEntry* current = pd_set_acquire();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
                              current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                              current = current->next()) {
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49594
diff changeset
   189
    if (oopDesc::equals(current->object_no_keepalive(), protection_domain)) return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
46274
534d019edb92 8175104: Unhandled oop in ProtectionDomainCacheTable::compute_hash
coleenp
parents: 46271
diff changeset
   195
void DictionaryEntry::add_protection_domain(Dictionary* dict, Handle protection_domain) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert_locked_or_safepoint(SystemDictionary_lock);
46274
534d019edb92 8175104: Unhandled oop in ProtectionDomainCacheTable::compute_hash
coleenp
parents: 46271
diff changeset
   197
  if (!contains_protection_domain(protection_domain())) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   198
    ProtectionDomainCacheEntry* entry = SystemDictionary::cache_get(protection_domain);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    ProtectionDomainEntry* new_head =
47098
e704f55561c3 8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents: 46746
diff changeset
   200
                new ProtectionDomainEntry(entry, pd_set());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    // Warning: Preserve store ordering.  The SystemDictionary is read
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    //          without locks.  The new ProtectionDomainEntry must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    //          complete before other threads can be allowed to see it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    //          via a store to _pd_set.
47098
e704f55561c3 8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents: 46746
diff changeset
   205
    release_set_pd_set(new_head);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
   207
  LogTarget(Trace, protectiondomain) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
   208
  if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
   209
    LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
   210
    print_count(&ls);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
48811
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   214
// During class loading we may have cached a protection domain that has
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   215
// since been unreferenced, so this entry should be cleared.
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   216
void Dictionary::clean_cached_protection_domains(DictionaryEntry* probe) {
48811
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   217
  assert_locked_or_safepoint(SystemDictionary_lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
48811
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   219
  ProtectionDomainEntry* current = probe->pd_set();
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   220
  ProtectionDomainEntry* prev = NULL;
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   221
  while (current != NULL) {
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   222
    if (current->object_no_keepalive() == NULL) {
48811
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   223
      LogTarget(Debug, protectiondomain) lt;
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   224
      if (lt.is_enabled()) {
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   225
        ResourceMark rm;
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   226
        // Print out trace information
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   227
        LogStream ls(lt);
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   228
        ls.print_cr("PD in set is not alive:");
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   229
        ls.print("class loader: "); loader_data()->class_loader()->print_value_on(&ls);
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   230
        ls.print(" loading: "); probe->instance_klass()->print_value_on(&ls);
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   231
        ls.cr();
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   232
      }
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   233
      if (probe->pd_set() == current) {
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   234
        probe->set_pd_set(current->next());
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   235
      } else {
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   236
        assert(prev != NULL, "should be set by alive entry");
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   237
        prev->set_next(current->next());
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   238
      }
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   239
      ProtectionDomainEntry* to_delete = current;
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   240
      current = current->next();
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   241
      delete to_delete;
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   242
    } else {
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   243
      prev = current;
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   244
      current = current->next();
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   245
    }
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   246
  }
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   247
}
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   248
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   249
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   250
void Dictionary::do_unloading() {
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 2534
diff changeset
   251
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   253
  // The NULL class loader doesn't initiate loading classes from other class loaders
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   254
  if (loader_data() == ClassLoaderData::the_null_class_loader_data()) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   255
    return;
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   256
  }
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   257
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   258
  // Remove unloaded entries and classes from this dictionary
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  DictionaryEntry* probe = NULL;
26174
ca46a107cb78 8054402: "klass->is_loader_alive(_is_alive)) failed: must be alive" for anonymous classes
thartmann
parents: 25492
diff changeset
   260
  for (int index = 0; index < table_size(); index++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      probe = *p;
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   263
      InstanceKlass* ik = probe->instance_klass();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   264
      ClassLoaderData* k_def_class_loader_data = ik->class_loader_data();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   266
      // If the klass that this loader initiated is dead,
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   267
      // (determined by checking the defining class loader)
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   268
      // remove this entry.
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   269
      if (k_def_class_loader_data->is_unloading()) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   270
        assert(k_def_class_loader_data != loader_data(),
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   271
               "cannot have live defining loader and unreachable klass");
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   272
        *p = probe->next();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   273
        free_entry(probe);
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   274
        continue;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      }
48811
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   276
      // Clean pd_set
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   277
      clean_cached_protection_domains(probe);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      p = probe->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   283
void Dictionary::remove_classes_in_error_state() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   284
  assert(DumpSharedSpaces, "supported only when dumping");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   285
  DictionaryEntry* probe = NULL;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   286
  for (int index = 0; index < table_size(); index++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   287
    for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   288
      probe = *p;
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   289
      InstanceKlass* ik = probe->instance_klass();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   290
      if (ik->is_in_error_state()) { // purge this entry
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   291
        *p = probe->next();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   292
        free_entry(probe);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   293
        ResourceMark rm;
27618
790a8bf5488b 8064375: Change certain errors to warnings in CDS output.
jiangli
parents: 26181
diff changeset
   294
        tty->print_cr("Preload Warning: Removed error class: %s", ik->external_name());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   295
        continue;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   296
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   297
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   298
      p = probe->next_addr();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   299
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   300
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   301
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25492
diff changeset
   302
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   303
//   Just the classes from defining class loaders
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   304
void Dictionary::classes_do(void f(InstanceKlass*)) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   305
  for (int index = 0; index < table_size(); index++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   306
    for (DictionaryEntry* probe = bucket(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   307
                          probe != NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   308
                          probe = probe->next()) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   309
      InstanceKlass* k = probe->instance_klass();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   310
      if (loader_data() == k->class_loader_data()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
        f(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
// Added for initialize_itable_for_klass to handle exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
//   Just the classes from defining class loaders
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   319
void Dictionary::classes_do(void f(InstanceKlass*, TRAPS), TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
                          probe = probe->next()) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   324
      InstanceKlass* k = probe->instance_klass();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   325
      if (loader_data() == k->class_loader_data()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
        f(k, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   332
// All classes, and their class loaders, including initiating class loaders
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   333
void Dictionary::all_entries_do(void f(InstanceKlass*, ClassLoaderData*)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
                          probe = probe->next()) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   338
      InstanceKlass* k = probe->instance_klass();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   339
      f(k, loader_data());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   344
// Used to scan and relocate the classes during CDS archive dump.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   345
void Dictionary::classes_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   346
  assert(DumpSharedSpaces, "dump-time only");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   347
  for (int index = 0; index < table_size(); index++) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   348
    for (DictionaryEntry* probe = bucket(index);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   349
                          probe != NULL;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   350
                          probe = probe->next()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   351
      it->push(probe->klass_addr());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   352
      ((SharedDictionaryEntry*)probe)->metaspace_pointers_do(it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   353
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   354
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   355
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   356
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   357
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   359
// Add a loaded class to the dictionary.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
// Readers of the SystemDictionary aren't always locked, so _buckets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
// is volatile. The store of the next field in the constructor is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
// also cast to volatile;  we do this to ensure store order is maintained
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
// by the compilers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   365
void Dictionary::add_klass(unsigned int hash, Symbol* class_name,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   366
                           InstanceKlass* obj) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  assert_locked_or_safepoint(SystemDictionary_lock);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   368
  assert(obj != NULL, "adding NULL obj");
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   369
  assert(obj->name() == class_name, "sanity check on name");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   371
  DictionaryEntry* entry = new_entry(hash, obj);
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   372
  int index = hash_to_index(hash);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  add_entry(index, entry);
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   374
  check_if_needs_resize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   378
// This routine does not lock the dictionary.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
// Since readers don't hold a lock, we must make sure that system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
// dictionary entries are only removed at a safepoint (when only one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
// thread is running), and are added to in a safe way (all links must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
// be updated in an MT-safe manner).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
// Callers should be aware that an entry could be added just after
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
// _buckets[index] is read here, so the caller will not see the new entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   388
                                       Symbol* class_name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  for (DictionaryEntry* entry = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                        entry != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
                        entry = entry->next()) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   392
    if (entry->hash() == hash && entry->equals(class_name)) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   393
      if (!DumpSharedSpaces || SystemDictionaryShared::is_builtin(entry)) {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   394
        return entry;
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   395
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   402
InstanceKlass* Dictionary::find(unsigned int hash, Symbol* name,
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   403
                                Handle protection_domain) {
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   404
  NoSafepointVerifier nsv;
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   405
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   406
  int index = hash_to_index(hash);
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   407
  DictionaryEntry* entry = get_entry(index, hash, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   409
    return entry->instance_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   416
InstanceKlass* Dictionary::find_class(int index, unsigned int hash,
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   417
                                      Symbol* name) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  assert_locked_or_safepoint(SystemDictionary_lock);
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   419
  assert (index == index_for(name), "incorrect index?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   421
  DictionaryEntry* entry = get_entry(index, hash, name);
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   422
  return (entry != NULL) ? entry->instance_klass() : NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
// Variant of find_class for shared classes.  No locking required, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
// that table is static.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   429
InstanceKlass* Dictionary::find_shared_class(int index, unsigned int hash,
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   430
                                             Symbol* name) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   431
  assert (index == index_for(name), "incorrect index?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   433
  DictionaryEntry* entry = get_entry(index, hash, name);
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   434
  return (entry != NULL) ? entry->instance_klass() : NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
void Dictionary::add_protection_domain(int index, unsigned int hash,
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46274
diff changeset
   439
                                       InstanceKlass* klass,
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   440
                                       Handle protection_domain,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
                                       TRAPS) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   442
  Symbol*  klass_name = klass->name();
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   443
  DictionaryEntry* entry = get_entry(index, hash, klass_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  assert(entry != NULL,"entry must be present, we just created it");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  assert(protection_domain() != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
         "real protection domain should be present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
46274
534d019edb92 8175104: Unhandled oop in ProtectionDomainCacheTable::compute_hash
coleenp
parents: 46271
diff changeset
   449
  entry->add_protection_domain(this, protection_domain);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
48811
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   451
#ifdef ASSERT
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   452
  assert(loader_data() != ClassLoaderData::the_null_class_loader_data(), "doesn't make sense");
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   453
#endif
58787a1708d2 8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents: 48781
diff changeset
   454
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  assert(entry->contains_protection_domain(protection_domain()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
         "now protection domain should be present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   460
bool Dictionary::is_valid_protection_domain(unsigned int hash,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   461
                                            Symbol* name,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
                                            Handle protection_domain) {
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47761
diff changeset
   463
  int index = hash_to_index(hash);
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   464
  DictionaryEntry* entry = get_entry(index, hash, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  return entry->is_valid_protection_domain(protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
47761
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   468
#if INCLUDE_CDS
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   469
static bool is_jfr_event_class(Klass *k) {
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   470
  while (k) {
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   471
    if (k->name()->equals("jdk/jfr/Event")) {
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   472
      return true;
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   473
    }
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   474
    k = k->super();
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   475
  }
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   476
  return false;
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   477
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   479
void Dictionary::reorder_dictionary_for_sharing() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  // Copy all the dictionary entries into a single master list.
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48811
diff changeset
   482
  assert(DumpSharedSpaces, "Should only be used at dump time");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  DictionaryEntry* master_list = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  for (int i = 0; i < table_size(); ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    DictionaryEntry* p = bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    while (p != NULL) {
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   488
      DictionaryEntry* next = p->next();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   489
      InstanceKlass*ik = p->instance_klass();
49329
04ed29f9ef33 8194759: Support caching class mirror objects.
jiangli
parents: 48811
diff changeset
   490
      if (ik->has_signer_and_not_archived()) {
47761
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   491
        // We cannot include signed classes in the archive because the certificates
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   492
        // used during dump time may be different than those used during
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   493
        // runtime (due to expiration, etc).
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   494
        ResourceMark rm;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   495
        tty->print_cr("Preload Warning: Skipping %s from signed JAR",
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   496
                       ik->name()->as_C_string());
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   497
        free_entry(p);
47761
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   498
      } else if (is_jfr_event_class(ik)) {
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   499
        // We cannot include JFR event classes because they need runtime-specific
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   500
        // instrumentation in order to work with -XX:FlightRecorderOptions=retransform=false.
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   501
        // There are only a small number of these classes, so it's not worthwhile to
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   502
        // support them and make CDS more complicated.
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   503
        ResourceMark rm;
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   504
        tty->print_cr("Skipping JFR event class %s", ik->name()->as_C_string());
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   505
        free_entry(p);
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   506
      } else {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   507
        p->set_next(master_list);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   508
        master_list = p;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   509
      }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents: 47098
diff changeset
   510
      p = next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    set_entry(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  // Add the dictionary entries back to the list in the correct buckets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  while (master_list != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    DictionaryEntry* p = master_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    master_list = master_list->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    p->set_next(NULL);
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   520
    Symbol* class_name = p->instance_klass()->name();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   521
    // Since the null class loader data isn't copied to the CDS archive,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   522
    // compute the hash with NULL for loader data.
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   523
    unsigned int hash = compute_hash(class_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    int index = hash_to_index(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    p->set_hash(hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    p->set_next(bucket(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    set_entry(index, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
}
47761
1b0566927c7a 8190191: Subclasses of jdk.jfr.Event loaded from CDS breaks -XX:FlightRecorderOptions=retransform=false
iklam
parents: 47216
diff changeset
   530
#endif
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 34257
diff changeset
   531
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   532
SymbolPropertyTable::SymbolPropertyTable(int table_size)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11628
diff changeset
   533
  : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry))
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   534
{
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   535
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11628
diff changeset
   536
SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   537
                                         int number_of_entries)
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11628
diff changeset
   538
  : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries)
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   539
{
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   540
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   541
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   542
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   543
SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   544
                                                     Symbol* sym,
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   545
                                                     intptr_t sym_mode) {
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   546
  assert(index == index_for(sym, sym_mode), "incorrect index?");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   547
  for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   548
    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
   549
      return p;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   550
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   551
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   552
  return NULL;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   553
}
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
SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   557
                                                    Symbol* sym, intptr_t sym_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   558
  assert_locked_or_safepoint(SystemDictionary_lock);
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   559
  assert(index == index_for(sym, sym_mode), "incorrect index?");
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   560
  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
   561
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   562
  SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11628
diff changeset
   563
  Hashtable<Symbol*, mtSymbol>::add_entry(index, p);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   564
  return p;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   565
}
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   566
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   567
void SymbolPropertyTable::oops_do(OopClosure* f) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   568
  for (int index = 0; index < table_size(); index++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   569
    for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   570
      if (p->method_type() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   571
        f->do_oop(p->method_type_addr());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   572
      }
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
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   577
void SymbolPropertyTable::methods_do(void f(Method*)) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   578
  for (int index = 0; index < table_size(); index++) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   579
    for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   580
      Method* prop = p->method();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   581
      if (prop != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   582
        f((Method*)prop);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   583
      }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
   584
    }
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
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
// ----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   591
void Dictionary::print_on(outputStream* st) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   594
  assert(loader_data() != NULL, "loader data should not be null");
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   595
  st->print_cr("Java dictionary (table_size=%d, classes=%d)",
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   596
               table_size(), number_of_entries());
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   597
  st->print_cr("^ indicates that initiating loader is different from defining loader");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  for (int index = 0; index < table_size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    for (DictionaryEntry* probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
                          probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
                          probe = probe->next()) {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   603
      Klass* e = probe->instance_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      bool is_defining_class =
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   605
         (loader_data() == e->class_loader_data());
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   606
      st->print("%4d: %s%s", index, is_defining_class ? " " : "^", e->external_name());
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   607
      ClassLoaderData* cld = e->class_loader_data();
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   608
      if (cld == NULL) {
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   609
        // Shared class not restored yet in shared dictionary
49348
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   610
        st->print(", loader data <shared, not restored>");
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   611
      } else if (!loader_data()->is_the_null_class_loader_data()) {
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   612
        // Class loader output for the dictionary for the null class loader data is
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   613
        // redundant and obvious.
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   614
        st->print(", ");
fde3feaaa4ed 8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents: 49340
diff changeset
   615
        cld->print_value_on(st);
39982
1a3808e3f4d9 8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents: 38259
diff changeset
   616
      }
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   617
      st->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  }
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 18439
diff changeset
   620
  tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   623
void DictionaryEntry::verify() {
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   624
  Klass* e = instance_klass();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   625
  guarantee(e->is_instance_klass(),
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   626
                          "Verify of dictionary failed");
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   627
  e->verify();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   628
  verify_protection_domain_set();
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   629
}
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   630
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   631
void Dictionary::verify() {
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   632
  guarantee(number_of_entries() >= 0, "Verify of dictionary failed");
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   633
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   634
  ClassLoaderData* cld = loader_data();
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   635
  // class loader must be present;  a null class loader is the
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   636
  // boostrap loader
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   637
  guarantee(cld != NULL || DumpSharedSpaces ||
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   638
            cld->class_loader() == NULL ||
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   639
            cld->class_loader()->is_instance(),
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   640
            "checking type of class_loader");
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   641
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   642
  ResourceMark rm;
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   643
  stringStream tempst;
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   644
  tempst.print("System Dictionary for %s", cld->loader_name());
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46701
diff changeset
   645
  verify_table<DictionaryEntry>(tempst.as_string());
42073
89e056fd82cc 8166145: runtime/threads/ThreadInterruptTest3 fails with ExitCode 0
gziemski
parents: 39982
diff changeset
   646
}