Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store AOT code in cached code region of AOT cache #39

Closed
4 changes: 3 additions & 1 deletion src/hotspot/share/cds/archiveBuilder.cpp
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "classfile/vmClasses.hpp"
#include "code/SCCache.hpp"
#include "interpreter/abstractInterpreter.hpp"
#include "jvm.h"
#include "logging/log.hpp"
@@ -312,7 +313,8 @@ void ArchiveBuilder::sort_klasses() {
}

address ArchiveBuilder::reserve_buffer() {
size_t buffer_size = LP64_ONLY(CompressedClassSpaceSize) NOT_LP64(256 * M);
// SCCache::max_aot_code_size() accounts for cached code region.
size_t buffer_size = LP64_ONLY(CompressedClassSpaceSize) NOT_LP64(256 * M) + SCCache::max_aot_code_size();
ReservedSpace rs = MemoryReserver::reserve(buffer_size,
MetaspaceShared::core_region_alignment(),
os::vm_page_size());
2 changes: 2 additions & 0 deletions src/hotspot/share/cds/archiveUtils.hpp
Original file line number Diff line number Diff line change
@@ -187,6 +187,8 @@ class DumpRegion {
return !is_packed() && _base != nullptr;
}

bool is_empty() const { return _base == _top; }

void print(size_t total_bytes) const;
void print_out_of_space_msg(const char* failing_region, size_t needed_bytes);

21 changes: 13 additions & 8 deletions src/hotspot/share/cds/cdsAccess.cpp
Original file line number Diff line number Diff line change
@@ -152,6 +152,8 @@ void CDSAccess::test_heap_access_api() {
test_cds_heap_access_api_for_object(Universe::null_ptr_exception_instance());
}

#endif // INCLUDE_CDS_JAVA_HEAP

// new workflow only
void* CDSAccess::allocate_from_code_cache(size_t size) {
assert(CDSConfig::is_dumping_final_static_archive(), "must be");
@@ -166,13 +168,9 @@ void CDSAccess::set_cached_code_size(size_t sz) {
_cached_code_size = sz;
}

void CDSAccess::set_pointer(address* ptr, address value) {
ArchiveBuilder* builder = ArchiveBuilder::current();
if (value != nullptr && !builder->is_in_buffer_space(value)) {
value = builder->get_buffered_addr(value);
}
*ptr = value;
ArchivePtrMarker::mark_pointer(ptr);
bool CDSAccess::is_cached_code_region_empty() {
assert(CDSConfig::is_dumping_final_static_archive(), "must be");
return ArchiveBuilder::current()->cc_region()->is_empty();
}

bool CDSAccess::map_cached_code(ReservedSpace rs) {
@@ -181,4 +179,11 @@ bool CDSAccess::map_cached_code(ReservedSpace rs) {
return static_mapinfo->map_cached_code_region(rs);
}

#endif // INCLUDE_CDS_JAVA_HEAP
void CDSAccess::set_pointer(address* ptr, address value) {
ArchiveBuilder* builder = ArchiveBuilder::current();
if (value != nullptr && !builder->is_in_buffer_space(value)) {
value = builder->get_buffered_addr(value);
}
*ptr = value;
ArchivePtrMarker::mark_pointer(ptr);
}
7 changes: 4 additions & 3 deletions src/hotspot/share/cds/cdsAccess.hpp
Original file line number Diff line number Diff line change
@@ -58,10 +58,11 @@ class CDSAccess : AllStatic {

static void* allocate_from_code_cache(size_t size) NOT_CDS_RETURN_(nullptr);

static size_t get_cached_code_size() NOT_CDS_JAVA_HEAP_RETURN_(0);
static void set_cached_code_size(size_t sz) NOT_CDS_JAVA_HEAP_RETURN;
static size_t get_cached_code_size() NOT_CDS_RETURN_(0);
static void set_cached_code_size(size_t sz) NOT_CDS_RETURN;

static bool map_cached_code(ReservedSpace rs) NOT_CDS_JAVA_HEAP_RETURN_(false);
static bool is_cached_code_region_empty() NOT_CDS_RETURN_(true);
static bool map_cached_code(ReservedSpace rs) NOT_CDS_RETURN_(false);

template <typename T>
static void set_pointer(T** ptr, T* value) {
4 changes: 2 additions & 2 deletions src/hotspot/share/cds/heapShared.hpp
Original file line number Diff line number Diff line change
@@ -463,8 +463,8 @@ class CachedCodeDirectoryInternal {
int _permanent_oop_count;
int* _permanent_oop_offsets; // offset of each permanent object from the bottom of the archived heap
public:
void dumptime_init_internal();
void runtime_init_internal();
void dumptime_init_internal() NOT_CDS_JAVA_HEAP_RETURN;
void runtime_init_internal() NOT_CDS_JAVA_HEAP_RETURN;
};

#if INCLUDE_CDS_JAVA_HEAP
9 changes: 4 additions & 5 deletions src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
@@ -1128,11 +1128,11 @@ void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS
{
builder.start_cc_region();
Precompiler::compile_cached_code(&builder, CHECK);
// Write the contents to cached code region and close SCCache before packing the region
SCCache::close();
builder.end_cc_region();
}
CDSConfig::disable_dumping_cached_code();

SCCache::close(); // Write final data and close archive
}
status = write_static_archive(&builder, mapinfo, heap_info);
} else {
@@ -1422,8 +1422,7 @@ void MetaspaceShared::initialize_runtime_shared_and_meta_spaces() {
}
}

// This is called very early at VM start up to get the size of the cached_code region, which
// is used in CodeCache::initialize_heaps()
// This is called very early at VM start up to get the size of the cached_code region
void MetaspaceShared::open_static_archive() {
if (!UseSharedSpaces) {
return;
@@ -1963,7 +1962,7 @@ void MetaspaceShared::initialize_shared_spaces() {
static_mapinfo->patch_heap_embedded_pointers();
ArchiveHeapLoader::finish_initialization();
Universe::load_archived_object_instances();
SCCache::new_workflow_load_cache();
SCCache::initialize();

// Close the mapinfo file
static_mapinfo->close();
Loading