Skip to content

Commit

Permalink
fixed crash issues after upgrading to JDK 13
Browse files Browse the repository at this point in the history
and updated README
  • Loading branch information
chuansheng.lcs committed Sep 17, 2019
1 parent a026fd0 commit 43c0914
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 40 deletions.
31 changes: 2 additions & 29 deletions README
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
Based on [the master OpenJDK Mercurial repository](http://hg.openjdk.java.net/jdk/jdk/)
Demonstration of bridging the Java heap to C-Heap.

Price of automatic memory management
===================

Java's automatic memory management is mostly GREAT, which significantly relieves Java
developers from the headache of object lifecycle, dangling pointers, etc.
But "everything you want in life has a price connected to it", the label
tagged on Java includes:

* Application pauses for GC scan (even in some 'pauseless' implementation)
* CPU time consumed by memory barriers, marking/sweeping/copying
* Extra memory to hold GC meta data


Retreat to manual style
===================
Most of Java's memory prices are about time, and for some special scenarios,
it is totally acceptable to trade space for time!
such as:

* Short-lived and non-memory-intensive batch jobs
* Move off-heap memory to in-heap to mitigate serialization cost

So how about stop automatic memory management, and delegate some even all the work
to native library (glibc, jemalloc, etc.) ?

The idea was inspired by OpenJDK's [Epsilon GC proposal](http://openjdk.java.net/jeps/318), which does not do GC either.
This project steps forward by trying to leverage native memory management
mechanisms to allocate and deallocate memory.
Based on OpenJDK jdk-13-ga
8 changes: 8 additions & 0 deletions src/hotspot/share/gc/bridged/bridgedCHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

// ------------------------------ allocators ------------------------

// Abstract interface to delegate memory requests
// we have several back-ends
class CHeapAllocator : public CHeapObj<mtGC> {
public:
virtual void* malloc(size_t size) = 0;
virtual void free(void* buf) = 0;
};

// Prototype of libc's malloc/free
typedef void* (*malloc_prototype)(size_t size);
typedef void (*free_prototype)(void* ptr);
Expand Down
19 changes: 10 additions & 9 deletions src/hotspot/share/gc/bridged/bridgedCHeap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
#include "gc/shared/gcArguments.hpp"
#include "gc/bridged/bridgedCHeapBarrierSet.hpp"

// Abstract interface to delegate memory requests
// we have several back-ends
class CHeapAllocator : public CHeapObj<mtGC> {
public:
virtual void* malloc(size_t size) = 0;
virtual void free(void* buf) = 0;
};
class CHeapAllocator;

//
// The Bridged CHeap
Expand Down Expand Up @@ -56,8 +50,8 @@ class BridgedCHeap : public CollectedHeap {
virtual bool can_elide_tlab_store_barriers() const { return false; }
virtual bool can_elide_initializing_store_barrier(oop new_obj) { return false; }
virtual bool card_mark_must_follow_store() const { return false; }
virtual void collect(GCCause::Cause cause) { DEBUG_ONLY(Unimplemented()); }
virtual void do_full_collection(bool clear_all_soft_refs) { DEBUG_ONLY(Unimplemented()); }
virtual void collect(GCCause::Cause cause) { Unimplemented(); }
virtual void do_full_collection(bool clear_all_soft_refs) { Unimplemented(); }
virtual GrowableArray<GCMemoryManager*> memory_managers() {
return GrowableArray<GCMemoryManager*>();
}
Expand Down Expand Up @@ -89,6 +83,7 @@ class BridgedCHeap : public CollectedHeap {
virtual void unregister_nmethod(nmethod* nm) { }
virtual void flush_nmethod(nmethod* nm) { }
virtual void verify_nmethod(nmethod* nm) { }
virtual bool is_oop(oop object) const { return true; }
};

// to work with JDK10's framework
Expand All @@ -97,6 +92,12 @@ class BridgedCHeapArguments : public GCArguments {
virtual size_t conservative_max_heap_alignment() {
return UseLargePages ? os::large_page_size() : os::vm_page_size();
}
virtual void initialize_alignments() {
size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
size_t align = MAX2((size_t)os::vm_allocation_granularity(), page_size);
SpaceAlignment = align;
HeapAlignment = align;
}
virtual CollectedHeap* create_heap() {
return new BridgedCHeap();
}
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/gc/shared/gcConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#if INCLUDE_ZGC
#include "gc/z/zArguments.hpp"
#endif
#include "gc/bridged/bridgedCHeap.hpp"

struct SupportedGC {
bool& _flag;
Expand All @@ -67,6 +68,7 @@ struct SupportedGC {
SERIALGC_ONLY(static SerialArguments serialArguments;)
SHENANDOAHGC_ONLY(static ShenandoahArguments shenandoahArguments;)
ZGC_ONLY(static ZArguments zArguments;)
static BridgedCHeapArguments bridgedCHeapArguments;

// Table of supported GCs, for translating between command
// line flag, CollectedHeap::Name and GCArguments instance.
Expand All @@ -79,6 +81,7 @@ static const SupportedGC SupportedGCs[] = {
SERIALGC_ONLY_ARG(SupportedGC(UseSerialGC, CollectedHeap::Serial, serialArguments, "serial gc"))
SHENANDOAHGC_ONLY_ARG(SupportedGC(UseShenandoahGC, CollectedHeap::Shenandoah, shenandoahArguments, "shenandoah gc"))
ZGC_ONLY_ARG(SupportedGC(UseZGC, CollectedHeap::Z, zArguments, "z gc"))
SupportedGC(UseBridgedCHeap, CollectedHeap::BridgedCHeap, bridgedCHeapArguments, "bridged cheap"),
};

#define FOR_EACH_SUPPORTED_GC(var) \
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/interpreter/interpreterRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code byte
assert(Universe::heap()->is_in_reserved_or_null(receiver()),
"sanity check");
assert(receiver.is_null() ||
!Universe::heap()->is_in_reserved(receiver->klass()),
!Universe::heap()->is_in_reserved(receiver->klass()) || UseBridgedCHeap,
"sanity check");
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/machnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const class TypePtr *MachNode::adr_type() const {
return TypePtr::BOTTOM;
}
// %%% make offset be intptr_t
assert(!Universe::heap()->is_in_reserved(cast_to_oop(offset)), "must be a raw ptr");
assert(!Universe::heap()->is_in_reserved(cast_to_oop(offset)) || UseBridgedCHeap, "must be a raw ptr");
return TypeRawPtr::BOTTOM;
}

Expand Down

0 comments on commit 43c0914

Please sign in to comment.