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