hotspot/src/share/vm/classfile/dictionary.hpp
author chegar
Wed, 01 May 2013 14:11:01 +0100
changeset 18060 7cfaa4558c12
parent 13728 882756847a04
child 17373 7d8bb2a8787e
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
     2
 * Copyright (c) 2003, 2012, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "oops/oop.hpp"
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;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The data structure for the system dictionary (and the shared system
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// dictionary).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    40
class Dictionary : public TwoOopHashtable<Klass*, mtClass> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // current iteration index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static int                    _current_class_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // pointer to the current hash table entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  static DictionaryEntry*       _current_class_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  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
    49
                             Symbol* name, ClassLoaderData* loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  DictionaryEntry* bucket(int i) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    52
    return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  DictionaryEntry** bucket_addr(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_addr(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
  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
    61
    Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  Dictionary(int table_size);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    66
  Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    68
  DictionaryEntry* new_entry(unsigned int hash, Klass* klass, ClassLoaderData* loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  DictionaryEntry* new_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void free_entry(DictionaryEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    74
  void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    76
  Klass* find_class(int index, unsigned int hash,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    77
                      Symbol* name, ClassLoaderData* loader_data);
1
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
  Klass* find_shared_class(int index, unsigned int hash, Symbol* name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Compiler support
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    82
  Klass* try_get_next_class();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // GC support
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    85
  void oops_do(OopClosure* f);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    86
  void always_strong_oops_do(OopClosure* blk);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    88
  void always_strong_classes_do(KlassClosure* closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    90
  void classes_do(void f(Klass*));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    91
  void classes_do(void f(Klass*, TRAPS), TRAPS);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    92
  void classes_do(void f(Klass*, ClassLoaderData*));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    93
  void classes_do(void f(Klass*, ClassLoaderData*, TRAPS), TRAPS);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    94
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    95
  void methods_do(void f(Method*));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Classes loaded by the bootstrap loader are always strongly reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // 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
   100
  static bool is_strongly_reachable(ClassLoaderData* loader_data, Klass* klass) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    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
   102
    return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // Unload (that is, break root links to) all unmarked classes and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // loaders.  Returns "true" iff something was unloaded.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   107
  bool do_unloading();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Protection domains
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   110
  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
   111
                ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  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
   113
                                  Symbol* name, ClassLoaderData* loader_data,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
                                  Handle protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  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
   116
                             instanceKlassHandle klass, ClassLoaderData* loader_data,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
                             Handle protection_domain, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Sharing support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void reorder_dictionary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// The following classes can be in dictionary.cpp, but we need these
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// to be in header file so that SA's vmStructs can access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   132
class ProtectionDomainEntry :public CHeapObj<mtClass> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  ProtectionDomainEntry* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  oop                    _protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    _protection_domain = protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    _next              = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  ProtectionDomainEntry* next() { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  oop protection_domain() { return _protection_domain; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// 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
   148
// { Klass*, loader, protection_domain }.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   150
class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Contains the set of approved protection domains that can access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // this system dictionary entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  ProtectionDomainEntry* _pd_set;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   156
  ClassLoaderData*       _loader_data;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Tells whether a protection is in the approved set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  bool contains_protection_domain(oop protection_domain) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Adds a protection domain to the approved set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void add_protection_domain(oop protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   164
  Klass* klass() const { return (Klass*)literal(); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   165
  Klass** klass_addr() { return (Klass**)literal_addr(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  DictionaryEntry* next() const {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   168
    return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  DictionaryEntry** next_addr() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   172
    return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   175
  ClassLoaderData* loader_data() const { return _loader_data; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   176
  void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  ProtectionDomainEntry* pd_set() const { return _pd_set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  bool has_protection_domain() { return _pd_set != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Tells whether the initiating class' protection can access the this _klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  bool is_valid_protection_domain(Handle protection_domain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    if (!ProtectionDomainVerification) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    if (!SystemDictionary::has_checkPackageAccess()) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    return protection_domain() == NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
         ? true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
         : contains_protection_domain(protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  void protection_domain_set_oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      f->do_oop(&(current->_protection_domain));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  void verify_protection_domain_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      current->_protection_domain->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   210
  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
   211
    Klass* klass = (Klass*)literal();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   212
    return (InstanceKlass::cast(klass)->name() == class_name &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   213
            _loader_data == loader_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    tty->print_cr("pd set = #%d", count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
};
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   226
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   227
// Entry in a SymbolPropertyTable, mapping a single Symbol*
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   228
// to a managed and an unmanaged pointer.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   229
class SymbolPropertyEntry : public HashtableEntry<Symbol*, mtSymbol> {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   230
  friend class VMStructs;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   231
 private:
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   232
  intptr_t _symbol_mode;  // secondary key
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   233
  Method*   _method;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   234
  oop       _method_type;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   235
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   236
 public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   237
  Symbol* symbol() const            { return literal(); }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   238
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   239
  intptr_t symbol_mode() const      { return _symbol_mode; }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   240
  void set_symbol_mode(intptr_t m)  { _symbol_mode = m; }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   241
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   242
  Method*        method() const     { return _method; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   243
  void set_method(Method* p)        { _method = p; }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   244
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   245
  oop      method_type() const      { return _method_type; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   246
  oop*     method_type_addr()       { return &_method_type; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   247
  void set_method_type(oop p)       { _method_type = p; }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   248
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   249
  SymbolPropertyEntry* next() const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   250
    return (SymbolPropertyEntry*)HashtableEntry<Symbol*, mtSymbol>::next();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   251
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   252
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   253
  SymbolPropertyEntry** next_addr() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   254
    return (SymbolPropertyEntry**)HashtableEntry<Symbol*, mtSymbol>::next_addr();
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   255
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   256
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   257
  void print_on(outputStream* st) const {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   258
    symbol()->print_value_on(st);
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   259
    st->print("/mode="INTX_FORMAT, symbol_mode());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   260
    st->print(" -> ");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   261
    bool printed = false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   262
    if (method() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   263
      method()->print_value_on(st);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   264
      printed = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   265
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   266
    if (method_type() != NULL) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   267
      if (printed)  st->print(" and ");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   268
      st->print(INTPTR_FORMAT, method_type());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   269
      printed = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   270
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   271
    st->print_cr(printed ? "" : "(empty)");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   272
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   273
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   274
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   275
// A system-internal mapping of symbols to pointers, both managed
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   276
// and unmanaged.  Used to record the auto-generation of each method
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   277
// MethodHandle.invoke(S)T, for all signatures (S)T.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   278
class SymbolPropertyTable : public Hashtable<Symbol*, mtSymbol> {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   279
  friend class VMStructs;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   280
private:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   281
  SymbolPropertyEntry* bucket(int i) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   282
    return (SymbolPropertyEntry*) Hashtable<Symbol*, mtSymbol>::bucket(i);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   283
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   284
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   285
  // 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
   286
  SymbolPropertyEntry** bucket_addr(int i) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   287
    return (SymbolPropertyEntry**) Hashtable<Symbol*, mtSymbol>::bucket_addr(i);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   288
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   289
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   290
  void add_entry(int index, SymbolPropertyEntry* new_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   291
    ShouldNotReachHere();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   292
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   293
  void set_entry(int index, SymbolPropertyEntry* new_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   294
    ShouldNotReachHere();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   295
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   296
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   297
  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
   298
    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
   299
    // 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
   300
    symbol->increment_refcount();
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   301
    entry->set_symbol_mode(symbol_mode);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   302
    entry->set_method(NULL);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   303
    entry->set_method_type(NULL);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   304
    return entry;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   305
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   306
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   307
public:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   308
  SymbolPropertyTable(int table_size);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   309
  SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, int number_of_entries);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   310
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   311
  void free_entry(SymbolPropertyEntry* entry) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   312
    // decrement Symbol refcount here because hashtable doesn't.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   313
    entry->literal()->decrement_refcount();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   314
    Hashtable<Symbol*, mtSymbol>::free_entry(entry);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   315
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   316
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   317
  unsigned int compute_hash(Symbol* sym, intptr_t symbol_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   318
    // Use the regular identity_hash.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   319
    return Hashtable<Symbol*, mtSymbol>::compute_hash(sym) ^ symbol_mode;
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   320
  }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   321
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   322
  int index_for(Symbol* name, intptr_t symbol_mode) {
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   323
    return hash_to_index(compute_hash(name, symbol_mode));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   324
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   325
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   326
  // need not be locked; no state change
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   327
  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
   328
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   329
  // must be done under SystemDictionary_lock
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   330
  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
   331
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   332
  // GC support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   333
  void oops_do(OopClosure* f);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   334
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   335
  void methods_do(void f(Method*));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   336
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   337
  // Sharing support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   338
  void reorder_dictionary();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   339
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   340
#ifndef PRODUCT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   341
  void print();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   342
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   343
  void verify();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   344
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   345
#endif // SHARE_VM_CLASSFILE_DICTIONARY_HPP