hotspot/src/share/vm/classfile/dictionary.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 5420 586d3988e72b
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5420
diff changeset
     2
 * Copyright (c) 2003, 2009, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
class DictionaryEntry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// The data structure for the system dictionary (and the shared system
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// dictionary).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class Dictionary : public TwoOopHashtable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // current iteration index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  static int                    _current_class_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // pointer to the current hash table entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  static DictionaryEntry*       _current_class_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  DictionaryEntry* get_entry(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                             symbolHandle name, Handle loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  DictionaryEntry* bucket(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    return (DictionaryEntry*)Hashtable::bucket(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // The following method is not MT-safe and must be done under lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  DictionaryEntry** bucket_addr(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    return (DictionaryEntry**)Hashtable::bucket_addr(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  void add_entry(int index, DictionaryEntry* new_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    Hashtable::add_entry(index, (HashtableEntry*)new_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  Dictionary(int table_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  Dictionary(int table_size, HashtableBucket* t, int number_of_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  DictionaryEntry* new_entry(unsigned int hash, klassOop klass, oop loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  DictionaryEntry* new_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  void free_entry(DictionaryEntry* entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  void add_klass(symbolHandle class_name, Handle class_loader,KlassHandle obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  klassOop find_class(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                      symbolHandle name, Handle loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  klassOop find_shared_class(int index, unsigned int hash, symbolHandle name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Compiler support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  klassOop try_get_next_class();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // GC support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  void always_strong_classes_do(OopClosure* blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  void classes_do(void f(klassOop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  void classes_do(void f(klassOop, TRAPS), TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  void classes_do(void f(klassOop, oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  void methods_do(void f(methodOop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Classes loaded by the bootstrap loader are always strongly reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // If we're not doing class unloading, all classes are strongly reachable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static bool is_strongly_reachable(oop class_loader, oop klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    assert (klass != NULL, "should have non-null klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    return (class_loader == NULL || !ClassUnloading);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Unload (that is, break root links to) all unmarked classes and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // loaders.  Returns "true" iff something was unloaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  bool do_unloading(BoolObjectClosure* is_alive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Protection domains
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  klassOop find(int index, unsigned int hash, symbolHandle name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                Handle loader, Handle protection_domain, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  bool is_valid_protection_domain(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                                  symbolHandle name, Handle class_loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                                  Handle protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void add_protection_domain(int index, unsigned int hash,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                             instanceKlassHandle klass, Handle loader,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                             Handle protection_domain, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // Sharing support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  void dump(SerializeOopClosure* soc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  void restore(SerializeOopClosure* soc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  void reorder_dictionary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// The following classes can be in dictionary.cpp, but we need these
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// to be in header file so that SA's vmStructs can access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
class ProtectionDomainEntry :public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  ProtectionDomainEntry* _next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  oop                    _protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _protection_domain = protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    _next              = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  ProtectionDomainEntry* next() { return _next; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  oop protection_domain() { return _protection_domain; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
// An entry in the system dictionary, this describes a class as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// { klassOop, loader, protection_domain }.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
class DictionaryEntry : public HashtableEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Contains the set of approved protection domains that can access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // this system dictionary entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  ProtectionDomainEntry* _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  oop                    _loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // Tells whether a protection is in the approved set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  bool contains_protection_domain(oop protection_domain) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Adds a protection domain to the approved set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  void add_protection_domain(oop protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  klassOop klass() const { return (klassOop)literal(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  klassOop* klass_addr() { return (klassOop*)literal_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  DictionaryEntry* next() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    return (DictionaryEntry*)HashtableEntry::next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  DictionaryEntry** next_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    return (DictionaryEntry**)HashtableEntry::next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  oop loader() const { return _loader; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  void set_loader(oop loader) { _loader = loader; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  oop* loader_addr() { return &_loader; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  ProtectionDomainEntry* pd_set() const { return _pd_set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  bool has_protection_domain() { return _pd_set != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // Tells whether the initiating class' protection can access the this _klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  bool is_valid_protection_domain(Handle protection_domain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if (!ProtectionDomainVerification) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    if (!SystemDictionary::has_checkPackageAccess()) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    return protection_domain() == NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
         ? true
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
         : contains_protection_domain(protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  void protection_domain_set_oops_do(OopClosure* f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      f->do_oop(&(current->_protection_domain));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  void verify_protection_domain_set() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      current->_protection_domain->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  bool equals(symbolOop class_name, oop class_loader) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    klassOop klass = (klassOop)literal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    return (instanceKlass::cast(klass)->name() == class_name &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
            _loader == class_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    for (ProtectionDomainEntry* current = _pd_set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
                                current != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
                                current = current->_next) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    tty->print_cr("pd set = #%d", count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
};
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   220
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   221
// Entry in a SymbolPropertyTable, mapping a single symbolOop
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   222
// to a managed and an unmanaged pointer.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   223
class SymbolPropertyEntry : public HashtableEntry {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   224
  friend class VMStructs;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   225
 private:
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   226
  intptr_t _symbol_mode;  // secondary key
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   227
  oop     _property_oop;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   228
  address _property_data;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   229
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   230
 public:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   231
  symbolOop symbol() const          { return (symbolOop) literal(); }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   232
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   233
  intptr_t symbol_mode() const      { return _symbol_mode; }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   234
  void set_symbol_mode(intptr_t m)  { _symbol_mode = m; }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   235
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   236
  oop      property_oop() const     { return _property_oop; }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   237
  void set_property_oop(oop p)      { _property_oop = p; }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   238
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   239
  address  property_data() const    { return _property_data; }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   240
  void set_property_data(address p) { _property_data = p; }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   241
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   242
  SymbolPropertyEntry* next() const {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   243
    return (SymbolPropertyEntry*)HashtableEntry::next();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   244
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   245
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   246
  SymbolPropertyEntry** next_addr() {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   247
    return (SymbolPropertyEntry**)HashtableEntry::next_addr();
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
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   250
  oop* symbol_addr()                { return literal_addr(); }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   251
  oop* property_oop_addr()          { return &_property_oop; }
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
  void print_on(outputStream* st) const {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   254
    symbol()->print_value_on(st);
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   255
    st->print("/mode="INTX_FORMAT, symbol_mode());
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   256
    st->print(" -> ");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   257
    bool printed = false;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   258
    if (property_oop() != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   259
      property_oop()->print_value_on(st);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   260
      printed = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   261
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   262
    if (property_data() != NULL) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   263
      if (printed)  st->print(" and ");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   264
      st->print(INTPTR_FORMAT, property_data());
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   265
      printed = true;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   266
    }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   267
    st->print_cr(printed ? "" : "(empty)");
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   268
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   269
};
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
// A system-internal mapping of symbols to pointers, both managed
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   272
// and unmanaged.  Used to record the auto-generation of each method
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   273
// MethodHandle.invoke(S)T, for all signatures (S)T.
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   274
class SymbolPropertyTable : public Hashtable {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   275
  friend class VMStructs;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   276
private:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   277
  SymbolPropertyEntry* bucket(int i) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   278
    return (SymbolPropertyEntry*) Hashtable::bucket(i);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   279
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   280
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   281
  // 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
   282
  SymbolPropertyEntry** bucket_addr(int i) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   283
    return (SymbolPropertyEntry**) Hashtable::bucket_addr(i);
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
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   286
  void add_entry(int index, SymbolPropertyEntry* new_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   287
    ShouldNotReachHere();
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
  void set_entry(int index, SymbolPropertyEntry* new_entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   290
    ShouldNotReachHere();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   291
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   292
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   293
  SymbolPropertyEntry* new_entry(unsigned int hash, symbolOop symbol, intptr_t symbol_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   294
    SymbolPropertyEntry* entry = (SymbolPropertyEntry*) Hashtable::new_entry(hash, symbol);
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   295
    entry->set_symbol_mode(symbol_mode);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   296
    entry->set_property_oop(NULL);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   297
    entry->set_property_data(NULL);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   298
    return entry;
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   299
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   300
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   301
public:
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   302
  SymbolPropertyTable(int table_size);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   303
  SymbolPropertyTable(int table_size, HashtableBucket* t, int number_of_entries);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   304
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   305
  void free_entry(SymbolPropertyEntry* entry) {
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   306
    Hashtable::free_entry(entry);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   307
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   308
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   309
  unsigned int compute_hash(symbolHandle sym, intptr_t symbol_mode) {
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   310
    // Use the regular identity_hash.
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   311
    return Hashtable::compute_hash(sym) ^ symbol_mode;
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   312
  }
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   313
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   314
  int index_for(symbolHandle name, intptr_t symbol_mode) {
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   315
    return hash_to_index(compute_hash(name, symbol_mode));
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   316
  }
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   317
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   318
  // need not be locked; no state change
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   319
  SymbolPropertyEntry* find_entry(int index, unsigned int hash, symbolHandle name, intptr_t name_mode);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   320
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   321
  // must be done under SystemDictionary_lock
5420
586d3988e72b 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 2534
diff changeset
   322
  SymbolPropertyEntry* add_entry(int index, unsigned int hash, symbolHandle name, intptr_t name_mode);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   323
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   324
  // GC support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   325
  void oops_do(OopClosure* f);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   326
  void methods_do(void f(methodOop));
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   327
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   328
  // Sharing support
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   329
  void dump(SerializeOopClosure* soc);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   330
  void restore(SerializeOopClosure* soc);
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   331
  void reorder_dictionary();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   332
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   333
#ifndef PRODUCT
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   334
  void print();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   335
#endif
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   336
  void verify();
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   337
};
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1
diff changeset
   338