hotspot/src/share/vm/memory/dump.cpp
author coleenp
Wed, 13 Jun 2012 19:52:59 -0400
changeset 13087 673ea6efaf18
parent 12623 09fcb0dc71ad
child 13283 a9e7a1234f89
permissions -rw-r--r--
7158800: Improve storage of symbol tables Summary: Use an alternate version of hashing algorithm for symbol string tables and after a certain bucket size to improve performance Reviewed-by: pbk, kamg, dlong, kvn, fparain
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11407
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: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
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: 4571
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/loaderConstraints.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "gc_implementation/shared/spaceDecorator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/classify.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "memory/filemap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "memory/oopFactory.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "oops/methodDataOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/javaCalls.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/vmThread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "runtime/vm_operations.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
#include "utilities/copy.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Closure to set up the fingerprint field for all methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class FingerprintMethodsClosure: public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    if (obj->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      methodOop mobj = (methodOop)obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      (new Fingerprinter(mobj))->fingerprint();
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// Closure to set the hash value (String.hash field) in all of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// String objects in the heap.  Setting the hash value is not required.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// However, setting the value in advance prevents the value from being
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// written later, increasing the likelihood that the shared page contain
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// the hash can be shared.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12623
diff changeset
    65
// NOTE THAT we have to call java_lang_String::to_hash() to match the
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12623
diff changeset
    66
// algorithm in java.lang.String.toHash().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
class StringHashCodeClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  Thread* THREAD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  int hash_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  StringHashCodeClosure(Thread* t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    THREAD = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    hash_offset = java_lang_String::hash_offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    78
  void do_oop(oop* p) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    79
    if (p != NULL) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    80
      oop obj = *p;
12623
09fcb0dc71ad 6924259: Remove String.count/String.offset
kvn
parents: 12267
diff changeset
    81
      if (obj->klass() == SystemDictionary::String_klass() &&
09fcb0dc71ad 6924259: Remove String.count/String.offset
kvn
parents: 12267
diff changeset
    82
          java_lang_String::has_hash_field()) {
13087
673ea6efaf18 7158800: Improve storage of symbol tables
coleenp
parents: 12623
diff changeset
    83
        int hash = java_lang_String::to_hash(obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
        obj->int_field_put(hash_offset, hash);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    88
  void do_oop(narrowOop* p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// Remove data from objects which should not appear in the shared file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// (as it pertains only to the current JVM).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
class RemoveUnshareableInfoClosure : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    // Zap data from the objects which is pertains only to this JVM.  We
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // want that data recreated in new JVMs when the shared file is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    if (obj->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      ((methodOop)obj)->remove_unshareable_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    else if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      Klass::cast((klassOop)obj)->remove_unshareable_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    // Don't save compiler related special oops (shouldn't be any yet).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (obj->is_methodData() || obj->is_compiledICHolder()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
static bool mark_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  if (obj != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      !obj->is_shared() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      !obj->is_forwarded() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      !obj->is_gc_marked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    obj->set_mark(markOopDesc::prototype()->set_marked());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   127
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   128
class MoveSymbols : public SymbolClosure {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   129
private:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   130
  char* _start;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   131
  char* _end;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   132
  char* _top;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   133
  int _count;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   134
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   135
  bool in_shared_space(Symbol* sym) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   136
    return (char*)sym >= _start && (char*)sym < _end;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   137
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   138
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   139
  Symbol* get_shared_copy(Symbol* sym) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   140
    return sym->refcount() > 0 ? NULL : (Symbol*)(_start - sym->refcount());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   141
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   142
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   143
  Symbol* make_shared_copy(Symbol* sym) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   144
    Symbol* new_sym = (Symbol*)_top;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   145
    int size = sym->object_size();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   146
    _top += size * HeapWordSize;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   147
    if (_top <= _end) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   148
      Copy::disjoint_words((HeapWord*)sym, (HeapWord*)new_sym, size);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   149
      // Encode a reference to the copy as a negative distance from _start
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   150
      // When a symbol is being copied to a shared space
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   151
      // during CDS archive creation, the original symbol is marked
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   152
      // as relocated by putting a negative value to its _refcount field,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   153
      // This value is also used to find where exactly the shared copy is
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   154
      // (see MoveSymbols::get_shared_copy), so that the other references
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   155
      // to this symbol could be changed to point to the shared copy.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   156
      sym->_refcount = (int)(_start - (char*)new_sym);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   157
      // Mark the symbol in the shared archive as immortal so it is read only
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   158
      // and not refcounted.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   159
      new_sym->_refcount = -1;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   160
      _count++;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   161
    } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   162
      report_out_of_shared_space(SharedMiscData);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   163
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   164
    return new_sym;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   165
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   166
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   167
public:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   168
  MoveSymbols(char* top, char* end) :
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   169
    _start(top), _end(end), _top(top), _count(0) { }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   170
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   171
  char* get_top() const { return _top; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   172
  int count()     const { return _count; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   173
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   174
  void do_symbol(Symbol** p) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   175
    Symbol* sym = load_symbol(p);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   176
    if (sym != NULL && !in_shared_space(sym)) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   177
      Symbol* new_sym = get_shared_copy(sym);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   178
      if (new_sym == NULL) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   179
        // The symbol has not been relocated yet; copy it to _top address
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   180
        assert(sym->refcount() > 0, "should have positive reference count");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   181
        new_sym = make_shared_copy(sym);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   182
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   183
      // Make the reference point to the shared copy of the symbol
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   184
      store_symbol(p, new_sym);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   185
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   186
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   187
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   188
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   189
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// Closure:  mark objects closure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
class MarkObjectsOopClosure : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
public:
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   194
  void do_oop(oop* p)       { mark_object(*p); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   195
  void do_oop(narrowOop* p) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
class MarkObjectsSkippingKlassesOopClosure : public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  void do_oop(oop* pobj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    oop obj = *pobj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    if (obj != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        !obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      mark_object(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   208
  void do_oop(narrowOop* pobj) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
static void mark_object_recursive_skipping_klasses(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  mark_object(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if (obj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    MarkObjectsSkippingKlassesOopClosure mark_all;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    obj->oop_iterate(&mark_all);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   221
// Closure:  mark common read-only objects
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
class MarkCommonReadOnly : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  MarkObjectsOopClosure mark_all;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    // Mark all constMethod objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    if (obj->is_constMethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      mark_object(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      mark_object(constMethodOop(obj)->stackmap_data());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      // Exception tables are needed by ci code during compilation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      mark_object(constMethodOop(obj)->exception_table());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    // Mark objects referenced by klass objects which are read-only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    else if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      Klass* k = Klass::cast((klassOop)obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      mark_object(k->secondary_supers());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      // The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      // it is never modified. Otherwise, they will be pre-marked; the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      // GC marking phase will skip them; and by skipping them will fail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      // to mark the methods objects referenced by the array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      if (obj->blueprint()->oop_is_instanceKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        instanceKlass* ik = instanceKlass::cast((klassOop)obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        mark_object(ik->method_ordering());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        mark_object(ik->local_interfaces());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        mark_object(ik->transitive_interfaces());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        mark_object(ik->fields());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        mark_object(ik->class_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        mark_object_recursive_skipping_klasses(ik->fields_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        mark_object_recursive_skipping_klasses(ik->methods_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        mark_object_recursive_skipping_klasses(ik->methods_parameter_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        mark_object_recursive_skipping_klasses(ik->methods_default_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        typeArrayOop inner_classes = ik->inner_classes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        if (inner_classes != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
          mark_object(inner_classes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   273
// Closure:  find symbol references in Java Heap objects
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   275
class CommonSymbolsClosure : public ObjectClosure {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
private:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   277
  SymbolClosure* _closure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   279
  CommonSymbolsClosure(SymbolClosure* closure) : _closure(closure) { }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   280
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   283
    // Traverse symbols referenced by method objects.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    if (obj->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      methodOop m = methodOop(obj);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   287
      constantPoolOop constants = m->constants();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   288
      _closure->do_symbol(constants->symbol_at_addr(m->name_index()));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   289
      _closure->do_symbol(constants->symbol_at_addr(m->signature_index()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   292
    // Traverse symbols referenced by klass objects which are read-only.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    else if (obj->is_klass()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   295
      Klass* k = Klass::cast((klassOop)obj);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   296
      k->shared_symbols_iterate(_closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      if (obj->blueprint()->oop_is_instanceKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        instanceKlass* ik = instanceKlass::cast((klassOop)obj);
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   300
        instanceKlassHandle ik_h((klassOop)obj);
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   301
        InnerClassesIterator iter(ik_h);
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   302
        constantPoolOop constants = ik->constants();
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   303
        for (; !iter.done(); iter.next()) {
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   304
          int index = iter.inner_name_index();
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   305
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   306
          if (index != 0) {
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 11407
diff changeset
   307
            _closure->do_symbol(constants->symbol_at_addr(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   313
    // Traverse symbols referenced by other constantpool entries.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   315
    else if (obj->is_constantPool()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   316
      constantPoolOop(obj)->shared_symbols_iterate(_closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// Closure:  mark char arrays used by strings
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
class MarkStringValues : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  MarkObjectsOopClosure mark_all;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    // Character arrays referenced by String objects are read-only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    if (java_lang_String::is_instance(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      mark_object(java_lang_String::value(obj));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
#ifdef DEBUG
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
// Closure:  Check for objects left in the heap which have not been moved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
class CheckRemainingObjects : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  int count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  CheckRemainingObjects() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    if (!obj->is_shared() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
        !obj->is_forwarded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      ++count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      if (Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
        tty->print("Unreferenced object: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
        obj->print_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  void status() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    tty->print_cr("%d objects no longer referenced, not shared.", count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// Closure:  Mark remaining objects read-write, except Strings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
class MarkReadWriteObjects : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  MarkObjectsOopClosure mark_objects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      // The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      // it is never modified. Otherwise, they will be pre-marked; the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      // GC marking phase will skip them; and by skipping them will fail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      // to mark the methods objects referenced by the array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      mark_object(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      Klass* k = klassOop(obj)->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      mark_object(k->java_mirror());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      if (obj->blueprint()->oop_is_instanceKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
        instanceKlass* ik = (instanceKlass*)k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
        mark_object(ik->methods());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
        mark_object(ik->constants());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      if (obj->blueprint()->oop_is_javaArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        arrayKlass* ak = (arrayKlass*)k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        mark_object(ak->component_mirror());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    // Mark constantPool tags and the constantPoolCache.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    else if (obj->is_constantPool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      constantPoolOop pool = constantPoolOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      mark_object(pool->cache());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      pool->shared_tags_iterate(&mark_objects);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    // Mark all method objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    if (obj->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      mark_object(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
// Closure:  Mark String objects read-write.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
class MarkStringObjects : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  MarkObjectsOopClosure mark_objects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    // Mark String objects referenced by constant pool entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    if (obj->is_constantPool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      constantPoolOop pool = constantPoolOop(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      pool->shared_strings_iterate(&mark_objects);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
// Move objects matching specified type (ie. lock_bits) to the specified
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
// space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
class MoveMarkedObjects : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  OffsetTableContigSpace* _space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  bool _read_only;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  MoveMarkedObjects(OffsetTableContigSpace* space, bool read_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    _space = space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    _read_only = read_only;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    if (obj->is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    if (obj->is_gc_marked() && obj->forwardee() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      int s = obj->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      oop sh_obj = (oop)_space->allocate(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      if (sh_obj == NULL) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   457
        report_out_of_shared_space(_read_only ? SharedReadOnly : SharedReadWrite);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
      if (PrintSharedSpaces && Verbose && WizardMode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
        tty->print_cr("\nMoveMarkedObjects: " PTR_FORMAT " -> " PTR_FORMAT " %s", obj, sh_obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
                      (_read_only ? "ro" : "rw"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)sh_obj, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
      obj->forward_to(sh_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      if (_read_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
        // Readonly objects: set hash value to self pointer and make gc_marked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
        sh_obj->forward_to(sh_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
        sh_obj->init_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
static void mark_and_move(oop obj, MoveMarkedObjects* move) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  if (mark_object(obj)) move->do_object(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
enum order_policy {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  OP_favor_startup = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  OP_balanced = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  OP_favor_runtime = 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
static void mark_and_move_for_policy(order_policy policy, oop obj, MoveMarkedObjects* move) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  if (SharedOptimizeColdStartPolicy >= policy) mark_and_move(obj, move);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
class MarkAndMoveOrderedReadOnly : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  MoveMarkedObjects *_move_ro;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  MarkAndMoveOrderedReadOnly(MoveMarkedObjects *move_ro) : _move_ro(move_ro) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    if (obj->is_klass() && obj->blueprint()->oop_is_instanceKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      instanceKlass* ik = instanceKlass::cast((klassOop)obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
      int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
      if (ik->super() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
        do_object(ik->super());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
      objArrayOop interfaces = ik->local_interfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
      mark_and_move_for_policy(OP_favor_startup, interfaces, _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      for(i = 0; i < interfaces->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
        klassOop k = klassOop(interfaces->obj_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
        do_object(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
      objArrayOop methods = ik->methods();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
      for(i = 0; i < methods->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
        methodOop m = methodOop(methods->obj_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
        mark_and_move_for_policy(OP_favor_startup, m->constMethod(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
        mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->exception_table(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
        mark_and_move_for_policy(OP_favor_runtime, m->constMethod()->stackmap_data(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      mark_and_move_for_policy(OP_favor_startup, ik->transitive_interfaces(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      mark_and_move_for_policy(OP_favor_startup, ik->fields(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      mark_and_move_for_policy(OP_favor_runtime, ik->secondary_supers(),  _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      mark_and_move_for_policy(OP_favor_runtime, ik->method_ordering(),   _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
      mark_and_move_for_policy(OP_favor_runtime, ik->class_annotations(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      mark_and_move_for_policy(OP_favor_runtime, ik->fields_annotations(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      mark_and_move_for_policy(OP_favor_runtime, ik->methods_annotations(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      mark_and_move_for_policy(OP_favor_runtime, ik->methods_parameter_annotations(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      mark_and_move_for_policy(OP_favor_runtime, ik->methods_default_annotations(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      mark_and_move_for_policy(OP_favor_runtime, ik->inner_classes(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      mark_and_move_for_policy(OP_favor_runtime, ik->secondary_supers(), _move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
class MarkAndMoveOrderedReadWrite: public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  MoveMarkedObjects *_move_rw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  MarkAndMoveOrderedReadWrite(MoveMarkedObjects *move_rw) : _move_rw(move_rw) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    if (obj->is_klass() && obj->blueprint()->oop_is_instanceKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      instanceKlass* ik = instanceKlass::cast((klassOop)obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      mark_and_move_for_policy(OP_favor_startup, ik->as_klassOop(), _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      if (ik->super() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
        do_object(ik->super());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
      objArrayOop interfaces = ik->local_interfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
      for(i = 0; i < interfaces->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
        klassOop k = klassOop(interfaces->obj_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
        mark_and_move_for_policy(OP_favor_startup, k, _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
        do_object(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
      objArrayOop methods = ik->methods();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      mark_and_move_for_policy(OP_favor_startup, methods, _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      for(i = 0; i < methods->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
        methodOop m = methodOop(methods->obj_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
        mark_and_move_for_policy(OP_favor_startup, m, _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
        mark_and_move_for_policy(OP_favor_startup, ik->constants(), _move_rw);          // idempotent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
        mark_and_move_for_policy(OP_balanced, ik->constants()->cache(), _move_rw); // idempotent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
        mark_and_move_for_policy(OP_balanced, ik->constants()->tags(), _move_rw);  // idempotent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      mark_and_move_for_policy(OP_favor_startup, ik->as_klassOop()->klass(), _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      mark_and_move_for_policy(OP_favor_startup, ik->constants()->klass(), _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
      // Although Java mirrors are marked in MarkReadWriteObjects,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
      // apparently they were never moved into shared spaces since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
      // MoveMarkedObjects skips marked instance oops.  This may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
      // be a bug in the original implementation or simply the vestige
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
      // of an abandoned experiment.  Nevertheless we leave a hint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
      // here in case this capability is ever correctly implemented.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      // mark_and_move_for_policy(OP_favor_runtime, ik->java_mirror(), _move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
// Adjust references in oops to refer to shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
class ResolveForwardingClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  void do_oop(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    if (!obj->is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
      if (obj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
        oop f = obj->forwardee();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
        guarantee(f->is_shared(), "Oop doesn't refer to shared space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
        *p = f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   601
  void do_oop(narrowOop* pobj) { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   605
// The methods array must be reordered by Symbol* address.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   606
// (See classFileParser.cpp where methods in a class are originally
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   607
// sorted). The addresses of symbols have been changed as a result
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   608
// of moving to the shared space.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
class SortMethodsClosure: public ObjectClosure {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   611
public:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   612
  void do_object(oop obj) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   613
    if (obj->blueprint()->oop_is_instanceKlass()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   614
      instanceKlass* ik = instanceKlass::cast((klassOop)obj);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   615
      methodOopDesc::sort_methods(ik->methods(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   616
                                  ik->methods_annotations(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   617
                                  ik->methods_parameter_annotations(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   618
                                  ik->methods_default_annotations(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   619
                                  true /* idempotent, slow */);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   620
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   621
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   622
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   623
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   624
// Vtable and Itable indices are calculated based on methods array
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   625
// order (see klassItable::compute_itable_index()).  Must reinitialize
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   626
// after ALL methods of ALL classes have been reordered.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   627
// We assume that since checkconstraints is false, this method
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   628
// cannot throw an exception.  An exception here would be
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   629
// problematic since this is the VMThread, not a JavaThread.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   630
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   631
class ReinitializeTables: public ObjectClosure {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  Thread* _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
public:
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   636
  ReinitializeTables(Thread* thread) : _thread(thread) {}
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   637
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   638
  // Initialize super vtable first, check if already initialized to avoid
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   639
  // quadradic behavior.  The vtable is cleared in remove_unshareable_info.
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   640
  void reinitialize_vtables(klassOop k) {
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   641
    if (k->blueprint()->oop_is_instanceKlass()) {
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   642
      instanceKlass* ik = instanceKlass::cast(k);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   643
      if (ik->vtable()->is_initialized()) return;
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   644
      if (ik->super() != NULL) {
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   645
        reinitialize_vtables(ik->super());
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   646
      }
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   647
      ik->vtable()->initialize_vtable(false, _thread);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   648
    }
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   649
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    if (obj->blueprint()->oop_is_instanceKlass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
      instanceKlass* ik = instanceKlass::cast((klassOop)obj);
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   654
      ResourceMark rm(_thread);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   655
      ik->itable()->initialize_itable(false, _thread);
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   656
      reinitialize_vtables((klassOop)obj);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   657
#ifdef ASSERT
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   658
      ik->vtable()->verify(tty, true);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   659
#endif // ASSERT
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   660
    } else if (obj->blueprint()->oop_is_arrayKlass()) {
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   661
      // The vtable for array klasses are that of its super class,
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   662
      // ie. java.lang.Object.
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   663
      arrayKlass* ak = arrayKlass::cast((klassOop)obj);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   664
      if (ak->vtable()->is_initialized()) return;
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
   665
      ak->vtable()->initialize_vtable(false, _thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
// Adjust references in oops to refer to shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
class PatchOopsClosure: public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  Thread* _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  ResolveForwardingClosure resolve;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  PatchOopsClosure(Thread* thread) : _thread(thread) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    obj->oop_iterate_header(&resolve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    obj->oop_iterate(&resolve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    assert(obj->klass()->is_shared(), "Klass not pointing into shared space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    // If the object is a Java object or class which might (in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    // future) contain a reference to a young gen object, add it to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    // list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    if (obj->is_klass() || obj->is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      if (obj->is_klass() ||
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 2538
diff changeset
   693
          obj->is_a(SystemDictionary::Class_klass()) ||
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 2538
diff changeset
   694
          obj->is_a(SystemDictionary::Throwable_klass())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        // Do nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      }
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 2538
diff changeset
   697
      else if (obj->is_a(SystemDictionary::String_klass())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
        // immutable objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
        // someone added an object we hadn't accounted for.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
        ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
// Empty the young and old generations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
class ClearSpaceClosure : public SpaceClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  void do_space(Space* s) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 360
diff changeset
   713
    s->clear(SpaceDecorator::Mangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
// Closure for serializing initialization data out to a data area to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
// written to the shared file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
class WriteClosure : public SerializeOopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  oop* top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  char* end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  inline void check_space() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    if ((char*)top + sizeof(oop) > end) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   728
      report_out_of_shared_space(SharedMiscData);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  WriteClosure(char* md_top, char* md_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    top = (oop*)md_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    end = md_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  char* get_top() { return (char*)top; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  void do_oop(oop* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    check_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    oop obj = *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    assert(obj->is_oop_or_null(), "invalid oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    assert(obj == NULL || obj->is_shared(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
           "Oop in shared space not pointing into shared space.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    *top = obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
    ++top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   751
  void do_oop(narrowOop* pobj) { ShouldNotReachHere(); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   752
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  void do_int(int* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    check_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    *top = (oop)(intptr_t)*p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
    ++top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  void do_size_t(size_t* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    check_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    *top = (oop)(intptr_t)*p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    ++top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  void do_ptr(void** p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
    check_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    *top = (oop)*p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    ++top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  void do_ptr(HeapWord** p) { do_ptr((void **) p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  void do_tag(int tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    check_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    *top = (oop)(intptr_t)tag;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    ++top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  void do_region(u_char* start, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    if ((char*)top + size > end) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   781
      report_out_of_shared_space(SharedMiscData);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    assert((intptr_t)start % sizeof(oop) == 0, "bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    assert(size % sizeof(oop) == 0, "bad size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    do_tag((int)size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    while (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      *top = *(oop*)start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      ++top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      start += sizeof(oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
      size -= sizeof(oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  bool reading() const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
class ResolveConstantPoolsClosure : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  TRAPS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  ResolveConstantPoolsClosure(Thread *t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    __the_thread__ = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
    if (obj->is_constantPool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      constantPoolOop cpool = (constantPoolOop)obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      int unresolved = cpool->pre_resolve_shared_klasses(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
// Print a summary of the contents of the read/write spaces to help
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
// identify objects which might be able to be made read-only.  At this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
// point, the objects have been written, and we can trash them as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
// needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
static void print_contents() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  if (PrintSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    // High level summary of the read-only space:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    ClassifyObjectClosure coc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    tty->cr(); tty->print_cr("ReadOnly space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    gen->ro_space()->object_iterate(&coc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    coc.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    // High level summary of the read-write space:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    coc.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    tty->cr(); tty->print_cr("ReadWrite space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    gen->rw_space()->object_iterate(&coc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    coc.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    // Reset counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    ClearAllocCountClosure cacc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    gen->ro_space()->object_iterate(&cacc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    gen->rw_space()->object_iterate(&cacc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    coc.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    // Lower level summary of the read-only space:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    gen->ro_space()->object_iterate(&coc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    tty->cr(); tty->print_cr("ReadOnly space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    ClassifyInstanceKlassClosure cikc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    gen->rw_space()->object_iterate(&cikc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    cikc.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    // Reset counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    gen->ro_space()->object_iterate(&cacc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    gen->rw_space()->object_iterate(&cacc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    coc.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    // Lower level summary of the read-write space:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    gen->rw_space()->object_iterate(&coc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    cikc.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    tty->cr();  tty->print_cr("ReadWrite space:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    gen->rw_space()->object_iterate(&cikc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    cikc.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
// Patch C++ vtable pointer in klass oops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
// Klass objects contain references to c++ vtables in the JVM library.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
// Fix them to point to our constructed vtables.  However, don't iterate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
// across the space while doing this, as that causes the vtables to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
// patched, undoing our useful work.  Instead, iterate to make a list,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
// then use the list to do the fixing.
1440
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   877
//
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   878
// Our constructed vtables:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   879
// Dump time:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   880
//  1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   881
//  2. generate_vtable_methods: create jump table, appended to above vtbl_list
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   882
//  3. PatchKlassVtables: for Klass list, patch the vtable entry to point to jump table
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   883
//     rather than to current vtbl
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   884
// Table layout: NOTE FIXED SIZE
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   885
//   1. vtbl pointers
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   886
//   2. #Klass X #virtual methods per Klass
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   887
//   1 entry for each, in the order:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   888
//   Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   889
//   Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   890
//   ...
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   891
//   Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry,
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   892
//       ... Klass<vtbl_list_size>:method<num_virtuals> entry
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   893
//  Sample entry: (Sparc):
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   894
//   save(sp, -256, sp)
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   895
//   ba,pt common_code
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   896
//   mov XXX, %L0       %L0 gets: Klass index <<8 + method index (note: max method index 255)
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   897
//
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   898
// Restore time:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   899
//   1. initialize_oops: reserve space for table
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   900
//   2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   901
//
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   902
// Execution time:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   903
//   First virtual method call for any object of these Klass types:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   904
//   1. object->klass->klass_part
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   905
//   2. vtable entry for that klass_part points to the jump table entries
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   906
//   3. branches to common_code with %O0/klass_part, %L0: Klass index <<8 + method index
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   907
//   4. common_code:
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   908
//      Get address of new vtbl pointer for this Klass from updated table
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   909
//      Update new vtbl pointer in the Klass: future virtual calls go direct
32e1f7935659 6761092: jvm crashes when CDS is enabled.
acorn
parents: 996
diff changeset
   910
//      Jump to method, using new vtbl pointer and method index
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
class PatchKlassVtables: public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  GrowableArray<klassOop>* _klass_objects;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
public:
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   917
  PatchKlassVtables() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    _klass_objects = new GrowableArray<klassOop>();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
      _klass_objects->append(klassOop(obj));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   927
  void patch(void** vtbl_list, void* new_vtable_start) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   928
    int n = _klass_objects->length();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   929
    for (int i = 0; i < n; i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      klassOop obj = (klassOop)_klass_objects->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
      Klass* k = obj->klass_part();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   932
      *(void**)k = CompactingPermGenGen::find_matching_vtbl_ptr(
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   933
                     vtbl_list, new_vtable_start, k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   938
// Walk through all symbols and patch their vtable pointers.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   939
// Note that symbols have vtable pointers only in non-product builds
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   940
// (see allocation.hpp).
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   941
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   942
#ifndef PRODUCT
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   943
class PatchSymbolVtables: public SymbolClosure {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   944
private:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   945
  void* _new_vtbl_ptr;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   946
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   947
public:
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   948
  PatchSymbolVtables(void** vtbl_list, void* new_vtable_start) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   949
    Symbol s;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   950
    _new_vtbl_ptr = CompactingPermGenGen::find_matching_vtbl_ptr(
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   951
                      vtbl_list, new_vtable_start, &s);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   952
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   953
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   954
  void do_symbol(Symbol** p) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   955
    Symbol* sym = load_symbol(p);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   956
    *(void**)sym = _new_vtbl_ptr;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   957
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   958
};
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   959
#endif
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
   960
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
// Populate the shared space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
class VM_PopulateDumpSharedSpace: public VM_Operation {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  GrowableArray<oop> *_class_promote_order;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  OffsetTableContigSpace* _ro_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  OffsetTableContigSpace* _rw_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  VirtualSpace* _md_vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  VirtualSpace* _mc_vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  VM_PopulateDumpSharedSpace(GrowableArray<oop> *class_promote_order,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
                             OffsetTableContigSpace* ro_space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
                             OffsetTableContigSpace* rw_space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
                             VirtualSpace* md_vs, VirtualSpace* mc_vs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    _class_promote_order = class_promote_order;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
    _ro_space = ro_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    _rw_space = rw_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    _md_vs = md_vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    _mc_vs = mc_vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  void doit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    Thread* THREAD = VMThread::vm_thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    NOT_PRODUCT(SystemDictionary::verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    // The following guarantee is meant to ensure that no loader constraints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    // exist yet, since the constraints table is not shared.  This becomes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    // more important now that we don't re-initialize vtables/itables for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    // shared classes at runtime, where constraints were previously created.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
              "loader constraints are not saved");
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1440
diff changeset
   994
    // Revisit and implement this if we prelink method handle call sites:
2538
1ecc4413e7e7 6831604: missing null check in guarantee
never
parents: 2534
diff changeset
   995
    guarantee(SystemDictionary::invoke_method_table() == NULL ||
1ecc4413e7e7 6831604: missing null check in guarantee
never
parents: 2534
diff changeset
   996
              SystemDictionary::invoke_method_table()->number_of_entries() == 0,
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 1440
diff changeset
   997
              "invoke method table is not saved");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
    // At this point, many classes have been loaded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    // Update all the fingerprints in the shared methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    tty->print("Calculating fingerprints ... ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    FingerprintMethodsClosure fpmc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    gch->object_iterate(&fpmc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    tty->print_cr("done. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    // Remove all references outside the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    tty->print("Removing unshareable information ... ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    RemoveUnshareableInfoClosure ruic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
    gch->object_iterate(&ruic);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
    tty->print_cr("done. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
    // Move the objects in three passes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    MarkObjectsOopClosure mark_all;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
    MarkCommonReadOnly mark_common_ro;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
    MarkStringValues mark_string_values;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
    MarkReadWriteObjects mark_rw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
    MarkStringObjects mark_strings;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
    MoveMarkedObjects move_ro(_ro_space, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    MoveMarkedObjects move_rw(_rw_space, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
    // The SharedOptimizeColdStart VM option governs the new layout
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    // algorithm for promoting classes into the shared archive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    // The general idea is to minimize cold start time by laying
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    // out the objects in the order they are accessed at startup time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    // By doing this we are trying to eliminate out-of-order accesses
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    // in the shared archive.  This benefits cold startup time by making
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    // disk reads as sequential as possible during class loading and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    // bootstrapping activities.  There may also be a small secondary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    // effect of better "packing" of more commonly used data on a smaller
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    // number of pages, although no direct benefit has been measured from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    // this effect.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    // At the class level of granularity, the promotion order is dictated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    // by the classlist file whose generation is discussed elsewhere.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    // At smaller granularity, optimal ordering was determined by an
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    // offline analysis of object access order in the shared archive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    // The dbx watchpoint facility, combined with SA post-processing,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    // was used to observe common access patterns primarily during
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    // classloading.  This information was used to craft the promotion
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    // order seen in the following closures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    // The observed access order is mostly governed by what happens
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    // in SystemDictionary::load_shared_class().  NOTE WELL - care
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    // should be taken when making changes to this method, because it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
    // may invalidate assumptions made about access order!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    // (Ideally, there would be a better way to manage changes to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    //  the access order.  Unfortunately a generic in-VM solution for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
    //  dynamically observing access order and optimizing shared
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    //  archive layout is pretty difficult.  We go with the static
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    //  analysis because the code is fairly mature at this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    //  and we're betting that the access order won't change much.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    MarkAndMoveOrderedReadOnly  mark_and_move_ordered_ro(&move_ro);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    MarkAndMoveOrderedReadWrite mark_and_move_ordered_rw(&move_rw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    // Set up the share data and shared code segments.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    char* md_top = _md_vs->low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    char* md_end = _md_vs->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
    char* mc_top = _mc_vs->low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    char* mc_end = _mc_vs->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    // Reserve space for the list of klassOops whose vtables are used
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    // for patching others as needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    void** vtbl_list = (void**)md_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    int vtbl_list_size = CompactingPermGenGen::vtbl_list_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    md_top += vtbl_list_size * sizeof(void*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
    void* vtable = md_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    // Reserve space for a new dummy vtable for klass objects in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    // heap.  Generate self-patching vtable entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    CompactingPermGenGen::generate_vtable_methods(vtbl_list,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
                                                  &vtable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
                                                  &md_top, md_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
                                                  &mc_top, mc_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1088
    // Reserve space for the total size and the number of stored symbols.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1089
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1090
    md_top += sizeof(intptr_t) * 2;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1091
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1092
    MoveSymbols move_symbols(md_top, md_end);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1093
    CommonSymbolsClosure traverse_common_symbols(&move_symbols);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1094
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1095
    // Phase 1a: remove symbols with _refcount == 0
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1096
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1097
    SymbolTable::unlink();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1098
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1099
    // Phase 1b: move commonly used symbols referenced by oop fields.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1100
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1101
    tty->print("Moving common symbols to metadata section at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1102
               move_symbols.get_top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1103
    gch->object_iterate(&traverse_common_symbols);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1104
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1105
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1106
    // Phase 1c: move known names and signatures.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1107
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1108
    tty->print("Moving vmSymbols to metadata section at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1109
               move_symbols.get_top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1110
    vmSymbols::symbols_do(&move_symbols);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1111
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1112
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1113
    // Phase 1d: move the remaining symbols by scanning the whole SymbolTable.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1114
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1115
    void* extra_symbols = move_symbols.get_top();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1116
    tty->print("Moving the remaining symbols to metadata section at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1117
               move_symbols.get_top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1118
    SymbolTable::symbols_do(&move_symbols);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1119
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1120
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1121
    // Record the total length of all symbols at the beginning of the block.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1122
    ((intptr_t*)md_top)[-2] = move_symbols.get_top() - md_top;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1123
    ((intptr_t*)md_top)[-1] = move_symbols.count();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1124
    tty->print_cr("Moved %d symbols, %d bytes.",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1125
                  move_symbols.count(), move_symbols.get_top() - md_top);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1126
    // Advance the pointer to the end of symbol store.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1127
    md_top = move_symbols.get_top();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1128
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1129
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1130
    // Phase 2: move commonly used read-only objects to the read-only space.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1131
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1132
    if (SharedOptimizeColdStart) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1133
      tty->print("Moving pre-ordered read-only objects to shared space at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1134
                 _ro_space->top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1135
      for (int i = 0; i < _class_promote_order->length(); i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1136
        oop obj = _class_promote_order->at(i);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1137
        mark_and_move_ordered_ro.do_object(obj);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1138
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1139
      tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1140
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1141
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1142
    tty->print("Moving read-only objects to shared space at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1143
               _ro_space->top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1144
    gch->object_iterate(&mark_common_ro);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1145
    gch->object_iterate(&move_ro);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1146
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1147
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1148
    // Phase 3: move String character arrays to the read-only space.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1149
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1150
    tty->print("Moving string char arrays to shared space at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1151
               _ro_space->top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1152
    gch->object_iterate(&mark_string_values);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1153
    gch->object_iterate(&move_ro);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1154
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1155
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1156
    // Phase 4: move read-write objects to the read-write space, except
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1157
    // Strings.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1158
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1159
    if (SharedOptimizeColdStart) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1160
      tty->print("Moving pre-ordered read-write objects to shared space at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1161
                 _rw_space->top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1162
      for (int i = 0; i < _class_promote_order->length(); i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1163
        oop obj = _class_promote_order->at(i);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1164
        mark_and_move_ordered_rw.do_object(obj);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1165
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1166
      tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1167
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1168
    tty->print("Moving read-write objects to shared space at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1169
               _rw_space->top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1170
    Universe::oops_do(&mark_all, true);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1171
    SystemDictionary::oops_do(&mark_all);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1172
    oop tmp = Universe::arithmetic_exception_instance();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1173
    mark_object(java_lang_Throwable::message(tmp));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1174
    gch->object_iterate(&mark_rw);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1175
    gch->object_iterate(&move_rw);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1176
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1177
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1178
    // Phase 5: move String objects to the read-write space.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1179
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1180
    tty->print("Moving String objects to shared space at " PTR_FORMAT " ... ",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1181
               _rw_space->top());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1182
    StringTable::oops_do(&mark_all);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1183
    gch->object_iterate(&mark_strings);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1184
    gch->object_iterate(&move_rw);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1185
    tty->print_cr("done. ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1186
    tty->print_cr("Read-write space ends at " PTR_FORMAT ", %d bytes.",
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1187
                  _rw_space->top(), _rw_space->used());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1188
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1189
#ifdef DEBUG
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1190
    // Check: scan for objects which were not moved.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1191
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1192
    CheckRemainingObjects check_objects;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1193
    gch->object_iterate(&check_objects);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1194
    check_objects.status();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1195
#endif
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1196
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1197
    // Resolve forwarding in objects and saved C++ structures
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1198
    tty->print("Updating references to shared objects ... ");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1199
    ResolveForwardingClosure resolve;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1200
    Universe::oops_do(&resolve);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1201
    SystemDictionary::oops_do(&resolve);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1202
    StringTable::oops_do(&resolve);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1203
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    // Fix (forward) all of the references in these shared objects (which
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    // are required to point ONLY to objects in the shared spaces).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
    // Also, create a list of all objects which might later contain a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
    // reference to a younger generation object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
    PatchOopsClosure patch(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
    gen->ro_space()->object_iterate(&patch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    gen->rw_space()->object_iterate(&patch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
    // Previously method sorting was done concurrently with forwarding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    // pointer resolution in the shared spaces.  This imposed an ordering
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    // restriction in that methods were required to be promoted/patched
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    // before their holder classes.  (Because constant pool pointers in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    // methodKlasses are required to be resolved before their holder class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    // is visited for sorting, otherwise methods are sorted by incorrect,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
    // pre-forwarding addresses.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    // Now, we reorder methods as a separate step after ALL forwarding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    // pointer resolution, so that methods can be promoted in any order
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    // with respect to their holder classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1226
    SortMethodsClosure sort;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    gen->ro_space()->object_iterate(&sort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    gen->rw_space()->object_iterate(&sort);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1229
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
  1230
    ReinitializeTables reinit_tables(THREAD);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
  1231
    gen->ro_space()->object_iterate(&reinit_tables);
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8885
diff changeset
  1232
    gen->rw_space()->object_iterate(&reinit_tables);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    tty->print_cr("done. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    // Reorder the system dictionary.  (Moving the symbols opps affects
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    // how the hash table indices are calculated.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
    SystemDictionary::reorder_dictionary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    // Empty the non-shared heap (because most of the objects were
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    // copied out, and the remainder cannot be considered valid oops).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    ClearSpaceClosure csc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
    for (int i = 0; i < gch->n_gens(); ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
      gch->get_gen(i)->space_iterate(&csc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
    csc.do_space(gen->the_space());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
    NOT_PRODUCT(SystemDictionary::verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
    // Copy the String table, the symbol table, and the system
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
    // dictionary to the shared space in usable form.  Copy the hastable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
    // buckets first [read-write], then copy the linked lists of entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
    // [read-only].
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
    SymbolTable::reverse(extra_symbols);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
    NOT_PRODUCT(SymbolTable::verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
    SymbolTable::copy_buckets(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    StringTable::reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    NOT_PRODUCT(StringTable::verify());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    StringTable::copy_buckets(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    SystemDictionary::reverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    SystemDictionary::copy_buckets(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    ClassLoader::verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    ClassLoader::copy_package_info_buckets(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    ClassLoader::verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    SymbolTable::copy_table(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    StringTable::copy_table(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    SystemDictionary::copy_table(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    ClassLoader::verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
    ClassLoader::copy_package_info_table(&md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    ClassLoader::verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
    // Print debug data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
    if (PrintSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
      const char* fmt = "%s space: " PTR_FORMAT " out of " PTR_FORMAT " bytes allocated at " PTR_FORMAT ".";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
      tty->print_cr(fmt, "ro", _ro_space->used(), _ro_space->capacity(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
                    _ro_space->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
      tty->print_cr(fmt, "rw", _rw_space->used(), _rw_space->capacity(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
                    _rw_space->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
    // Write the oop data to the output array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
    WriteClosure wc(md_top, md_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
    CompactingPermGenGen::serialize_oops(&wc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
    md_top = wc.get_top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    // Update the vtable pointers in all of the Klass objects in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
    // heap. They should point to newly generated vtable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1297
    PatchKlassVtables pkvt;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
    _rw_space->object_iterate(&pkvt);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1299
    pkvt.patch(vtbl_list, vtable);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1300
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1301
#ifndef PRODUCT
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1302
    // Update the vtable pointers in all symbols,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1303
    // but only in non-product builds where symbols DO have virtual methods.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1304
    PatchSymbolVtables psvt(vtbl_list, vtable);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1305
    SymbolTable::symbols_do(&psvt);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1306
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
    char* saved_vtbl = (char*)malloc(vtbl_list_size * sizeof(void*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
    memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
    memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
    // Create and write the archive file that maps the shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    FileMapInfo* mapinfo = new FileMapInfo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
    mapinfo->populate_header(gch->gen_policy()->max_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    // Pass 1 - update file offsets in header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
    mapinfo->write_header();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
    mapinfo->write_space(CompactingPermGenGen::ro, _ro_space, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    _ro_space->set_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
    mapinfo->write_space(CompactingPermGenGen::rw, _rw_space, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
    _rw_space->set_saved_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
    mapinfo->write_region(CompactingPermGenGen::md, _md_vs->low(),
995
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1324
                          pointer_delta(md_top, _md_vs->low(), sizeof(char)),
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1325
                          SharedMiscDataSize,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
                          false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
    mapinfo->write_region(CompactingPermGenGen::mc, _mc_vs->low(),
995
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1328
                          pointer_delta(mc_top, _mc_vs->low(), sizeof(char)),
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1329
                          SharedMiscCodeSize,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
                          true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
    // Pass 2 - write data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
    mapinfo->open_for_write();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
    mapinfo->write_header();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
    mapinfo->write_space(CompactingPermGenGen::ro, _ro_space, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
    mapinfo->write_space(CompactingPermGenGen::rw, _rw_space, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
    mapinfo->write_region(CompactingPermGenGen::md, _md_vs->low(),
995
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1338
                          pointer_delta(md_top, _md_vs->low(), sizeof(char)),
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1339
                          SharedMiscDataSize,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
                          false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
    mapinfo->write_region(CompactingPermGenGen::mc, _mc_vs->low(),
995
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1342
                          pointer_delta(mc_top, _mc_vs->low(), sizeof(char)),
1a961ad82730 6459085: naked pointer subtractions in class data sharing code
xlu
parents: 670
diff changeset
  1343
                          SharedMiscCodeSize,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
                          true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
    mapinfo->close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    // Summarize heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    print_contents();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
}; // class VM_PopulateDumpSharedSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
// Populate the shared spaces and dump to a file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
jint CompactingPermGenGen::dump_shared(GrowableArray<oop>* class_promote_order, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  // Calculate hash values for all of the (interned) strings to avoid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
  // writes to shared pages in the future.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  tty->print("Calculating hash values for String objects .. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  StringHashCodeClosure shcc(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
  StringTable::oops_do(&shcc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
  tty->print_cr("done. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
  CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  VM_PopulateDumpSharedSpace op(class_promote_order,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
                                gen->ro_space(), gen->rw_space(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
                                gen->md_space(), gen->mc_space());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
  VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  return JNI_OK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1375
void* CompactingPermGenGen::find_matching_vtbl_ptr(void** vtbl_list,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1376
                                                   void* new_vtable_start,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1377
                                                   void* obj) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1378
  void* old_vtbl_ptr = *(void**)obj;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1379
  for (int i = 0; i < vtbl_list_size; i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1380
    if (vtbl_list[i] == old_vtbl_ptr) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1381
      return (void**)new_vtable_start + i * num_virtuals;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1382
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1383
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1384
  ShouldNotReachHere();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1385
  return NULL;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1386
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7405
diff changeset
  1387
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
class LinkClassesClosure : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
  Thread* THREAD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  LinkClassesClosure(Thread* thread) : THREAD(thread) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
    if (obj->is_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
      Klass* k = Klass::cast((klassOop) obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
      if (k->oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
        instanceKlass* ik = (instanceKlass*) k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
        // Link the class to cause the bytecodes to be rewritten and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
        // cpcache to be created.
11407
5399831730cd 7117052: instanceKlass::_init_state can be u1 type
coleenp
parents: 9172
diff changeset
  1403
        if (ik->init_state() < instanceKlass::linked) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
          ik->link_class(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
          guarantee(!HAS_PENDING_EXCEPTION, "exception in class rewriting");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
        // Create String objects from string initializer symbols.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
        ik->constants()->resolve_string_constants(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
        guarantee(!HAS_PENDING_EXCEPTION, "exception resolving string constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
// Support for a simple checksum of the contents of the class list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
// file to prevent trivial tampering. The algorithm matches that in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
// the MakeClassList program used by the J2SE build process.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
#define JSUM_SEED ((jlong)CONST64(0xcafebabebabecafe))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
static jlong
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
jsum(jlong start, const char *buf, const int len)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
    jlong h = start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    char *p = (char *)buf, *e = p + len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    while (p < e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
        char c = *p++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
        if (c <= ' ') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
            /* Skip spaces and control characters */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
            continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
        h = 31 * h + c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
    return h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
// Preload classes from a list, populate the shared spaces and dump to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
// file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
void GenCollectedHeap::preload_and_dump(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
  TraceTime timer("Dump Shared Spaces", TraceStartupTime);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
  // Preload classes to be shared.
7405
e6fc8d3926f8 6348631: remove the use of the HPI library from Hotspot
ikrylov
parents: 7397
diff changeset
  1449
  // Should use some os:: method rather than fopen() here. aB.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
  // Construct the path to the class list (in jre/lib)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  // Walk up two directories from the location of the VM and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  // optionally tack on "lib" (depending on platform)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  char class_list_path[JVM_MAXPATHLEN];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  os::jvm_path(class_list_path, sizeof(class_list_path));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  for (int i = 0; i < 3; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
    char *end = strrchr(class_list_path, *os::file_separator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
    if (end != NULL) *end = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
  int class_list_path_len = (int)strlen(class_list_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
  if (class_list_path_len >= 3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    if (strcmp(class_list_path + class_list_path_len - 3, "lib") != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
      strcat(class_list_path, os::file_separator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
      strcat(class_list_path, "lib");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  strcat(class_list_path, os::file_separator());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
  strcat(class_list_path, "classlist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
  FILE* file = fopen(class_list_path, "r");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
  if (file != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
    jlong computed_jsum  = JSUM_SEED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
    jlong file_jsum      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
    char class_name[256];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
    int class_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
    GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
    gch->_preloading_shared_classes = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
    GrowableArray<oop>* class_promote_order = new GrowableArray<oop>();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
    // Preload (and intern) strings which will be used later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
    StringTable::intern("main", THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
    StringTable::intern("([Ljava/lang/String;)V", THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
    StringTable::intern("Ljava/lang/Class;", THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
    StringTable::intern("I", THREAD);   // Needed for StringBuffer persistence?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
    StringTable::intern("Z", THREAD);   // Needed for StringBuffer persistence?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
    // sun.io.Converters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
    static const char obj_array_sig[] = "[[Ljava/lang/Object;";
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11407
diff changeset
  1491
    (void)SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
    // java.util.HashMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
    static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11407
diff changeset
  1495
    (void)SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
    tty->print("Loading classes to share ... ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
    while ((fgets(class_name, sizeof class_name, file)) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
      if (*class_name == '#') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
        jint fsh, fsl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
        if (sscanf(class_name, "# %8x%8x\n", &fsh, &fsl) == 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
          file_jsum = ((jlong)(fsh) << 32) | (fsl & 0xffffffff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
      // Remove trailing newline
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
      size_t name_len = strlen(class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
      class_name[name_len-1] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
      computed_jsum = jsum(computed_jsum, class_name, (const int)name_len - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
      // Got a class name - load it.
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 11407
diff changeset
  1514
      Symbol* class_name_symbol = SymbolTable::new_permanent_symbol(class_name, THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
      guarantee(!HAS_PENDING_EXCEPTION, "Exception creating a symbol.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
      klassOop klass = SystemDictionary::resolve_or_null(class_name_symbol,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
                                                         THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
      guarantee(!HAS_PENDING_EXCEPTION, "Exception resolving a class.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
      if (klass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
        if (PrintSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
          tty->print_cr("Shared spaces preloaded: %s", class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
        instanceKlass* ik = instanceKlass::cast(klass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
        // Should be class load order as per -XX:+TraceClassLoadingPreorder
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
        class_promote_order->append(ik->as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
        // Link the class to cause the bytecodes to be rewritten and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
        // cpcache to be created. The linking is done as soon as classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
        // are loaded in order that the related data structures (klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
        // cpCache, Sting constants) are located together.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
11407
5399831730cd 7117052: instanceKlass::_init_state can be u1 type
coleenp
parents: 9172
diff changeset
  1535
        if (ik->init_state() < instanceKlass::linked) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
          ik->link_class(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
          guarantee(!(HAS_PENDING_EXCEPTION), "exception in class rewriting");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
        // Create String objects from string initializer symbols.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
        ik->constants()->resolve_string_constants(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
        class_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
        if (PrintSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
          tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
          tty->print_cr(" Preload failed: %s", class_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
      file_jsum = 0; // Checksum must be on last line of file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
    if (computed_jsum != file_jsum) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
      tty->print_cr("Preload failed: checksum of class list was incorrect.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
      exit(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
    tty->print_cr("done. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
    if (PrintSharedSpaces) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
      tty->print_cr("Shared spaces: preloaded %d classes", class_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
    // Rewrite and unlink classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
    tty->print("Rewriting and unlinking classes ... ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
    // Make heap parsable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
    ensure_parsability(false); // arg is actually don't care
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
    // Link any classes which got missed.  (It's not quite clear why
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
    // they got missed.)  This iteration would be unsafe if we weren't
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
    // single-threaded at this point; however we can't do it on the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
    // thread because it requires object allocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
    LinkClassesClosure lcc(Thread::current());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
    object_iterate(&lcc);
8728
3f1bcd33068e 6962931: move interned strings out of the perm gen
jcoomes
parents: 8076
diff changeset
  1576
    ensure_parsability(false); // arg is actually don't care
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
    tty->print_cr("done. ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
    // Create and dump the shared spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
    jint err = CompactingPermGenGen::dump_shared(class_promote_order, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
    if (err != JNI_OK) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
      fatal("Dumping shared spaces failed.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
    char errmsg[JVM_MAXPATHLEN];
7405
e6fc8d3926f8 6348631: remove the use of the HPI library from Hotspot
ikrylov
parents: 7397
diff changeset
  1587
    os::lasterror(errmsg, JVM_MAXPATHLEN);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
    tty->print_cr("Loading classlist failed: %s", errmsg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
    exit(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
  // Since various initialization steps have been undone by this process,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  // it is not reasonable to continue running a java process.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
  exit(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
}