/*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/loaderConstraints.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "gc_implementation/shared/spaceDecorator.hpp"
#include "memory/classify.hpp"
#include "memory/filemap.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "oops/methodDataOop.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/signature.hpp"
#include "runtime/vmThread.hpp"
#include "runtime/vm_operations.hpp"
// Closure to set up the fingerprint field for all methods.
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 we have to call java_lang_String::to_hash() to match the
// algorithm in java.lang.String.toHash().
private:
int hash_offset;
public:
THREAD = t;
}
if (p != NULL) {
}
}
}
};
// Remove data from objects which should not appear in the shared file
// (as it pertains only to the current JVM).
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;
}
private:
char* _start;
char* _end;
char* _top;
int _count;
}
}
// Encode a reference to the copy as a negative distance from _start
// When a symbol is being copied to a shared space
// during CDS archive creation, the original symbol is marked
// as relocated by putting a negative value to its _refcount field,
// This value is also used to find where exactly the shared copy is
// (see MoveSymbols::get_shared_copy), so that the other references
// to this symbol could be changed to point to the shared copy.
// Mark the symbol in the shared archive as immortal so it is read only
// and not refcounted.
_count++;
} else {
}
return new_sym;
}
public:
// The symbol has not been relocated yet; copy it to _top address
}
// Make the reference point to the shared copy of the symbol
store_symbol(p, new_sym);
}
}
};
// Closure: mark objects closure.
public:
};
public:
}
}
};
}
}
// Closure: mark common read-only objects
private:
public:
// Mark all constMethod objects.
if (obj->is_constMethod()) {
}
// 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: find symbol references in Java Heap objects
private:
public:
// Traverse symbols referenced by method objects.
}
// Traverse symbols referenced by klass objects which are read-only.
if (index != 0) {
}
}
}
}
// Traverse symbols referenced by other constantpool entries.
else if (obj->is_constantPool()) {
}
}
};
// Closure: mark char arrays used by strings
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.
private:
int count;
public:
count = 0;
}
!obj->is_forwarded()) {
++count;
if (Verbose) {
}
}
}
void status() {
}
};
#endif
// Closure: Mark remaining objects read-write, except Strings.
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.
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.
private:
bool _read_only;
public:
}
return;
}
}
}
if (_read_only) {
// Readonly objects: set hash value to self pointer and make gc_marked.
} else {
}
}
}
};
}
enum order_policy {
OP_favor_startup = 0,
};
}
private:
public:
int i;
}
for(i = 0; i < interfaces->length(); i++) {
do_object(k);
}
}
}
}
};
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.
public:
*p = f;
}
}
}
};
// The methods array must be reordered by Symbol* address.
// (See classFileParser.cpp where methods in a class are originally
// sorted). The addresses of symbols have been changed as a result
// of moving to the shared space.
public:
true /* idempotent, slow */);
}
}
};
// Vtable and Itable indices are calculated based on methods array
// order (see klassItable::compute_itable_index()). Must reinitialize
// after ALL methods of ALL classes have been reordered.
// 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.
private:
public:
// Initialize super vtable first, check if already initialized to avoid
// quadradic behavior. The vtable is cleared in remove_unshareable_info.
if (k->blueprint()->oop_is_instanceKlass()) {
}
}
}
#ifdef ASSERT
#endif // ASSERT
// The vtable for array klasses are that of its super class,
// ie. java.lang.Object.
}
}
};
// Adjust references in oops to refer to shared spaces.
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.
public:
}
};
// Closure for serializing initialization data out to a data area to be
// written to the shared file.
private:
char* end;
inline void check_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;
}
}
while (size > 0) {
++top;
}
}
bool reading() const { return false; }
};
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
private:
public:
}
}
}
int n = _klass_objects->length();
for (int i = 0; i < n; i++) {
*(void**)k = CompactingPermGenGen::find_matching_vtbl_ptr(
vtbl_list, new_vtable_start, k);
}
}
};
// Walk through all symbols and patch their vtable pointers.
// Note that symbols have vtable pointers only in non-product builds
// (see allocation.hpp).
#ifndef PRODUCT
private:
void* _new_vtbl_ptr;
public:
Symbol s;
vtbl_list, new_vtable_start, &s);
}
*(void**)sym = _new_vtbl_ptr;
}
};
#endif
// Populate the shared space.
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.)
// 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,
// Reserve space for the total size and the number of stored symbols.
// Phase 1a: remove symbols with _refcount == 0
SymbolTable::unlink();
// Phase 1b: move commonly used symbols referenced by oop fields.
move_symbols.get_top());
// Phase 1c: move known names and signatures.
move_symbols.get_top());
// Phase 1d: move the remaining symbols by scanning the whole SymbolTable.
move_symbols.get_top());
// Record the total length of all symbols at the beginning of the block.
// Advance the pointer to the end of symbol store.
// Phase 2: move commonly used read-only objects to the read-only space.
if (SharedOptimizeColdStart) {
for (int i = 0; i < _class_promote_order->length(); i++) {
}
}
// Phase 3: move String character arrays to the read-only space.
// Phase 4: move read-write objects to the read-write space, except
// Strings.
if (SharedOptimizeColdStart) {
for (int i = 0; i < _class_promote_order->length(); i++) {
}
}
// Phase 5: 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
// 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.
#ifndef PRODUCT
// Update the vtable pointers in all symbols,
// but only in non-product builds where symbols DO have virtual methods.
#endif
// 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;
}
void* new_vtable_start,
void* obj) {
for (int i = 0; i < vtbl_list_size; i++) {
if (vtbl_list[i] == old_vtbl_ptr) {
return (void**)new_vtable_start + i * num_virtuals;
}
}
return NULL;
}
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 os:: method rather than fopen() here. aB.
// Walk up two directories from the location of the VM and
// optionally tack on "lib" (depending on platform)
for (int i = 0; i < 3; i++) {
}
if (class_list_path_len >= 3) {
}
}
int class_count = 0;
gch->_preloading_shared_classes = true;
// Preload (and intern) strings which will be used later.
// sun.io.Converters
// java.util.HashMap
if (*class_name == '#') {
}
continue;
}
// Remove trailing newline
// Got a class name - load it.
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.
ensure_parsability(false); // arg is actually don't care
// Create and dump the shared spaces.
fatal("Dumping shared spaces failed.");
}
} else {
exit(1);
}
// Since various initialization steps have been undone by this process,
// it is not reasonable to continue running a java process.
exit(0);
}