dump.cpp revision 710
/*
* Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
# include "incls/_precompiled.incl"
# include "incls/_dump.cpp.incl"
// Closure to set up the fingerprint field for all methods.
class FingerprintMethodsClosure: public ObjectClosure {
public:
}
}
};
// Closure to set the hash value (String.hash field) in all of the
// String objects in the heap. Setting the hash value is not required.
// However, setting the value in advance prevents the value from being
// written later, increasing the likelihood that the shared page contain
// the hash can be shared.
//
// NOTE THAT the algorithm in StringTable::hash_string() MUST MATCH the
// algorithm in java.lang.String.hashCode().
class StringHashCodeClosure: public OopClosure {
private:
int hash_offset;
public:
StringHashCodeClosure(Thread* t) {
THREAD = t;
}
if (p != NULL) {
int hash;
if (length == 0) {
hash = 0;
} else {
}
}
}
}
};
// Remove data from objects which should not appear in the shared file
// (as it pertains only to the current JVM).
class RemoveUnshareableInfoClosure : public ObjectClosure {
public:
// Zap data from the objects which is pertains only to this JVM. We
// want that data recreated in new JVMs when the shared file is used.
}
}
// Don't save compiler related special oops (shouldn't be any yet).
}
}
};
!obj->is_forwarded() &&
!obj->is_gc_marked()) {
return true;
}
return false;
}
// Closure: mark objects closure.
class MarkObjectsOopClosure : public OopClosure {
public:
};
class MarkObjectsSkippingKlassesOopClosure : public OopClosure {
public:
}
}
};
}
}
// Closure: mark common read-only objects, excluding symbols
class MarkCommonReadOnly : public ObjectClosure {
private:
public:
// Mark all constMethod objects.
if (obj->is_constMethod()) {
// Exception tables are needed by ci code during compilation.
}
// Mark objects referenced by klass objects which are read-only.
mark_object(k->secondary_supers());
// The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though
// it is never modified. Otherwise, they will be pre-marked; the
// GC marking phase will skip them; and by skipping them will fail
// to mark the methods objects referenced by the array.
if (inner_classes != NULL) {
}
}
}
}
};
// Closure: mark common symbols
class MarkCommonSymbols : public ObjectClosure {
private:
public:
// Mark symbols refered to by method objects.
mark_object(m->name());
mark_object(m->signature());
}
// Mark symbols referenced by klass objects which are read-only.
if (inner_classes != NULL) {
for (int i = 0;
i < length;
i += instanceKlass::inner_class_next_offset) {
if (index != 0) {
}
}
}
}
}
// Mark symbols referenced by other constantpool entries.
if (obj->is_constantPool()) {
}
}
};
// Closure: mark char arrays used by strings
class MarkStringValues : public ObjectClosure {
private:
public:
// Character arrays referenced by String objects are read-only.
}
}
};
#ifdef DEBUG
// Closure: Check for objects left in the heap which have not been moved.
class CheckRemainingObjects : public ObjectClosure {
private:
int count;
public:
count = 0;
}
!obj->is_forwarded()) {
++count;
if (Verbose) {
}
}
}
void status() {
}
};
#endif
// Closure: Mark remaining objects read-write, except Strings.
class MarkReadWriteObjects : public ObjectClosure {
private:
public:
// The METHODS() OBJARRAYS CANNOT BE MADE READ-ONLY, even though
// it is never modified. Otherwise, they will be pre-marked; the
// GC marking phase will skip them; and by skipping them will fail
// to mark the methods objects referenced by the array.
mark_object(k->java_mirror());
}
}
return;
}
// Mark constantPool tags and the constantPoolCache.
else if (obj->is_constantPool()) {
return;
}
// Mark all method objects.
}
}
};
// Closure: Mark String objects read-write.
class MarkStringObjects : public ObjectClosure {
private:
public:
// Mark String objects referenced by constant pool entries.
if (obj->is_constantPool()) {
return;
}
}
};
// Move objects matching specified type (ie. lock_bits) to the specified
// space.
class MoveMarkedObjects : public ObjectClosure {
private:
bool _read_only;
public:
}
return;
}
if (_read_only) {
warning("\nThe permanent generation read only space is not large "
"enough to \npreload requested classes. Use "
"-XX:SharedReadOnlySize= to increase \nthe initial "
"size of the read only space.\n");
} else {
warning("\nThe permanent generation read write space is not large "
"enough to \npreload requested classes. Use "
"-XX:SharedReadWriteSize= to increase \nthe initial "
"size of the read write space.\n");
}
exit(2);
}
}
if (_read_only) {
// Readonly objects: set hash value to self pointer and make gc_marked.
} else {
}
}
}
};
}
enum order_policy {
OP_favor_startup = 0,
OP_balanced = 1,
OP_favor_runtime = 2
};
}
class MarkAndMoveOrderedReadOnly : public ObjectClosure {
private:
public:
int i;
}
for(i = 0; i < interfaces->length(); i++) {
do_object(k);
}
// We don't move the name symbolOop here because it may invalidate
// method ordering, which is dependent on the address of the name
// symbolOop. It will get promoted later with the other symbols.
// Method name is rarely accessed during classloading anyway.
// mark_and_move_for_policy(OP_balanced, m->name(), _move_ro);
}
}
}
};
class MarkAndMoveOrderedReadWrite: public ObjectClosure {
private:
public:
int i;
}
for(i = 0; i < interfaces->length(); i++) {
do_object(k);
}
}
// Although Java mirrors are marked in MarkReadWriteObjects,
// apparently they were never moved into shared spaces since
// MoveMarkedObjects skips marked instance oops. This may
// be a bug in the original implementation or simply the vestige
// of an abandoned experiment. Nevertheless we leave a hint
// here in case this capability is ever correctly implemented.
//
// mark_and_move_for_policy(OP_favor_runtime, ik->java_mirror(), _move_rw);
}
}
};
// Adjust references in oops to refer to shared spaces.
class ResolveForwardingClosure: public OopClosure {
public:
*p = f;
}
}
}
};
}
// The methods array must be ordered by symbolOop address. (See
// classFileParser.cpp where methods in a class are originally
// sorted.) Since objects have just be reordered, this must be
// corrected.
true /* idempotent, slow */);
// Itable indices are calculated based on methods array order
// (see klassItable::compute_itable_index()). Must reinitialize.
// We assume that since checkconstraints is false, this method
// cannot throw an exception. An exception here would be
// problematic since this is the VMThread, not a JavaThread.
}
// Sort methods if the oop is an instanceKlass.
class SortMethodsClosure: public ObjectClosure {
private:
public:
// instanceKlass objects need some adjustment.
}
}
};
// Adjust references in oops to refer to shared spaces.
class PatchOopsClosure: public ObjectClosure {
private:
public:
// If the object is a Java object or class which might (in the
// future) contain a reference to a young gen object, add it to the
// list.
// Do nothing
}
// immutable objects.
} else {
// someone added an object we hadn't accounted for.
}
}
}
};
// Empty the young and old generations.
class ClearSpaceClosure : public SpaceClosure {
public:
}
};
// Closure for serializing initialization data out to a data area to be
// written to the shared file.
class WriteClosure : public SerializeOopClosure {
private:
char* end;
void out_of_space() {
warning("\nThe shared miscellaneous data space is not large "
"enough to \npreload requested classes. Use "
"-XX:SharedMiscDataSize= to increase \nthe initial "
"size of the miscellaneous data space.\n");
exit(2);
}
inline void check_space() {
out_of_space();
}
}
public:
}
check_space();
"Oop in shared space not pointing into shared space.");
++top;
}
void do_int(int* p) {
check_space();
++top;
}
check_space();
++top;
}
void do_ptr(void** p) {
check_space();
++top;
}
check_space();
++top;
}
out_of_space();
}
while (size > 0) {
++top;
}
}
bool reading() const { return false; }
};
class ResolveConstantPoolsClosure : public ObjectClosure {
private:
public:
__the_thread__ = t;
}
if (obj->is_constantPool()) {
}
}
};
// identify objects which might be able to be made read-only. At this
// point, the objects have been written, and we can trash them as
// needed.
static void print_contents() {
if (PrintSharedSpaces) {
// High level summary of the read-only space:
// High level summary of the read-write space:
// Reset counters
// Lower level summary of the read-only space:
// Reset counters
// Lower level summary of the read-write space:
}
}
// Patch C++ vtable pointer in klass oops.
// Klass objects contain references to c++ vtables in the JVM library.
// Fix them to point to our constructed vtables. However, don't iterate
// across the space while doing this, as that causes the vtables to be
// patched, undoing our useful work. Instead, iterate to make a list,
// then use the list to do the fixing.
//
// Our constructed vtables:
// Dump time:
// 1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs
// 2. generate_vtable_methods: create jump table, appended to above vtbl_list
// 3. PatchKlassVtables: for Klass list, patch the vtable entry to point to jump table
// rather than to current vtbl
// Table layout: NOTE FIXED SIZE
// 1. vtbl pointers
// 2. #Klass X #virtual methods per Klass
// 1 entry for each, in the order:
// Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry
// Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry
// ...
// Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry,
// ... Klass<vtbl_list_size>:method<num_virtuals> entry
// Sample entry: (Sparc):
// save(sp, -256, sp)
// ba,pt common_code
// mov XXX, %L0 %L0 gets: Klass index <<8 + method index (note: max method index 255)
//
// Restore time:
// 1. initialize_oops: reserve space for table
// 2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text
//
// Execution time:
// First virtual method call for any object of these Klass types:
// 1. object->klass->klass_part
// 2. vtable entry for that klass_part points to the jump table entries
// 3. branches to common_code with %O0/klass_part, %L0: Klass index <<8 + method index
// 4. common_code:
// Get address of new vtbl pointer for this Klass from updated table
// Update new vtbl pointer in the Klass: future virtual calls go direct
// Jump to method, using new vtbl pointer and method index
class PatchKlassVtables: public ObjectClosure {
private:
void* _vtbl_ptr;
public:
}
}
}
for (int i = 0; i < _klass_objects->length(); ++i) {
void* v = *(void**)k;
int n;
for (n = 0; n < vtbl_list_size; ++n) {
*(void**)k = NULL;
if (vtbl_list[n] == v) {
*(void**)k = (void**)_vtbl_ptr +
(n * CompactingPermGenGen::num_virtuals);
break;
}
}
}
}
};
// Populate the shared space.
class VM_PopulateDumpSharedSpace: public VM_Operation {
private:
public:
}
void doit() {
// The following guarantee is meant to ensure that no loader constraints
// exist yet, since the constraints table is not shared. This becomes
// shared classes at runtime, where constraints were previously created.
"loader constraints are not saved");
// Revisit and implement this if we prelink method handle call sites:
"invoke method table is not saved");
// At this point, many classes have been loaded.
// Update all the fingerprints in the shared methods.
// Remove all references outside the heap.
// Move the objects in three passes.
// The SharedOptimizeColdStart VM option governs the new layout
// algorithm for promoting classes into the shared archive.
// The general idea is to minimize cold start time by laying
// out the objects in the order they are accessed at startup time.
// By doing this we are trying to eliminate out-of-order accesses
// in the shared archive. This benefits cold startup time by making
// disk reads as sequential as possible during class loading and
// bootstrapping activities. There may also be a small secondary
// effect of better "packing" of more commonly used data on a smaller
// number of pages, although no direct benefit has been measured from
// this effect.
//
// At the class level of granularity, the promotion order is dictated
// by the classlist file whose generation is discussed elsewhere.
//
// At smaller granularity, optimal ordering was determined by an
// offline analysis of object access order in the shared archive.
// The dbx watchpoint facility, combined with SA post-processing,
// was used to observe common access patterns primarily during
// classloading. This information was used to craft the promotion
// order seen in the following closures.
//
// The observed access order is mostly governed by what happens
// in SystemDictionary::load_shared_class(). NOTE WELL - care
// should be taken when making changes to this method, because it
// may invalidate assumptions made about access order!
//
// (Ideally, there would be a better way to manage changes to
// the access order. Unfortunately a generic in-VM solution for
// dynamically observing access order and optimizing shared
// archive layout is pretty difficult. We go with the static
// analysis because the code is fairly mature at this point
// and we're betting that the access order won't change much.)
// Phase 1a: move commonly used read-only objects to the read-only space.
if (SharedOptimizeColdStart) {
for (int i = 0; i < _class_promote_order->length(); i++) {
}
}
// Phase 1b: move commonly used symbols to the read-only space.
// Phase 1c: move remaining symbols to the read-only space
// (e.g. String initializers).
// Phase 1d: move String character arrays to the read-only space.
// Phase 2: move all remaining symbols to the read-only space. The
// remaining symbols are assumed to be string initializers no longer
// referenced.
// Phase 3: move read-write objects to the read-write space, except
// Strings.
if (SharedOptimizeColdStart) {
for (int i = 0; i < _class_promote_order->length(); i++) {
}
}
// Phase 4: move String objects to the read-write space.
#ifdef DEBUG
// Check: scan for objects which were not moved.
#endif
// Resolve forwarding in objects and saved C++ structures
// Set up the share data and shared code segments.
// Reserve space for the list of klassOops whose vtables are used
// for patching others as needed.
md_top += vtbl_list_size * sizeof(void*);
// Reserve space for a new dummy vtable for klass objects in the
// heap. Generate self-patching vtable entries.
&vtable,
// Fix (forward) all of the references in these shared objects (which
// are required to point ONLY to objects in the shared spaces).
// Also, create a list of all objects which might later contain a
// reference to a younger generation object.
// Previously method sorting was done concurrently with forwarding
// pointer resolution in the shared spaces. This imposed an ordering
// before their holder classes. (Because constant pool pointers in
// methodKlasses are required to be resolved before their holder class
// is visited for sorting, otherwise methods are sorted by incorrect,
// pre-forwarding addresses.)
//
// Now, we reorder methods as a separate step after ALL forwarding
// pointer resolution, so that methods can be promoted in any order
// with respect to their holder classes.
// Reorder the system dictionary. (Moving the symbols opps affects
// how the hash table indices are calculated.)
// Empty the non-shared heap (because most of the objects were
// copied out, and the remainder cannot be considered valid oops).
}
// Copy the String table, the symbol table, and the system
// dictionary to the shared space in usable form. Copy the hastable
// buckets first [read-write], then copy the linked lists of entries
// [read-only].
StringTable::reverse();
ClassLoader::verify();
ClassLoader::verify();
ClassLoader::verify();
ClassLoader::verify();
// Print debug data.
if (PrintSharedSpaces) {
const char* fmt = "%s space: " PTR_FORMAT " out of " PTR_FORMAT " bytes allocated at " PTR_FORMAT ".";
}
// Write the oop data to the output array.
// Update the vtable pointers in all of the Klass objects in the
// heap. They should point to newly generated vtable.
// Create and write the archive file that maps the shared spaces.
// Pass 1 - update file offsets in header.
mapinfo->write_header();
false, false);
true, true);
// Pass 2 - write data.
mapinfo->write_header();
false, false);
true, true);
// Summarize heap.
}
}; // class VM_PopulateDumpSharedSpace
// Populate the shared spaces and dump to a file.
// Calculate hash values for all of the (interned) strings to avoid
// writes to shared pages in the future.
return JNI_OK;
}
class LinkClassesClosure : public ObjectClosure {
private:
public:
if (k->oop_is_instance()) {
// Link the class to cause the bytecodes to be rewritten and the
// cpcache to be created.
}
// Create String objects from string initializer symbols.
}
}
}
};
// Support for a simple checksum of the contents of the class list
// file to prevent trivial tampering. The algorithm matches that in
// the MakeClassList program used by the J2SE build process.
static jlong
{
while (p < e) {
char c = *p++;
if (c <= ' ') {
/* Skip spaces and control characters */
continue;
}
h = 31 * h + c;
}
return h;
}
// Preload classes from a list, populate the shared spaces and dump to a
// file.
// Preload classes to be shared.
// Should use some hpi:: method rather than fopen() here. aB.
// Walk up two directories from the location of the VM and
// optionally tack on "lib" (depending on platform)
char class_list_path[JVM_MAXPATHLEN];
for (int i = 0; i < 3; i++) {
}
if (class_list_path_len >= 3) {
}
}
char class_name[256];
int class_count = 0;
gch->_preloading_shared_classes = true;
// Preload (and intern) strings which will be used later.
// sun.io.Converters
static const char obj_array_sig[] = "[[Ljava/lang/Object;";
// java.util.HashMap
static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
THREAD);
if (*class_name == '#') {
}
continue;
}
// Remove trailing newline
// Got a class name - load it.
THREAD);
THREAD);
if (PrintSharedSpaces) {
}
// Should be class load order as per -XX:+TraceClassLoadingPreorder
// Link the class to cause the bytecodes to be rewritten and the
// cpcache to be created. The linking is done as soon as classes
// are loaded in order that the related data structures (klass,
// cpCache, Sting constants) are located together.
}
// Create String objects from string initializer symbols.
class_count++;
} else {
if (PrintSharedSpaces) {
}
}
file_jsum = 0; // Checksum must be on last line of file
}
if (computed_jsum != file_jsum) {
exit(1);
}
if (PrintSharedSpaces) {
}
// Rewrite and unlink classes.
// Make heap parsable
ensure_parsability(false); // arg is actually don't care
// Link any classes which got missed. (It's not quite clear why
// they got missed.) This iteration would be unsafe if we weren't
// single-threaded at this point; however we can't do it on the VM
// thread because it requires object allocation.
// Create and dump the shared spaces.
fatal("Dumping shared spaces failed.");
}
} else {
char errmsg[JVM_MAXPATHLEN];
exit(1);
}
// Since various initialization steps have been undone by this process,
// it is not reasonable to continue running a java process.
exit(0);
}