hotspot/src/share/vm/classfile/dictionary.hpp
author stefank
Mon, 07 Jul 2014 10:12:40 +0200
changeset 25492 d27050bdfb04
parent 25491 70fb742e40aa
child 26174 ca46a107cb78
child 26135 82b516c550f7
permissions -rw-r--r--
8049421: G1 Class Unloading after completing a concurrent mark cycle Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 20408
diff changeset
     2
 * Copyright (c) 2003, 2014, 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: 5420
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5420
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: 5420
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
#ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CLASSFILE_DICTIONARY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/instanceKlass.hpp"
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
    30
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/hashtable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class DictionaryEntry;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    34
class PSPromotionManager;
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
    35
class ProtectionDomainCacheTable;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
    36
class ProtectionDomainCacheEntry;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
    37
class BoolObjectClosure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// The data structure for the system dictionary (and the shared system
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// dictionary).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    43
class Dictionary : public TwoOopHashtable<Klass*, mtClass> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // current iteration index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static int                    _current_class_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // pointer to the current hash table entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  static DictionaryEntry*       _current_class_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
    51
  ProtectionDomainCacheTable*   _pd_cache_table;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
    52
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  DictionaryEntry* get_entry(int index, unsigned int hash,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    54
                             Symbol* name, ClassLoaderData* loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  DictionaryEntry* bucket(int i) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    57
    return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
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
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  DictionaryEntry** bucket_addr(int i) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    62
    return (DictionaryEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  void add_entry(int index, DictionaryEntry* new_entry) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    66
    Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  Dictionary(int table_size);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    71
  Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    73
  DictionaryEntry* new_entry(unsigned int hash, Klass* klass, ClassLoaderData* loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  DictionaryEntry* new_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void free_entry(DictionaryEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    79
  void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    81
  Klass* find_class(int index, unsigned int hash,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    82
                      Symbol* name, ClassLoaderData* loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    84
  Klass* find_shared_class(int index, unsigned int hash, Symbol* name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Compiler support
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    87
  Klass* try_get_next_class();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // GC support
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    90
  void oops_do(OopClosure* f);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    91
  void always_strong_oops_do(OopClosure* blk);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
    92
  void roots_oops_do(OopClosure* strong, OopClosure* weak);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    94
  void always_strong_classes_do(KlassClosure* closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    96
  void classes_do(void f(Klass*));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    97
  void classes_do(void f(Klass*, TRAPS), TRAPS);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    98
  void classes_do(void f(Klass*, ClassLoaderData*));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    99
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   100
  void methods_do(void f(Method*));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   102
  void unlink(BoolObjectClosure* is_alive);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Classes loaded by the bootstrap loader are always strongly reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // If we're not doing class unloading, all classes are strongly reachable.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   106
  static bool is_strongly_reachable(ClassLoaderData* loader_data, Klass* klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    assert (klass != NULL, "should have non-null klass");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   108
    return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Unload (that is, break root links to) all unmarked classes and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // loaders.  Returns "true" iff something was unloaded.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   113
  bool do_unloading();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Protection domains
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   116
  Klass* find(int index, unsigned int hash, Symbol* name,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   117
                ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  bool is_valid_protection_domain(int index, unsigned int hash,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   119
                                  Symbol* name, ClassLoaderData* loader_data,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
                                  Handle protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void add_protection_domain(int index, unsigned int hash,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   122
                             instanceKlassHandle klass, ClassLoaderData* loader_data,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
                             Handle protection_domain, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Sharing support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void reorder_dictionary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   128
  ProtectionDomainCacheEntry* cache_get(oop protection_domain);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// The following classes can be in dictionary.cpp, but we need these
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   137
// to be in header file so that SA's vmStructs can access them.
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   138
class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   139
  friend class VMStructs;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   140
 private:
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   141
  // Flag indicating whether this protection domain entry is strongly reachable.
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   142
  // Used during iterating over the system dictionary to remember oops that need
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   143
  // to be updated.
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   144
  bool _strongly_reachable;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   145
 public:
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   146
  oop protection_domain() { return literal(); }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   147
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   148
  void init() {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   149
    _strongly_reachable = false;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   150
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   151
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   152
  ProtectionDomainCacheEntry* next() {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   153
    return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   154
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   155
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   156
  ProtectionDomainCacheEntry** next_addr() {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   157
    return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   158
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   159
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   160
  void oops_do(OopClosure* f) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   161
    f->do_oop(literal_addr());
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   162
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   163
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   164
  void set_strongly_reachable()   { _strongly_reachable = true; }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   165
  bool is_strongly_reachable()    { return _strongly_reachable; }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   166
  void reset_strongly_reachable() { _strongly_reachable = false; }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   167
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   168
  void print() PRODUCT_RETURN;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   169
  void verify();
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   170
};
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   171
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   172
// The ProtectionDomainCacheTable contains all protection domain oops. The system
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   173
// dictionary entries reference its entries instead of having references to oops
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   174
// directly.
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   175
// This is used to speed up system dictionary iteration: the oops in the
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   176
// protection domain are the only ones referring the Java heap. So when there is
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   177
// need to update these, instead of going over every entry of the system dictionary,
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   178
// we only need to iterate over this set.
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   179
// The amount of different protection domains used is typically magnitudes smaller
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   180
// than the number of system dictionary entries (loaded classes).
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   181
class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   182
  friend class VMStructs;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   183
private:
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   184
  ProtectionDomainCacheEntry* bucket(int i) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   185
    return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   186
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   187
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   188
  // The following method is not MT-safe and must be done under lock.
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   189
  ProtectionDomainCacheEntry** bucket_addr(int i) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   190
    return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   191
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   192
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   193
  ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   194
    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   195
    entry->init();
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   196
    return entry;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   197
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   198
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   199
  static unsigned int compute_hash(oop protection_domain) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   200
    return (unsigned int)(protection_domain->identity_hash());
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   201
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   202
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   203
  int index_for(oop protection_domain) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   204
    return hash_to_index(compute_hash(protection_domain));
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   205
  }
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   206
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   207
  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   208
  ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   209
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   210
public:
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   211
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   212
  ProtectionDomainCacheTable(int table_size);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   213
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   214
  ProtectionDomainCacheEntry* get(oop protection_domain);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   215
  void free(ProtectionDomainCacheEntry* entry);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   216
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   217
  void unlink(BoolObjectClosure* cl);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   218
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   219
  // GC support
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   220
  void oops_do(OopClosure* f);
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   221
  void always_strong_oops_do(OopClosure* f);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   222
  void roots_oops_do(OopClosure* strong, OopClosure* weak);
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   223
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   224
  static uint bucket_size();
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   225
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   226
  void print() PRODUCT_RETURN;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   227
  void verify();
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   228
};
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   229
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   231
class ProtectionDomainEntry :public CHeapObj<mtClass> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  ProtectionDomainEntry* _next;
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   235
  ProtectionDomainCacheEntry* _pd_cache;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   237
  ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   238
    _pd_cache = pd_cache;
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   239
    _next     = next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  ProtectionDomainEntry* next() { return _next; }
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   243
  oop protection_domain() { return _pd_cache->protection_domain(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// An entry in the system dictionary, this describes a class as
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   247
// { Klass*, loader, protection_domain }.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   249
class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // Contains the set of approved protection domains that can access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // this system dictionary entry.
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   254
  //
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   255
  // This protection domain set is a set of tuples:
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   256
  //
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   257
  // (InstanceKlass C, initiating class loader ICL, Protection Domain PD)
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   258
  //
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   259
  // [Note that C.protection_domain(), which is stored in the java.lang.Class
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   260
  // mirror of C, is NOT the same as PD]
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   261
  //
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   262
  // If such an entry (C, ICL, PD) exists in the table, it means that
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   263
  // it is okay for a class Foo to reference C, where
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   264
  //
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   265
  //    Foo.protection_domain() == PD, and
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   266
  //    Foo's defining class loader == ICL
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   267
  //
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   268
  // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain()
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   269
  // It is essentially a cache to avoid repeated Java up-calls to
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   270
  // ClassLoader.checkPackageAccess().
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   271
  //
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  ProtectionDomainEntry* _pd_set;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   273
  ClassLoaderData*       _loader_data;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  // Tells whether a protection is in the approved set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  bool contains_protection_domain(oop protection_domain) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  // Adds a protection domain to the approved set.
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   279
  void add_protection_domain(Dictionary* dict, oop protection_domain);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   281
  Klass* klass() const { return (Klass*)literal(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   282
  Klass** klass_addr() { return (Klass**)literal_addr(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  DictionaryEntry* next() const {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   285
    return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  DictionaryEntry** next_addr() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   289
    return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   292
  ClassLoaderData* loader_data() const { return _loader_data; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   293
  void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  ProtectionDomainEntry* pd_set() const { return _pd_set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  bool has_protection_domain() { return _pd_set != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // Tells whether the initiating class' protection can access the this _klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  bool is_valid_protection_domain(Handle protection_domain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (!ProtectionDomainVerification) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    if (!SystemDictionary::has_checkPackageAccess()) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    return protection_domain() == NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
         ? true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
         : contains_protection_domain(protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   310
  void set_strongly_reachable() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
                                current = current->_next) {
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   314
      current->_pd_cache->set_strongly_reachable();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  void verify_protection_domain_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
                                current = current->_next) {
20405
3321f6b16639 8003420: NPG: make new GC root for pd_set
tschatzl
parents: 17373
diff changeset
   322
      current->_pd_cache->protection_domain()->verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   326
  bool equals(Symbol* class_name, ClassLoaderData* loader_data) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   327
    Klass* klass = (Klass*)literal();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   328
    return (InstanceKlass::cast(klass)->name() == class_name &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   329
            _loader_data == loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    tty->print_cr("pd set = #%d", count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
};
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   342
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   343
// Entry in a SymbolPropertyTable, mapping a single Symbol*
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   344
// to a managed and an unmanaged pointer.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   345
class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   346
  friend class VMStructs;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   347
 private:
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   348
  intptr_t _symbol_mode;  // secondary key
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   349
  Method*   _method;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   350
  oop       _method_type;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   351
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   352
 public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   353
  Symbol* symbol() const            { return literal(); }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   354
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   355
  intptr_t symbol_mode() const      { return _symbol_mode; }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   356
  void set_symbol_mode(intptr_t m)  { _symbol_mode = m; }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   357
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   358
  Method*        method() const     { return _method; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   359
  void set_method(Method* p)        { _method = p; }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   360
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   361
  oop      method_type() const      { return _method_type; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   362
  oop*     method_type_addr()       { return &_method_type; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   363
  void set_method_type(oop p)       { _method_type = p; }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   364
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   365
  SymbolPropertyEntry* next() const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   366
    return (SymbolPropertyEntry*)HashtableEntry<Symbol*, mtSymbol>::next();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   367
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   368
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   369
  SymbolPropertyEntry** next_addr() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   370
    return (SymbolPropertyEntry**)HashtableEntry<Symbol*, mtSymbol>::next_addr();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   371
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   372
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   373
  void print_on(outputStream* st) const {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   374
    symbol()->print_value_on(st);
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   375
    st->print("/mode="INTX_FORMAT, symbol_mode());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   376
    st->print(" -> ");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   377
    bool printed = false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   378
    if (method() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   379
      method()->print_value_on(st);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   380
      printed = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   381
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   382
    if (method_type() != NULL) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   383
      if (printed)  st->print(" and ");
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 20408
diff changeset
   384
      st->print(INTPTR_FORMAT, p2i((void *)method_type()));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   385
      printed = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   386
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   387
    st->print_cr(printed ? "" : "(empty)");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   388
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   389
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   390
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   391
// A system-internal mapping of symbols to pointers, both managed
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   392
// and unmanaged.  Used to record the auto-generation of each method
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   393
// MethodHandle.invoke(S)T, for all signatures (S)T.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   394
class SymbolPropertyTable : public Hashtable<Symbol*, mtSymbol> {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   395
  friend class VMStructs;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   396
private:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   397
  SymbolPropertyEntry* bucket(int i) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   398
    return (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::bucket(i);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   399
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   400
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   401
  // The following method is not MT-safe and must be done under lock.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   402
  SymbolPropertyEntry** bucket_addr(int i) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   403
    return (SymbolPropertyEntry**) Hashtable<Symbol*, mtSymbol>::bucket_addr(i);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   404
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   405
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   406
  void add_entry(int index, SymbolPropertyEntry* new_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   407
    ShouldNotReachHere();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   408
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   409
  void set_entry(int index, SymbolPropertyEntry* new_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   410
    ShouldNotReachHere();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   411
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   412
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   413
  SymbolPropertyEntry* new_entry(unsigned int hash, Symbol* symbol, intptr_t symbol_mode) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   414
    SymbolPropertyEntry* entry = (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::new_entry(hash, symbol);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   415
    // Hashtable with Symbol* literal must increment and decrement refcount.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   416
    symbol->increment_refcount();
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   417
    entry->set_symbol_mode(symbol_mode);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   418
    entry->set_method(NULL);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   419
    entry->set_method_type(NULL);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   420
    return entry;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   421
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   422
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   423
public:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   424
  SymbolPropertyTable(int table_size);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   425
  SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, int number_of_entries);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   426
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   427
  void free_entry(SymbolPropertyEntry* entry) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   428
    // decrement Symbol refcount here because hashtable doesn't.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   429
    entry->literal()->decrement_refcount();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   430
    Hashtable<Symbol*, mtSymbol>::free_entry(entry);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   431
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   432
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   433
  unsigned int compute_hash(Symbol* sym, intptr_t symbol_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   434
    // Use the regular identity_hash.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   435
    return Hashtable<Symbol*, mtSymbol>::compute_hash(sym) ^ symbol_mode;
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   436
  }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   437
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   438
  int index_for(Symbol* name, intptr_t symbol_mode) {
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   439
    return hash_to_index(compute_hash(name, symbol_mode));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   440
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   441
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   442
  // need not be locked; no state change
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   443
  SymbolPropertyEntry* find_entry(int index, unsigned int hash, Symbol* name, intptr_t name_mode);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   444
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   445
  // must be done under SystemDictionary_lock
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   446
  SymbolPropertyEntry* add_entry(int index, unsigned int hash, Symbol* name, intptr_t name_mode);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   447
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   448
  // GC support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   449
  void oops_do(OopClosure* f);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   450
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   451
  void methods_do(void f(Method*));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   452
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   453
  // Sharing support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   454
  void reorder_dictionary();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   455
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   456
#ifndef PRODUCT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   457
  void print();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   458
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   459
  void verify();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   460
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   461
#endif // SHARE_VM_CLASSFILE_DICTIONARY_HPP