diff --git a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp
index c7067b2e5abf..cab6abc4e6f5 100644
--- a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp
+++ b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp
@@ -45,7 +45,7 @@ void ShenandoahGenerationalHeuristics::choose_collection_set(ShenandoahCollectio
// Check all pinned regions have updated status before choosing the collection set.
- heap->assert_pinned_region_status();
+ heap->assert_pinned_region_status(_generation);
// Step 1. Build up the region candidates we care about, rejecting losers and accepting winners right away.
@@ -127,7 +127,7 @@ void ShenandoahGenerationalHeuristics::choose_collection_set(ShenandoahCollectio
// Reclaim humongous regions here, and count them as the immediate garbage
#ifdef ASSERT
bool reg_live = region->has_live();
- bool bm_live = heap->active_generation()->complete_marking_context()->is_marked(cast_to_oop(region->bottom()));
+ bool bm_live = _generation->complete_marking_context()->is_marked(cast_to_oop(region->bottom()));
assert(reg_live == bm_live,
"Humongous liveness and marks should agree. Region live: %s; Bitmap live: %s; Region Live Words: %zu",
BOOL_TO_STR(reg_live), BOOL_TO_STR(bm_live), region->get_live_data_words());
diff --git a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.cpp b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.cpp
index 0aa117385cff..eb740cfac618 100644
--- a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.cpp
+++ b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahHeuristics.cpp
@@ -73,10 +73,11 @@ ShenandoahHeuristics::~ShenandoahHeuristics() {
}
void ShenandoahHeuristics::choose_collection_set(ShenandoahCollectionSet* collection_set) {
- assert(collection_set->is_empty(), "Must be empty");
-
ShenandoahHeap* heap = ShenandoahHeap::heap();
+ assert(collection_set->is_empty(), "Must be empty");
+ assert(!heap->mode()->is_generational(), "Wrong heuristic for heap mode");
+
// Check all pinned regions have updated status before choosing the collection set.
heap->assert_pinned_region_status();
@@ -120,7 +121,7 @@ void ShenandoahHeuristics::choose_collection_set(ShenandoahCollectionSet* collec
// Reclaim humongous regions here, and count them as the immediate garbage
#ifdef ASSERT
bool reg_live = region->has_live();
- bool bm_live = heap->gc_generation()->complete_marking_context()->is_marked(cast_to_oop(region->bottom()));
+ bool bm_live = heap->global_generation()->complete_marking_context()->is_marked(cast_to_oop(region->bottom()));
assert(reg_live == bm_live,
"Humongous liveness and marks should agree. Region live: %s; Bitmap live: %s; Region Live Words: %zu",
BOOL_TO_STR(reg_live), BOOL_TO_STR(bm_live), region->get_live_data_words());
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp
index 34b4f235a00e..10290963f20e 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp
@@ -382,6 +382,16 @@ void ShenandoahAsserts::assert_marked_strong(void *interior_loc, oop obj, const
}
}
+void ShenandoahAsserts::assert_mark_complete(HeapWord* obj, const char* file, int line) {
+ const ShenandoahHeap* heap = ShenandoahHeap::heap();
+ const ShenandoahHeapRegion* region = heap->heap_region_containing(obj);
+ const ShenandoahGeneration* generation = heap->generation_for(region->affiliation());
+ if (!generation->is_mark_complete()) {
+ ShenandoahMessageBuffer msg("Marking should be complete for object " PTR_FORMAT " in the %s generation", p2i(obj), generation->name());
+ report_vm_error(file, line, msg.buffer());
+ }
+}
+
void ShenandoahAsserts::assert_bitmap_clear_above_top(ShenandoahHeapRegion* region) {
ShenandoahMarkingContext* const ctx = ShenandoahHeap::heap()->marking_context();
const HeapWord* top_bitmap = ctx->top_bitmap(region);
@@ -507,20 +517,3 @@ void ShenandoahAsserts::assert_control_or_vm_thread_at_safepoint(bool at_safepoi
}
report_vm_error(file, line, msg.buffer());
}
-
-void ShenandoahAsserts::assert_generations_reconciled(const char* file, int line) {
- if (!ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
- // Only shenandoah safepoint operations participate in the active/gc generation scheme
- return;
- }
-
- ShenandoahHeap* heap = ShenandoahHeap::heap();
- ShenandoahGeneration* ggen = heap->gc_generation();
- ShenandoahGeneration* agen = heap->active_generation();
- if (agen == ggen) {
- return;
- }
-
- ShenandoahMessageBuffer msg("Active(%s) & GC(%s) Generations aren't reconciled", agen->name(), ggen->name());
- report_vm_error(file, line, msg.buffer());
-}
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp
index 2d34c797566c..e9ec7f36d3a0 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahAsserts.hpp
@@ -66,6 +66,9 @@ class ShenandoahAsserts {
static void assert_marked(void* interior_loc, oop obj, const char* file, int line);
static void assert_marked_weak(void* interior_loc, oop obj, const char* file, int line);
static void assert_marked_strong(void* interior_loc, oop obj, const char* file, int line);
+
+ // Assert that marking is complete for the generation where this obj resides
+ static void assert_mark_complete(HeapWord* obj, const char* file, int line);
static void assert_bitmap_clear_above_top(ShenandoahHeapRegion* region);
static void assert_in_cset(void* interior_loc, oop obj, const char* file, int line);
static void assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line);
@@ -78,7 +81,6 @@ class ShenandoahAsserts {
static void assert_heaplocked_or_safepoint(const char* file, int line);
static void assert_control_or_vm_thread_at_safepoint(bool at_safepoint, const char* file, int line);
static void assert_generational(const char* file, int line);
- static void assert_generations_reconciled(const char* file, int line);
#ifdef ASSERT
#define shenandoah_assert_in_heap_bounds(interior_loc, obj) \
@@ -129,6 +131,8 @@ class ShenandoahAsserts {
if (!(exception)) ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__)
#define shenandoah_assert_marked_strong(interior_loc, obj) \
ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__)
+#define shenandoah_assert_mark_complete(obj) \
+ ShenandoahAsserts::assert_mark_complete(obj, __FILE__, __LINE__)
#define shenandoah_assert_clear_above_top(region) \
ShenandoahAsserts::assert_bitmap_clear_above_top(region)
@@ -184,10 +188,6 @@ class ShenandoahAsserts {
#define shenandoah_assert_generational() \
ShenandoahAsserts::assert_generational(__FILE__, __LINE__)
-// Some limited sanity checking of the _gc_generation and _active_generation fields of ShenandoahHeap
-#define shenandoah_assert_generations_reconciled() \
- ShenandoahAsserts::assert_generations_reconciled(__FILE__, __LINE__)
-
#else
#define shenandoah_assert_in_heap_bounds(interior_loc, obj)
#define shenandoah_assert_in_heap_bounds_or_null(interior_loc, obj)
@@ -217,6 +217,8 @@ class ShenandoahAsserts {
#define shenandoah_assert_marked_strong_except(interior_loc, obj, exception)
#define shenandoah_assert_marked_strong(interior_loc, obj)
+#define shenandoah_assert_mark_complete(obj)
+
#define shenandoah_assert_clear_above_top(region)
#define shenandoah_assert_in_cset_if(interior_loc, obj, condition)
#define shenandoah_assert_in_cset_except(interior_loc, obj, exception)
@@ -242,7 +244,6 @@ class ShenandoahAsserts {
#define shenandoah_assert_control_or_vm_thread()
#define shenandoah_assert_control_or_vm_thread_at_safepoint()
#define shenandoah_assert_generational()
-#define shenandoah_assert_generations_reconciled()
#endif
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp b/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
index 3885a3f4c1d6..79615be7068f 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
@@ -91,8 +91,8 @@ class ShenandoahBreakpointMarkScope : public StackObj {
};
ShenandoahConcurrentGC::ShenandoahConcurrentGC(ShenandoahGeneration* generation, bool do_old_gc_bootstrap) :
+ ShenandoahGC(generation),
_mark(generation),
- _generation(generation),
_degen_point(ShenandoahDegenPoint::_degenerated_unset),
_abbreviated(false),
_do_old_gc_bootstrap(do_old_gc_bootstrap) {
@@ -574,7 +574,7 @@ void ShenandoahConcurrentGC::entry_promote_in_place() const {
ShenandoahGCWorkerPhase worker_phase(ShenandoahPhaseTimings::promote_in_place);
EventMark em("%s", "Promote in place");
- ShenandoahGenerationalHeap::heap()->promote_regions_in_place(true);
+ ShenandoahGenerationalHeap::heap()->promote_regions_in_place(_generation, true);
}
void ShenandoahConcurrentGC::entry_update_thread_roots() {
@@ -706,7 +706,7 @@ void ShenandoahConcurrentGC::op_init_mark() {
if (ShenandoahVerify) {
ShenandoahTimingsTracker v(ShenandoahPhaseTimings::init_mark_verify);
- heap->verifier()->verify_before_concmark();
+ heap->verifier()->verify_before_concmark(_generation);
}
if (VerifyBeforeGC) {
@@ -766,7 +766,7 @@ void ShenandoahConcurrentGC::op_final_mark() {
assert(!heap->has_forwarded_objects(), "No forwarded objects on this path");
if (ShenandoahVerify) {
- heap->verifier()->verify_roots_no_forwarded();
+ heap->verifier()->verify_roots_no_forwarded(_generation);
}
if (!heap->cancelled_gc()) {
@@ -794,7 +794,7 @@ void ShenandoahConcurrentGC::op_final_mark() {
if (ShenandoahVerify) {
ShenandoahTimingsTracker v(ShenandoahPhaseTimings::final_mark_verify);
- heap->verifier()->verify_before_evacuation();
+ heap->verifier()->verify_before_evacuation(_generation);
}
heap->set_evacuation_in_progress(true);
@@ -812,9 +812,9 @@ void ShenandoahConcurrentGC::op_final_mark() {
if (ShenandoahVerify) {
ShenandoahTimingsTracker v(ShenandoahPhaseTimings::final_mark_verify);
if (has_in_place_promotions(heap)) {
- heap->verifier()->verify_after_concmark_with_promotions();
+ heap->verifier()->verify_after_concmark_with_promotions(_generation);
} else {
- heap->verifier()->verify_after_concmark();
+ heap->verifier()->verify_after_concmark(_generation);
}
}
}
@@ -883,18 +883,20 @@ void ShenandoahConcurrentGC::op_weak_refs() {
class ShenandoahEvacUpdateCleanupOopStorageRootsClosure : public BasicOopIterateClosure {
private:
ShenandoahHeap* const _heap;
+ ShenandoahGeneration* const _generation;
ShenandoahMarkingContext* const _mark_context;
bool _evac_in_progress;
Thread* const _thread;
public:
- ShenandoahEvacUpdateCleanupOopStorageRootsClosure();
+ explicit ShenandoahEvacUpdateCleanupOopStorageRootsClosure(ShenandoahGeneration* generation);
void do_oop(oop* p);
void do_oop(narrowOop* p);
};
-ShenandoahEvacUpdateCleanupOopStorageRootsClosure::ShenandoahEvacUpdateCleanupOopStorageRootsClosure() :
+ShenandoahEvacUpdateCleanupOopStorageRootsClosure::ShenandoahEvacUpdateCleanupOopStorageRootsClosure(ShenandoahGeneration* generation) :
_heap(ShenandoahHeap::heap()),
+ _generation(generation),
_mark_context(ShenandoahHeap::heap()->marking_context()),
_evac_in_progress(ShenandoahHeap::heap()->is_evacuation_in_progress()),
_thread(Thread::current()) {
@@ -904,8 +906,7 @@ void ShenandoahEvacUpdateCleanupOopStorageRootsClosure::do_oop(oop* p) {
const oop obj = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(obj)) {
if (!_mark_context->is_marked(obj)) {
- shenandoah_assert_generations_reconciled();
- if (_heap->is_in_active_generation(obj)) {
+ if (_generation->contains(obj)) {
// Note: The obj is dead here. Do not touch it, just clear.
ShenandoahHeap::atomic_clear_oop(p, obj);
}
@@ -948,14 +949,16 @@ class ShenandoahConcurrentWeakRootsEvacUpdateTask : public WorkerTask {
ShenandoahClassLoaderDataRoots
_cld_roots;
ShenandoahConcurrentNMethodIterator _nmethod_itr;
+ ShenandoahGeneration* _generation;
ShenandoahPhaseTimings::Phase _phase;
public:
- ShenandoahConcurrentWeakRootsEvacUpdateTask(ShenandoahPhaseTimings::Phase phase) :
+ ShenandoahConcurrentWeakRootsEvacUpdateTask(ShenandoahGeneration* generation, ShenandoahPhaseTimings::Phase phase) :
WorkerTask("Shenandoah Evacuate/Update Concurrent Weak Roots"),
_vm_roots(phase),
_cld_roots(phase, ShenandoahHeap::heap()->workers()->active_workers(), false /*heap iteration*/),
_nmethod_itr(ShenandoahCodeRoots::table()),
+ _generation(generation),
_phase(phase) {}
~ShenandoahConcurrentWeakRootsEvacUpdateTask() {
@@ -963,14 +966,14 @@ class ShenandoahConcurrentWeakRootsEvacUpdateTask : public WorkerTask {
_vm_roots.report_num_dead();
}
- void work(uint worker_id) {
+ void work(uint worker_id) override {
ShenandoahConcurrentWorkerSession worker_session(worker_id);
ShenandoahSuspendibleThreadSetJoiner sts_join;
{
ShenandoahEvacOOMScope oom;
// jni_roots and weak_roots are OopStorage backed roots, concurrent iteration
// may race against OopStorage::release() calls.
- ShenandoahEvacUpdateCleanupOopStorageRootsClosure cl;
+ ShenandoahEvacUpdateCleanupOopStorageRootsClosure cl(_generation);
_vm_roots.oops_do(&cl, worker_id);
}
@@ -1005,7 +1008,7 @@ void ShenandoahConcurrentGC::op_weak_roots() {
// Concurrent weak root processing
ShenandoahTimingsTracker t(ShenandoahPhaseTimings::conc_weak_roots_work);
ShenandoahGCWorkerPhase worker_phase(ShenandoahPhaseTimings::conc_weak_roots_work);
- ShenandoahConcurrentWeakRootsEvacUpdateTask task(ShenandoahPhaseTimings::conc_weak_roots_work);
+ ShenandoahConcurrentWeakRootsEvacUpdateTask task(_generation, ShenandoahPhaseTimings::conc_weak_roots_work);
heap->workers()->run_task(&task);
}
@@ -1107,14 +1110,14 @@ void ShenandoahConcurrentGC::op_cleanup_early() {
}
void ShenandoahConcurrentGC::op_evacuate() {
- ShenandoahHeap::heap()->evacuate_collection_set(true /*concurrent*/);
+ ShenandoahHeap::heap()->evacuate_collection_set(_generation, true /*concurrent*/);
}
void ShenandoahConcurrentGC::op_init_update_refs() {
ShenandoahHeap* const heap = ShenandoahHeap::heap();
if (ShenandoahVerify) {
ShenandoahTimingsTracker v(ShenandoahPhaseTimings::init_update_refs_verify);
- heap->verifier()->verify_before_update_refs();
+ heap->verifier()->verify_before_update_refs(_generation);
}
if (ShenandoahPacing) {
heap->pacer()->setup_for_update_refs();
@@ -1122,7 +1125,7 @@ void ShenandoahConcurrentGC::op_init_update_refs() {
}
void ShenandoahConcurrentGC::op_update_refs() {
- ShenandoahHeap::heap()->update_heap_references(true /*concurrent*/);
+ ShenandoahHeap::heap()->update_heap_references(_generation, true /*concurrent*/);
}
class ShenandoahUpdateThreadClosure : public HandshakeClosure {
@@ -1168,7 +1171,7 @@ void ShenandoahConcurrentGC::op_final_update_refs() {
// Has to be done before cset is clear
if (ShenandoahVerify) {
- heap->verifier()->verify_roots_in_to_space();
+ heap->verifier()->verify_roots_in_to_space(_generation);
}
// If we are running in generational mode and this is an aging cycle, this will also age active
@@ -1203,7 +1206,7 @@ void ShenandoahConcurrentGC::op_final_update_refs() {
if (ShenandoahVerify) {
ShenandoahTimingsTracker v(ShenandoahPhaseTimings::final_update_refs_verify);
- heap->verifier()->verify_after_update_refs();
+ heap->verifier()->verify_after_update_refs(_generation);
}
if (VerifyAfterGC) {
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.hpp b/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.hpp
index d81c49363a23..54d43416fdb3 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.hpp
@@ -47,7 +47,6 @@ class ShenandoahConcurrentGC : public ShenandoahGC {
protected:
ShenandoahConcurrentMark _mark;
- ShenandoahGeneration* const _generation;
private:
ShenandoahDegenPoint _degen_point;
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahConcurrentMark.cpp b/src/hotspot/share/gc/shenandoah/shenandoahConcurrentMark.cpp
index facba2236be8..04d0d28e2bec 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahConcurrentMark.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahConcurrentMark.cpp
@@ -57,18 +57,11 @@ class ShenandoahConcurrentMarkingTask : public WorkerTask {
}
void work(uint worker_id) {
- ShenandoahHeap* heap = ShenandoahHeap::heap();
ShenandoahConcurrentWorkerSession worker_session(worker_id);
ShenandoahWorkerTimingsTracker timer(ShenandoahPhaseTimings::conc_mark, ShenandoahPhaseTimings::ParallelMark, worker_id, true);
ShenandoahSuspendibleThreadSetJoiner stsj;
- // Do not use active_generation() : we must use the gc_generation() set by
- // ShenandoahGCScope on the ControllerThread's stack; no safepoint may
- // intervene to update active_generation, so we can't
- // shenandoah_assert_generations_reconciled() here.
- ShenandoahReferenceProcessor* rp = heap->gc_generation()->ref_processor();
- assert(rp != nullptr, "need reference processor");
StringDedup::Requests requests;
- _cm->mark_loop(worker_id, _terminator, rp, GENERATION, true /*cancellable*/,
+ _cm->mark_loop(worker_id, _terminator, GENERATION, true /*cancellable*/,
ShenandoahStringDedup::is_enabled() ? ENQUEUE_DEDUP : NO_DEDUP,
&requests);
}
@@ -105,9 +98,6 @@ class ShenandoahFinalMarkingTask : public WorkerTask {
ShenandoahParallelWorkerSession worker_session(worker_id);
StringDedup::Requests requests;
- ShenandoahReferenceProcessor* rp = heap->gc_generation()->ref_processor();
- shenandoah_assert_generations_reconciled();
-
// First drain remaining SATB buffers.
{
ShenandoahObjToScanQueue* q = _cm->get_queue(worker_id);
@@ -121,7 +111,7 @@ class ShenandoahFinalMarkingTask : public WorkerTask {
ShenandoahSATBAndRemarkThreadsClosure tc(satb_mq_set);
Threads::possibly_parallel_threads_do(true /* is_par */, &tc);
}
- _cm->mark_loop(worker_id, _terminator, rp, GENERATION, false /*not cancellable*/,
+ _cm->mark_loop(worker_id, _terminator, GENERATION, false /*not cancellable*/,
_dedup_string ? ENQUEUE_DEDUP : NO_DEDUP,
&requests);
assert(_cm->task_queues()->is_empty(), "Should be empty");
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.cpp b/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.cpp
index 641274d30720..f74849f1ecc8 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.cpp
@@ -46,9 +46,8 @@
#include "utilities/events.hpp"
ShenandoahDegenGC::ShenandoahDegenGC(ShenandoahDegenPoint degen_point, ShenandoahGeneration* generation) :
- ShenandoahGC(),
+ ShenandoahGC(generation),
_degen_point(degen_point),
- _generation(generation),
_abbreviated(false) {
}
@@ -260,7 +259,7 @@ void ShenandoahDegenGC::op_degenerated() {
} else if (has_in_place_promotions(heap)) {
// We have nothing to evacuate, but there are still regions to promote in place.
ShenandoahGCPhase phase(ShenandoahPhaseTimings::degen_gc_promote_regions);
- ShenandoahGenerationalHeap::heap()->promote_regions_in_place(false /* concurrent*/);
+ ShenandoahGenerationalHeap::heap()->promote_regions_in_place(_generation, false /* concurrent*/);
}
// Update collector state regardless of whether there are forwarded objects
@@ -300,7 +299,7 @@ void ShenandoahDegenGC::op_degenerated() {
}
if (ShenandoahVerify) {
- heap->verifier()->verify_after_degenerated();
+ heap->verifier()->verify_after_degenerated(_generation);
}
if (VerifyAfterGC) {
@@ -341,11 +340,11 @@ void ShenandoahDegenGC::op_finish_mark() {
void ShenandoahDegenGC::op_prepare_evacuation() {
ShenandoahHeap* const heap = ShenandoahHeap::heap();
if (ShenandoahVerify) {
- heap->verifier()->verify_roots_no_forwarded();
+ heap->verifier()->verify_roots_no_forwarded(_generation);
}
// STW cleanup weak roots and unload classes
- heap->parallel_cleaning(false /*full gc*/);
+ heap->parallel_cleaning(_generation, false /*full gc*/);
// Prepare regions and collection set
_generation->prepare_regions_and_collection_set(false /*concurrent*/);
@@ -362,7 +361,7 @@ void ShenandoahDegenGC::op_prepare_evacuation() {
if (!heap->collection_set()->is_empty()) {
if (ShenandoahVerify) {
- heap->verifier()->verify_before_evacuation();
+ heap->verifier()->verify_before_evacuation(_generation);
}
heap->set_evacuation_in_progress(true);
@@ -370,9 +369,9 @@ void ShenandoahDegenGC::op_prepare_evacuation() {
} else {
if (ShenandoahVerify) {
if (has_in_place_promotions(heap)) {
- heap->verifier()->verify_after_concmark_with_promotions();
+ heap->verifier()->verify_after_concmark_with_promotions(_generation);
} else {
- heap->verifier()->verify_after_concmark();
+ heap->verifier()->verify_after_concmark(_generation);
}
}
@@ -392,7 +391,7 @@ void ShenandoahDegenGC::op_cleanup_early() {
void ShenandoahDegenGC::op_evacuate() {
ShenandoahGCPhase phase(ShenandoahPhaseTimings::degen_gc_stw_evac);
- ShenandoahHeap::heap()->evacuate_collection_set(false /* concurrent*/);
+ ShenandoahHeap::heap()->evacuate_collection_set(_generation, false /* concurrent*/);
}
void ShenandoahDegenGC::op_init_update_refs() {
@@ -406,7 +405,7 @@ void ShenandoahDegenGC::op_update_refs() {
ShenandoahHeap* const heap = ShenandoahHeap::heap();
ShenandoahGCPhase phase(ShenandoahPhaseTimings::degen_gc_update_refs);
// Handed over from concurrent update references phase
- heap->update_heap_references(false /*concurrent*/);
+ heap->update_heap_references(_generation, false /*concurrent*/);
heap->set_update_refs_in_progress(false);
heap->set_has_forwarded_objects(false);
@@ -420,7 +419,7 @@ void ShenandoahDegenGC::op_update_roots() {
heap->update_heap_region_states(false /*concurrent*/);
if (ShenandoahVerify) {
- heap->verifier()->verify_after_update_refs();
+ heap->verifier()->verify_after_update_refs(_generation);
}
if (VerifyAfterGC) {
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.hpp b/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.hpp
index 971bd67eb0df..34b9688106c9 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.hpp
@@ -34,12 +34,11 @@ class ShenandoahDegenGC : public ShenandoahGC {
friend class VM_ShenandoahDegeneratedGC;
private:
const ShenandoahDegenPoint _degen_point;
- ShenandoahGeneration* _generation;
bool _abbreviated;
public:
ShenandoahDegenGC(ShenandoahDegenPoint degen_point, ShenandoahGeneration* generation);
- bool collect(GCCause::Cause cause);
+ bool collect(GCCause::Cause cause) override;
private:
void vmop_degenerated();
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahFullGC.cpp b/src/hotspot/share/gc/shenandoah/shenandoahFullGC.cpp
index b9455ebfeb0f..64ee2e7670b3 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahFullGC.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahFullGC.cpp
@@ -68,6 +68,7 @@
#include "utilities/growableArray.hpp"
ShenandoahFullGC::ShenandoahFullGC() :
+ ShenandoahGC(ShenandoahHeap::heap()->global_generation()),
_gc_timer(ShenandoahHeap::heap()->gc_timer()),
_preserved_marks(new PreservedMarksSet(true)) {}
@@ -124,7 +125,7 @@ void ShenandoahFullGC::op_full(GCCause::Cause cause) {
}
// Regardless if progress was made, we record that we completed a "successful" full GC.
- heap->global_generation()->heuristics()->record_success_full();
+ _generation->heuristics()->record_success_full();
heap->shenandoah_policy()->record_success_full();
{
@@ -141,7 +142,7 @@ void ShenandoahFullGC::do_it(GCCause::Cause gc_cause) {
}
if (ShenandoahVerify) {
- heap->verifier()->verify_before_fullgc();
+ heap->verifier()->verify_before_fullgc(_generation);
}
if (VerifyBeforeGC) {
@@ -194,7 +195,7 @@ void ShenandoahFullGC::do_it(GCCause::Cause gc_cause) {
}
// d. Abandon reference discovery and clear all discovered references.
- ShenandoahReferenceProcessor* rp = heap->global_generation()->ref_processor();
+ ShenandoahReferenceProcessor* rp = _generation->ref_processor();
rp->abandon_partial_discovery();
// e. Sync pinned region status from the CP marks
@@ -273,7 +274,7 @@ void ShenandoahFullGC::do_it(GCCause::Cause gc_cause) {
heap->set_full_gc_in_progress(false);
if (ShenandoahVerify) {
- heap->verifier()->verify_after_fullgc();
+ heap->verifier()->verify_after_fullgc(_generation);
}
if (VerifyAfterGC) {
@@ -292,19 +293,19 @@ void ShenandoahFullGC::phase1_mark_heap() {
ShenandoahHeap* heap = ShenandoahHeap::heap();
- heap->global_generation()->reset_mark_bitmap();
+ _generation->reset_mark_bitmap();
assert(heap->marking_context()->is_bitmap_clear(), "sanity");
- assert(!heap->global_generation()->is_mark_complete(), "sanity");
+ assert(!_generation->is_mark_complete(), "sanity");
- heap->set_unload_classes(heap->global_generation()->heuristics()->can_unload_classes());
+ heap->set_unload_classes(_generation->heuristics()->can_unload_classes());
- ShenandoahReferenceProcessor* rp = heap->global_generation()->ref_processor();
+ ShenandoahReferenceProcessor* rp = _generation->ref_processor();
// enable ("weak") refs discovery
rp->set_soft_reference_policy(true); // forcefully purge all soft references
- ShenandoahSTWMark mark(heap->global_generation(), true /*full_gc*/);
+ ShenandoahSTWMark mark(_generation, true /*full_gc*/);
mark.mark();
- heap->parallel_cleaning(true /* full_gc */);
+ heap->parallel_cleaning(_generation, true /* full_gc */);
if (ShenandoahHeap::heap()->mode()->is_generational()) {
ShenandoahGenerationalFullGC::log_live_in_old(heap);
@@ -350,10 +351,12 @@ class ShenandoahPrepareForCompactionObjectClosure : public ObjectClosure {
return _empty_regions_pos;
}
- void do_object(oop p) {
+ void do_object(oop p) override {
+ shenandoah_assert_mark_complete(cast_from_oop(p));
assert(_from_region != nullptr, "must set before work");
- assert(_heap->gc_generation()->complete_marking_context()->is_marked(p), "must be marked");
- assert(!_heap->gc_generation()->complete_marking_context()->allocated_after_mark_start(p), "must be truly marked");
+ assert(_heap->global_generation()->is_mark_complete(), "marking must be finished");
+ assert(_heap->marking_context()->is_marked(p), "must be marked");
+ assert(!_heap->marking_context()->allocated_after_mark_start(p), "must be truly marked");
size_t obj_size = p->size();
if (_compact_point + obj_size > _to_region->end()) {
@@ -523,12 +526,8 @@ void ShenandoahFullGC::calculate_target_humongous_objects() {
}
class ShenandoahEnsureHeapActiveClosure: public ShenandoahHeapRegionClosure {
-private:
- ShenandoahHeap* const _heap;
-
public:
- ShenandoahEnsureHeapActiveClosure() : _heap(ShenandoahHeap::heap()) {}
- void heap_region_do(ShenandoahHeapRegion* r) {
+ void heap_region_do(ShenandoahHeapRegion* r) override {
if (r->is_trash()) {
r->try_recycle_under_lock();
}
@@ -760,7 +759,6 @@ void ShenandoahFullGC::phase2_calculate_target_addresses(ShenandoahHeapRegionSet
class ShenandoahAdjustPointersClosure : public MetadataVisitingOopIterateClosure {
private:
- ShenandoahHeap* const _heap;
ShenandoahMarkingContext* const _ctx;
template
@@ -778,8 +776,7 @@ class ShenandoahAdjustPointersClosure : public MetadataVisitingOopIterateClosure
public:
ShenandoahAdjustPointersClosure() :
- _heap(ShenandoahHeap::heap()),
- _ctx(ShenandoahHeap::heap()->gc_generation()->complete_marking_context()) {}
+ _ctx(ShenandoahHeap::heap()->global_generation()->complete_marking_context()) {}
void do_oop(oop* p) { do_oop_work(p); }
void do_oop(narrowOop* p) { do_oop_work(p); }
@@ -789,15 +786,12 @@ class ShenandoahAdjustPointersClosure : public MetadataVisitingOopIterateClosure
class ShenandoahAdjustPointersObjectClosure : public ObjectClosure {
private:
- ShenandoahHeap* const _heap;
ShenandoahAdjustPointersClosure _cl;
public:
- ShenandoahAdjustPointersObjectClosure() :
- _heap(ShenandoahHeap::heap()) {
- }
- void do_object(oop p) {
- assert(_heap->gc_generation()->complete_marking_context()->is_marked(p), "must be marked");
+ void do_object(oop p) override {
+ assert(ShenandoahHeap::heap()->global_generation()->is_mark_complete(), "marking must be complete");
+ assert(ShenandoahHeap::heap()->marking_context()->is_marked(p), "must be marked");
p->oop_iterate(&_cl);
}
};
@@ -813,7 +807,7 @@ class ShenandoahAdjustPointersTask : public WorkerTask {
_heap(ShenandoahHeap::heap()) {
}
- void work(uint worker_id) {
+ void work(uint worker_id) override {
ShenandoahParallelWorkerSession worker_session(worker_id);
ShenandoahAdjustPointersObjectClosure obj_cl;
ShenandoahHeapRegion* r = _regions.next();
@@ -839,7 +833,7 @@ class ShenandoahAdjustRootPointersTask : public WorkerTask {
_rp(rp),
_preserved_marks(preserved_marks) {}
- void work(uint worker_id) {
+ void work(uint worker_id) override {
ShenandoahParallelWorkerSession worker_session(worker_id);
ShenandoahAdjustPointersClosure cl;
_rp->roots_do(worker_id, &cl);
@@ -873,15 +867,15 @@ void ShenandoahFullGC::phase3_update_references() {
class ShenandoahCompactObjectsClosure : public ObjectClosure {
private:
- ShenandoahHeap* const _heap;
- uint const _worker_id;
+ uint const _worker_id;
public:
- ShenandoahCompactObjectsClosure(uint worker_id) :
- _heap(ShenandoahHeap::heap()), _worker_id(worker_id) {}
+ explicit ShenandoahCompactObjectsClosure(uint worker_id) :
+ _worker_id(worker_id) {}
- void do_object(oop p) {
- assert(_heap->gc_generation()->complete_marking_context()->is_marked(p), "must be marked");
+ void do_object(oop p) override {
+ assert(ShenandoahHeap::heap()->global_generation()->is_mark_complete(), "marking must be finished");
+ assert(ShenandoahHeap::heap()->marking_context()->is_marked(p), "must be marked");
size_t size = p->size();
if (FullGCForwarding::is_forwarded(p)) {
HeapWord* compact_from = cast_from_oop(p);
@@ -911,7 +905,7 @@ class ShenandoahCompactObjectsTask : public WorkerTask {
_worker_slices(worker_slices) {
}
- void work(uint worker_id) {
+ void work(uint worker_id) override {
ShenandoahParallelWorkerSession worker_session(worker_id);
ShenandoahHeapRegionSetIterator slice(_worker_slices[worker_id]);
@@ -948,7 +942,7 @@ class ShenandoahPostCompactClosure : public ShenandoahHeapRegionClosure {
_heap->free_set()->clear();
}
- void heap_region_do(ShenandoahHeapRegion* r) {
+ void heap_region_do(ShenandoahHeapRegion* r) override {
assert (!r->is_cset(), "cset regions should have been demoted already");
// Need to reset the complete-top-at-mark-start pointer here because
@@ -957,7 +951,7 @@ class ShenandoahPostCompactClosure : public ShenandoahHeapRegionClosure {
// NOTE: See blurb at ShenandoahMCResetCompleteBitmapTask on why we need to skip
// pinned regions.
if (!r->is_pinned()) {
- _heap->gc_generation()->complete_marking_context()->reset_top_at_mark_start(r);
+ _heap->marking_context()->reset_top_at_mark_start(r);
}
size_t live = r->used();
@@ -1082,7 +1076,7 @@ void ShenandoahFullGC::compact_humongous_objects() {
// we need to remain able to walk pinned regions.
// Since pinned region do not move and don't get compacted, we will get holes with
// unreachable objects in them (which may have pointers to unloaded Klasses and thus
-// cannot be iterated over using oop->size(). The only way to safely iterate over those is using
+// cannot be iterated over using oop->size()). The only way to safely iterate over those is using
// a valid marking bitmap and valid TAMS pointer. This class only resets marking
// bitmaps for un-pinned regions, and later we only reset TAMS for unpinned regions.
class ShenandoahMCResetCompleteBitmapTask : public WorkerTask {
@@ -1094,11 +1088,12 @@ class ShenandoahMCResetCompleteBitmapTask : public WorkerTask {
WorkerTask("Shenandoah Reset Bitmap") {
}
- void work(uint worker_id) {
+ void work(uint worker_id) override {
ShenandoahParallelWorkerSession worker_session(worker_id);
ShenandoahHeapRegion* region = _regions.next();
ShenandoahHeap* heap = ShenandoahHeap::heap();
- ShenandoahMarkingContext* const ctx = heap->gc_generation()->complete_marking_context();
+ ShenandoahMarkingContext* const ctx = heap->marking_context();
+ assert(heap->global_generation()->is_mark_complete(), "Marking must be complete");
while (region != nullptr) {
if (heap->is_bitmap_slice_committed(region) && !region->is_pinned() && region->has_live()) {
ctx->clear_bitmap(region);
@@ -1166,7 +1161,7 @@ ShenandoahGenerationalHeap::TransferResult ShenandoahFullGC::phase5_epilog() {
heap->free_set()->finish_rebuild(young_cset_regions, old_cset_regions, num_old);
// Set mark incomplete because the marking bitmaps have been reset except pinned regions.
- heap->global_generation()->set_mark_incomplete();
+ _generation->set_mark_incomplete();
heap->clear_cancelled_gc();
}
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahFullGC.hpp b/src/hotspot/share/gc/shenandoah/shenandoahFullGC.hpp
index b0b8c7bf0c59..8b8244f2ce3a 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahFullGC.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahFullGC.hpp
@@ -68,7 +68,7 @@ class ShenandoahFullGC : public ShenandoahGC {
public:
ShenandoahFullGC();
~ShenandoahFullGC();
- bool collect(GCCause::Cause cause);
+ bool collect(GCCause::Cause cause) override;
private:
// GC entries
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGC.hpp b/src/hotspot/share/gc/shenandoah/shenandoahGC.hpp
index f08bdce0a202..7182665f2e3a 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGC.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGC.hpp
@@ -44,6 +44,8 @@
* Full GC --------> (finish)
*/
+class ShenandoahGeneration;
+
class ShenandoahGC : public StackObj {
public:
// Fail point from concurrent GC
@@ -57,12 +59,17 @@ class ShenandoahGC : public StackObj {
_DEGENERATED_LIMIT
};
+ explicit ShenandoahGC(ShenandoahGeneration* generation) : _generation(generation) {}
+
// Returns false if the collection was cancelled, true otherwise.
virtual bool collect(GCCause::Cause cause) = 0;
static const char* degen_point_to_string(ShenandoahDegenPoint point);
+ ShenandoahGeneration* generation() const { return _generation; }
protected:
static void update_roots(bool full_gc);
+
+ ShenandoahGeneration* _generation;
};
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHGC_HPP
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp b/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp
index 664ec40e37e0..33970683805b 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp
@@ -807,7 +807,7 @@ ShenandoahGeneration::ShenandoahGeneration(ShenandoahGenerationType type,
size_t max_capacity) :
_type(type),
_task_queues(new ShenandoahObjToScanQueueSet(max_workers)),
- _ref_processor(new ShenandoahReferenceProcessor(MAX2(max_workers, 1U))),
+ _ref_processor(new ShenandoahReferenceProcessor(this, MAX2(max_workers, 1U))),
_affiliated_region_count(0), _humongous_waste(0), _evacuation_reserve(0),
_used(0), _bytes_allocated_since_gc_start(0),
_max_capacity(max_capacity),
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGeneration.hpp b/src/hotspot/share/gc/shenandoah/shenandoahGeneration.hpp
index 52b08fc0c520..82dacb639496 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGeneration.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGeneration.hpp
@@ -203,7 +203,7 @@ class ShenandoahGeneration : public CHeapObj, public ShenandoahSpaceInfo {
bool is_bitmap_clear();
// We need to track the status of marking for different generations.
- bool is_mark_complete() { return _is_marking_complete.is_set(); }
+ bool is_mark_complete() const { return _is_marking_complete.is_set(); }
virtual void set_mark_complete();
virtual void set_mark_incomplete();
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.cpp b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.cpp
index a228595ffdf8..b918957f5bb7 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.cpp
@@ -51,10 +51,12 @@ class ShenandoahConcurrentEvacuator : public ObjectClosure {
};
ShenandoahGenerationalEvacuationTask::ShenandoahGenerationalEvacuationTask(ShenandoahGenerationalHeap* heap,
+ ShenandoahGeneration* generation,
ShenandoahRegionIterator* iterator,
bool concurrent, bool only_promote_regions) :
WorkerTask("Shenandoah Evacuation"),
_heap(heap),
+ _generation(generation),
_regions(iterator),
_concurrent(concurrent),
_only_promote_regions(only_promote_regions)
@@ -173,13 +175,12 @@ void ShenandoahGenerationalEvacuationTask::maybe_promote_region(ShenandoahHeapRe
// We identify the entirety of the region as DIRTY to force the next remembered set scan to identify the "interesting pointers"
// contained herein.
void ShenandoahGenerationalEvacuationTask::promote_in_place(ShenandoahHeapRegion* region) {
- assert(!_heap->gc_generation()->is_old(), "Sanity check");
+ assert(!_generation->is_old(), "Sanity check");
ShenandoahMarkingContext* const marking_context = _heap->young_generation()->complete_marking_context();
HeapWord* const tams = marking_context->top_at_mark_start(region);
{
const size_t old_garbage_threshold = (ShenandoahHeapRegion::region_size_bytes() * ShenandoahOldGarbageThreshold) / 100;
- shenandoah_assert_generations_reconciled();
assert(!_heap->is_concurrent_old_mark_in_progress(), "Cannot promote in place during old marking");
assert(region->garbage_before_padded_for_promote() < old_garbage_threshold, "Region %zu has too much garbage for promotion", region->index());
assert(region->is_young(), "Only young regions can be promoted");
@@ -263,8 +264,7 @@ void ShenandoahGenerationalEvacuationTask::promote_in_place(ShenandoahHeapRegion
void ShenandoahGenerationalEvacuationTask::promote_humongous(ShenandoahHeapRegion* region) {
ShenandoahMarkingContext* marking_context = _heap->marking_context();
oop obj = cast_to_oop(region->bottom());
- assert(_heap->gc_generation()->is_mark_complete(), "sanity");
- shenandoah_assert_generations_reconciled();
+ assert(_generation->is_mark_complete(), "sanity");
assert(region->is_young(), "Only young regions can be promoted");
assert(region->is_humongous_start(), "Should not promote humongous continuation in isolation");
assert(_heap->is_tenurable(region), "Only promote regions that are sufficiently aged");
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.hpp b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.hpp
index 0c402d6c90a5..de47184ffffc 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalEvacuationTask.hpp
@@ -36,12 +36,14 @@ class ShenandoahRegionIterator;
class ShenandoahGenerationalEvacuationTask : public WorkerTask {
private:
ShenandoahGenerationalHeap* const _heap;
+ ShenandoahGeneration* const _generation;
ShenandoahRegionIterator* _regions;
bool _concurrent;
bool _only_promote_regions;
public:
ShenandoahGenerationalEvacuationTask(ShenandoahGenerationalHeap* sh,
+ ShenandoahGeneration* generation,
ShenandoahRegionIterator* iterator,
bool concurrent, bool only_promote_regions);
void work(uint worker_id) override;
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalFullGC.cpp b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalFullGC.cpp
index c4a7408e0324..8d8091472fcb 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalFullGC.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalFullGC.cpp
@@ -53,8 +53,7 @@ void assert_usage_not_more_than_regions_used(ShenandoahGeneration* generation) {
void ShenandoahGenerationalFullGC::prepare() {
auto heap = ShenandoahGenerationalHeap::heap();
// Since we may arrive here from degenerated GC failure of either young or old, establish generation as GLOBAL.
- heap->set_gc_generation(heap->global_generation());
- heap->set_active_generation();
+ heap->set_active_generation(heap->global_generation());
// No need for old_gen->increase_used() as this was done when plabs were allocated.
heap->reset_generation_reserves();
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp
index 2c817774b374..634e9a9d3167 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.cpp
@@ -177,15 +177,15 @@ bool ShenandoahGenerationalHeap::requires_barriers(stackChunkOop obj) const {
return false;
}
-void ShenandoahGenerationalHeap::evacuate_collection_set(bool concurrent) {
+void ShenandoahGenerationalHeap::evacuate_collection_set(ShenandoahGeneration* generation, bool concurrent) {
ShenandoahRegionIterator regions;
- ShenandoahGenerationalEvacuationTask task(this, ®ions, concurrent, false /* only promote regions */);
+ ShenandoahGenerationalEvacuationTask task(this, generation, ®ions, concurrent, false /* only promote regions */);
workers()->run_task(&task);
}
-void ShenandoahGenerationalHeap::promote_regions_in_place(bool concurrent) {
+void ShenandoahGenerationalHeap::promote_regions_in_place(ShenandoahGeneration* generation, bool concurrent) {
ShenandoahRegionIterator regions;
- ShenandoahGenerationalEvacuationTask task(this, ®ions, concurrent, true /* only promote regions */);
+ ShenandoahGenerationalEvacuationTask task(this, generation, ®ions, concurrent, true /* only promote regions */);
workers()->run_task(&task);
}
@@ -759,23 +759,27 @@ void ShenandoahGenerationalHeap::coalesce_and_fill_old_regions(bool concurrent)
template
class ShenandoahGenerationalUpdateHeapRefsTask : public WorkerTask {
private:
+ // For update refs, _generation will be young or global. Mixed collections use the young generation.
+ ShenandoahGeneration* _generation;
ShenandoahGenerationalHeap* _heap;
ShenandoahRegionIterator* _regions;
ShenandoahRegionChunkIterator* _work_chunks;
public:
- explicit ShenandoahGenerationalUpdateHeapRefsTask(ShenandoahRegionIterator* regions,
- ShenandoahRegionChunkIterator* work_chunks) :
+ ShenandoahGenerationalUpdateHeapRefsTask(ShenandoahGeneration* generation,
+ ShenandoahRegionIterator* regions,
+ ShenandoahRegionChunkIterator* work_chunks) :
WorkerTask("Shenandoah Update References"),
+ _generation(generation),
_heap(ShenandoahGenerationalHeap::heap()),
_regions(regions),
_work_chunks(work_chunks)
{
- bool old_bitmap_stable = _heap->old_generation()->is_mark_complete();
+ const bool old_bitmap_stable = _heap->old_generation()->is_mark_complete();
log_debug(gc, remset)("Update refs, scan remembered set using bitmap: %s", BOOL_TO_STR(old_bitmap_stable));
}
- void work(uint worker_id) {
+ void work(uint worker_id) override {
if (CONCURRENT) {
ShenandoahConcurrentWorkerSession worker_session(worker_id);
ShenandoahSuspendibleThreadSetJoiner stsj;
@@ -805,10 +809,8 @@ class ShenandoahGenerationalUpdateHeapRefsTask : public WorkerTask {
// If !CONCURRENT, there's no value in expanding Mutator free set
ShenandoahHeapRegion* r = _regions->next();
- // We update references for global, old, and young collections.
- ShenandoahGeneration* const gc_generation = _heap->gc_generation();
- shenandoah_assert_generations_reconciled();
- assert(gc_generation->is_mark_complete(), "Expected complete marking");
+ // We update references for global, mixed, and young collections.
+ assert(_generation->is_mark_complete(), "Expected complete marking");
ShenandoahMarkingContext* const ctx = _heap->marking_context();
bool is_mixed = _heap->collection_set()->has_old_regions();
while (r != nullptr) {
@@ -822,7 +824,7 @@ class ShenandoahGenerationalUpdateHeapRefsTask : public WorkerTask {
_heap->marked_object_oop_iterate(r, &cl, update_watermark);
region_progress = true;
} else if (r->is_old()) {
- if (gc_generation->is_global()) {
+ if (_generation->is_global()) {
_heap->marked_object_oop_iterate(r, &cl, update_watermark);
region_progress = true;
@@ -857,7 +859,7 @@ class ShenandoahGenerationalUpdateHeapRefsTask : public WorkerTask {
r = _regions->next();
}
- if (!gc_generation->is_global()) {
+ if (_generation->is_young()) {
// Since this is generational and not GLOBAL, we have to process the remembered set. There's no remembered
// set processing if not in generational mode or if GLOBAL mode.
@@ -975,15 +977,15 @@ class ShenandoahGenerationalUpdateHeapRefsTask : public WorkerTask {
}
};
-void ShenandoahGenerationalHeap::update_heap_references(bool concurrent) {
+void ShenandoahGenerationalHeap::update_heap_references(ShenandoahGeneration* generation, bool concurrent) {
assert(!is_full_gc_in_progress(), "Only for concurrent and degenerated GC");
const uint nworkers = workers()->active_workers();
ShenandoahRegionChunkIterator work_list(nworkers);
if (concurrent) {
- ShenandoahGenerationalUpdateHeapRefsTask task(&_update_refs_iterator, &work_list);
+ ShenandoahGenerationalUpdateHeapRefsTask task(generation, &_update_refs_iterator, &work_list);
workers()->run_task(&task);
} else {
- ShenandoahGenerationalUpdateHeapRefsTask task(&_update_refs_iterator, &work_list);
+ ShenandoahGenerationalUpdateHeapRefsTask task(generation, &_update_refs_iterator, &work_list);
workers()->run_task(&task);
}
@@ -1058,7 +1060,7 @@ class ShenandoahUpdateRegionAges : public ShenandoahHeapRegionClosure {
void ShenandoahGenerationalHeap::final_update_refs_update_region_states() {
ShenandoahSynchronizePinnedRegionStates pins;
- ShenandoahUpdateRegionAges ages(active_generation()->complete_marking_context());
+ ShenandoahUpdateRegionAges ages(marking_context());
auto cl = ShenandoahCompositeRegionClosure::of(pins, ages);
parallel_heap_region_iterate(&cl);
}
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.hpp b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.hpp
index adf9c73a2322..48a99b7a64a4 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.hpp
@@ -87,8 +87,11 @@ class ShenandoahGenerationalHeap : public ShenandoahHeap {
oop evacuate_object(oop p, Thread* thread) override;
oop try_evacuate_object(oop p, Thread* thread, ShenandoahHeapRegion* from_region, ShenandoahAffiliation target_gen);
- void evacuate_collection_set(bool concurrent) override;
- void promote_regions_in_place(bool concurrent);
+
+ // In the generational mode, we will use these two functions for young, mixed, and global collections.
+ // For young and mixed, the generation argument will be the young generation, otherwise it will be the global generation.
+ void evacuate_collection_set(ShenandoahGeneration* generation, bool concurrent) override;
+ void promote_regions_in_place(ShenandoahGeneration* generation, bool concurrent);
size_t plab_min_size() const { return _min_plab_size; }
size_t plab_max_size() const { return _max_plab_size; }
@@ -98,7 +101,9 @@ class ShenandoahGenerationalHeap : public ShenandoahHeap {
// ---------- Update References
//
- void update_heap_references(bool concurrent) override;
+ // In the generational mode, we will use this function for young, mixed, and global collections.
+ // For young and mixed, the generation argument will be the young generation, otherwise it will be the global generation.
+ void update_heap_references(ShenandoahGeneration* generation, bool concurrent) override;
void final_update_refs_update_region_states() override;
private:
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
index 1749c3077835..cb3e74a5274d 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
@@ -535,7 +535,6 @@ void ShenandoahHeap::initialize_heuristics() {
ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) :
CollectedHeap(),
- _gc_generation(nullptr),
_active_generation(nullptr),
_initial_size(0),
_committed(0),
@@ -1282,7 +1281,8 @@ class ShenandoahPrepareForUpdateRefs : public HandshakeClosure {
ShenandoahGCStatePropagator _propagator;
};
-void ShenandoahHeap::evacuate_collection_set(bool concurrent) {
+void ShenandoahHeap::evacuate_collection_set(ShenandoahGeneration* generation, bool concurrent) {
+ assert(generation->is_global(), "Only global generation expected here");
ShenandoahEvacuationTask task(this, _collection_set, concurrent);
workers()->run_task(&task);
}
@@ -1697,17 +1697,11 @@ void ShenandoahHeap::print_tracing_info() const {
}
}
-void ShenandoahHeap::set_gc_generation(ShenandoahGeneration* generation) {
- shenandoah_assert_control_or_vm_thread_at_safepoint();
- _gc_generation = generation;
-}
-
// Active generation may only be set by the VM thread at a safepoint.
-void ShenandoahHeap::set_active_generation() {
+void ShenandoahHeap::set_active_generation(ShenandoahGeneration* generation) {
assert(Thread::current()->is_VM_thread(), "Only the VM Thread");
assert(SafepointSynchronize::is_at_safepoint(), "Only at a safepoint!");
- assert(_gc_generation != nullptr, "Will set _active_generation to nullptr");
- _active_generation = _gc_generation;
+ _active_generation = generation;
}
void ShenandoahHeap::on_cycle_start(GCCause::Cause cause, ShenandoahGeneration* generation) {
@@ -1716,17 +1710,14 @@ void ShenandoahHeap::on_cycle_start(GCCause::Cause cause, ShenandoahGeneration*
const GCCause::Cause current = gc_cause();
assert(current == GCCause::_no_gc, "Over-writing cause: %s, with: %s",
GCCause::to_string(current), GCCause::to_string(cause));
- assert(_gc_generation == nullptr, "Over-writing _gc_generation");
set_gc_cause(cause);
- set_gc_generation(generation);
generation->heuristics()->record_cycle_start();
}
void ShenandoahHeap::on_cycle_end(ShenandoahGeneration* generation) {
assert(gc_cause() != GCCause::_no_gc, "cause wasn't set");
- assert(_gc_generation != nullptr, "_gc_generation wasn't set");
generation->heuristics()->record_cycle_end();
if (mode()->is_generational() && generation->is_global()) {
@@ -1735,14 +1726,13 @@ void ShenandoahHeap::on_cycle_end(ShenandoahGeneration* generation) {
old_generation()->heuristics()->record_cycle_end();
}
- set_gc_generation(nullptr);
set_gc_cause(GCCause::_no_gc);
}
void ShenandoahHeap::verify(VerifyOption vo) {
if (ShenandoahSafepoint::is_at_shenandoah_safepoint()) {
if (ShenandoahVerify) {
- verifier()->verify_generic(vo);
+ verifier()->verify_generic(active_generation(), vo);
} else {
// TODO: Consider allocating verification bitmaps on demand,
// and turn this on unconditionally.
@@ -2095,14 +2085,13 @@ void ShenandoahHeap::do_class_unloading() {
}
}
-void ShenandoahHeap::stw_weak_refs(bool full_gc) {
+void ShenandoahHeap::stw_weak_refs(ShenandoahGeneration* generation, bool full_gc) {
// Weak refs processing
ShenandoahPhaseTimings::Phase phase = full_gc ? ShenandoahPhaseTimings::full_gc_weakrefs
: ShenandoahPhaseTimings::degen_gc_weakrefs;
ShenandoahTimingsTracker t(phase);
ShenandoahGCWorkerPhase worker_phase(phase);
- shenandoah_assert_generations_reconciled();
- gc_generation()->ref_processor()->process_references(phase, workers(), false /* concurrent */);
+ generation->ref_processor()->process_references(phase, workers(), false /* concurrent */);
}
void ShenandoahHeap::prepare_update_heap_references() {
@@ -2354,13 +2343,13 @@ void ShenandoahHeap::stw_process_weak_roots(bool full_gc) {
}
}
-void ShenandoahHeap::parallel_cleaning(bool full_gc) {
+void ShenandoahHeap::parallel_cleaning(ShenandoahGeneration* generation, bool full_gc) {
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
assert(is_stw_gc_in_progress(), "Only for Degenerated and Full GC");
ShenandoahGCPhase phase(full_gc ?
ShenandoahPhaseTimings::full_gc_purge :
ShenandoahPhaseTimings::degen_gc_purge);
- stw_weak_refs(full_gc);
+ stw_weak_refs(generation, full_gc);
stw_process_weak_roots(full_gc);
stw_unload_classes(full_gc);
}
@@ -2465,11 +2454,14 @@ void ShenandoahHeap::sync_pinned_region_status() {
}
#ifdef ASSERT
-void ShenandoahHeap::assert_pinned_region_status() {
+void ShenandoahHeap::assert_pinned_region_status() const {
+ assert_pinned_region_status(global_generation());
+}
+
+void ShenandoahHeap::assert_pinned_region_status(ShenandoahGeneration* generation) const {
for (size_t i = 0; i < num_regions(); i++) {
ShenandoahHeapRegion* r = get_region(i);
- shenandoah_assert_generations_reconciled();
- if (gc_generation()->contains(r)) {
+ if (generation->contains(r)) {
assert((r->is_pinned() && r->pin_count() > 0) || (!r->is_pinned() && r->pin_count() == 0),
"Region %zu pinning status is inconsistent", i);
}
@@ -2578,7 +2570,8 @@ class ShenandoahUpdateHeapRefsTask : public WorkerTask {
}
};
-void ShenandoahHeap::update_heap_references(bool concurrent) {
+void ShenandoahHeap::update_heap_references(ShenandoahGeneration* generation, bool concurrent) {
+ assert(generation->is_global(), "Should only get global generation here");
assert(!is_full_gc_in_progress(), "Only for concurrent and degenerated GC");
if (concurrent) {
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
index b5b7200329ad..0dbc2b25ba4e 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
@@ -147,17 +147,10 @@ class ShenandoahHeap : public CollectedHeap {
private:
ShenandoahHeapLock _lock;
- // Indicates the generation whose collection is in
- // progress. Mutator threads aren't allowed to read
- // this field.
- ShenandoahGeneration* _gc_generation;
-
// This is set and cleared by only the VMThread
- // at each STW pause (safepoint) to the value seen in
- // _gc_generation. This allows the value to be always consistently
+ // at each STW pause (safepoint) to the value given to the VM operation.
+ // This allows the value to be always consistently
// seen by all mutators as well as all GC worker threads.
- // In that sense, it's a stable snapshot of _gc_generation that is
- // updated at each STW pause associated with a ShenandoahVMOp.
ShenandoahGeneration* _active_generation;
public:
@@ -165,25 +158,13 @@ class ShenandoahHeap : public CollectedHeap {
return &_lock;
}
- ShenandoahGeneration* gc_generation() const {
- // We don't want this field read by a mutator thread
- assert(!Thread::current()->is_Java_thread(), "Not allowed");
- // value of _gc_generation field, see above
- return _gc_generation;
- }
-
ShenandoahGeneration* active_generation() const {
// value of _active_generation field, see above
return _active_generation;
}
- // Set the _gc_generation field
- void set_gc_generation(ShenandoahGeneration* generation);
-
- // Copy the value in the _gc_generation field into
- // the _active_generation field: can only be called at
- // a safepoint by the VMThread.
- void set_active_generation();
+ // Update the _active_generation field: can only be called at a safepoint by the VMThread.
+ void set_active_generation(ShenandoahGeneration* generation);
ShenandoahHeuristics* heuristics();
@@ -484,7 +465,7 @@ class ShenandoahHeap : public CollectedHeap {
// GC support
// Evacuation
- virtual void evacuate_collection_set(bool concurrent);
+ virtual void evacuate_collection_set(ShenandoahGeneration* generation, bool concurrent);
// Concurrent root processing
void prepare_concurrent_roots();
void finish_concurrent_roots();
@@ -499,7 +480,7 @@ class ShenandoahHeap : public CollectedHeap {
// Turn off weak roots flag, purge old satb buffers in generational mode
void concurrent_final_roots(HandshakeClosure* handshake_closure = nullptr);
- virtual void update_heap_references(bool concurrent);
+ virtual void update_heap_references(ShenandoahGeneration* generation, bool concurrent);
// Final update region states
void update_heap_region_states(bool concurrent);
virtual void final_update_refs_update_region_states();
@@ -607,12 +588,12 @@ class ShenandoahHeap : public CollectedHeap {
bool unload_classes() const;
// Perform STW class unloading and weak root cleaning
- void parallel_cleaning(bool full_gc);
+ void parallel_cleaning(ShenandoahGeneration* generation, bool full_gc);
private:
void stw_unload_classes(bool full_gc);
void stw_process_weak_roots(bool full_gc);
- void stw_weak_refs(bool full_gc);
+ void stw_weak_refs(ShenandoahGeneration* generation, bool full_gc);
inline void assert_lock_for_affiliation(ShenandoahAffiliation orig_affiliation,
ShenandoahAffiliation new_affiliation);
@@ -690,7 +671,8 @@ class ShenandoahHeap : public CollectedHeap {
void unpin_object(JavaThread* thread, oop obj) override;
void sync_pinned_region_status();
- void assert_pinned_region_status() NOT_DEBUG_RETURN;
+ void assert_pinned_region_status() const NOT_DEBUG_RETURN;
+ void assert_pinned_region_status(ShenandoahGeneration* generation) const NOT_DEBUG_RETURN;
// ---------- CDS archive support
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
index 39f25194a6d7..2b8445ebe6f4 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp
@@ -312,9 +312,9 @@ void ShenandoahHeapRegion::make_trash_immediate() {
// On this path, we know there are no marked objects in the region,
// tell marking context about it to bypass bitmap resets.
- assert(ShenandoahHeap::heap()->gc_generation()->is_mark_complete(), "Marking should be complete here.");
- shenandoah_assert_generations_reconciled();
- ShenandoahHeap::heap()->marking_context()->reset_top_bitmap(this);
+ const ShenandoahHeap* heap = ShenandoahHeap::heap();
+ assert(heap->generation_for(affiliation())->is_mark_complete(), "Marking should be complete here.");
+ heap->marking_context()->reset_top_bitmap(this);
}
void ShenandoahHeapRegion::make_empty() {
@@ -458,9 +458,9 @@ bool ShenandoahHeapRegion::oop_coalesce_and_fill(bool cancellable) {
ShenandoahGenerationalHeap* heap = ShenandoahGenerationalHeap::heap();
ShenandoahMarkingContext* marking_context = heap->marking_context();
- // Expect marking to be completed before these threads invoke this service.
- assert(heap->gc_generation()->is_mark_complete(), "sanity");
- shenandoah_assert_generations_reconciled();
+ // Expect marking to be completed for the old generation before we fill in unmarked objects
+ assert(heap->old_generation()->is_mark_complete(), "sanity");
+ assert(is_old(), "Only need to coalesce and fill old regions");
// All objects above TAMS are considered live even though their mark bits will not be set. Note that young-
// gen evacuations that interrupt a long-running old-gen concurrent mark may promote objects into old-gen
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahMark.cpp b/src/hotspot/share/gc/shenandoah/shenandoahMark.cpp
index 2a4149ee44dc..a3c28e2c6d37 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahMark.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahMark.cpp
@@ -55,10 +55,10 @@ ShenandoahMark::ShenandoahMark(ShenandoahGeneration* generation) :
}
template
-void ShenandoahMark::mark_loop_prework(uint w, TaskTerminator *t, ShenandoahReferenceProcessor *rp, StringDedup::Requests* const req, bool update_refs) {
+void ShenandoahMark::mark_loop_prework(uint w, TaskTerminator *t, StringDedup::Requests* const req, bool update_refs) {
ShenandoahObjToScanQueue* q = get_queue(w);
ShenandoahObjToScanQueue* old_q = get_old_queue(w);
-
+ ShenandoahReferenceProcessor *rp = _generation->ref_processor();
ShenandoahHeap* const heap = ShenandoahHeap::heap();
ShenandoahLiveData* ld = heap->get_liveness_cache(w);
@@ -78,22 +78,22 @@ void ShenandoahMark::mark_loop_prework(uint w, TaskTerminator *t, ShenandoahRefe
}
template
-void ShenandoahMark::mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahReferenceProcessor *rp,
- ShenandoahGenerationType generation, StringDedup::Requests* const req) {
+void ShenandoahMark::mark_loop(uint worker_id, TaskTerminator* terminator,
+ ShenandoahGenerationType generation_type, StringDedup::Requests* const req) {
bool update_refs = ShenandoahHeap::heap()->has_forwarded_objects();
- switch (generation) {
+ switch (generation_type) {
case YOUNG:
- mark_loop_prework(worker_id, terminator, rp, req, update_refs);
+ mark_loop_prework(worker_id, terminator, req, update_refs);
break;
case OLD:
// Old generation collection only performs marking, it should not update references.
- mark_loop_prework(worker_id, terminator, rp, req, false);
+ mark_loop_prework(worker_id, terminator, req, false);
break;
case GLOBAL:
- mark_loop_prework(worker_id, terminator, rp, req, update_refs);
+ mark_loop_prework(worker_id, terminator, req, update_refs);
break;
case NON_GEN:
- mark_loop_prework(worker_id, terminator, rp, req, update_refs);
+ mark_loop_prework(worker_id, terminator, req, update_refs);
break;
default:
ShouldNotReachHere();
@@ -101,30 +101,30 @@ void ShenandoahMark::mark_loop(uint worker_id, TaskTerminator* terminator, Shena
}
}
-void ShenandoahMark::mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahReferenceProcessor *rp,
- ShenandoahGenerationType generation, bool cancellable, StringDedupMode dedup_mode, StringDedup::Requests* const req) {
+void ShenandoahMark::mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahGenerationType generation_type,
+ bool cancellable, StringDedupMode dedup_mode, StringDedup::Requests* const req) {
if (cancellable) {
switch(dedup_mode) {
case NO_DEDUP:
- mark_loop(worker_id, terminator, rp, generation, req);
+ mark_loop(worker_id, terminator, generation_type, req);
break;
case ENQUEUE_DEDUP:
- mark_loop(worker_id, terminator, rp, generation, req);
+ mark_loop(worker_id, terminator, generation_type, req);
break;
case ALWAYS_DEDUP:
- mark_loop(worker_id, terminator, rp, generation, req);
+ mark_loop(worker_id, terminator, generation_type, req);
break;
}
} else {
switch(dedup_mode) {
case NO_DEDUP:
- mark_loop(worker_id, terminator, rp, generation, req);
+ mark_loop(worker_id, terminator, generation_type, req);
break;
case ENQUEUE_DEDUP:
- mark_loop(worker_id, terminator, rp, generation, req);
+ mark_loop(worker_id, terminator, generation_type, req);
break;
case ALWAYS_DEDUP:
- mark_loop(worker_id, terminator, rp, generation, req);
+ mark_loop(worker_id, terminator, generation_type, req);
break;
}
}
@@ -139,12 +139,8 @@ void ShenandoahMark::mark_loop_work(T* cl, ShenandoahLiveData* live_data, uint w
ShenandoahObjToScanQueue* q;
ShenandoahMarkTask t;
- // Do not use active_generation() : we must use the gc_generation() set by
- // ShenandoahGCScope on the ControllerThread's stack; no safepoint may
- // intervene to update active_generation, so we can't
- // shenandoah_assert_generations_reconciled() here.
- assert(heap->gc_generation()->type() == GENERATION, "Sanity: %d != %d", heap->gc_generation()->type(), GENERATION);
- heap->gc_generation()->ref_processor()->set_mark_closure(worker_id, cl);
+ assert(_generation->type() == GENERATION, "Sanity: %d != %d", _generation->type(), GENERATION);
+ _generation->ref_processor()->set_mark_closure(worker_id, cl);
/*
* Process outstanding queues, if any.
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahMark.hpp b/src/hotspot/share/gc/shenandoah/shenandoahMark.hpp
index d4e8d23ef0f8..951779a2ab6a 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahMark.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahMark.hpp
@@ -41,7 +41,6 @@ enum StringDedupMode {
};
class ShenandoahMarkingContext;
-class ShenandoahReferenceProcessor;
// Base class for mark
// Mark class does not maintain states. Instead, mark states are
@@ -72,7 +71,7 @@ class ShenandoahMark: public StackObj {
inline ShenandoahObjToScanQueue* get_queue(uint index) const;
inline ShenandoahObjToScanQueue* get_old_queue(uint index) const;
- inline ShenandoahGeneration* generation() { return _generation; };
+ ShenandoahGeneration* generation() const { return _generation; };
private:
// ---------- Marking loop and tasks
@@ -93,7 +92,7 @@ class ShenandoahMark: public StackObj {
void mark_loop_work(T* cl, ShenandoahLiveData* live_data, uint worker_id, TaskTerminator *t, StringDedup::Requests* const req);
template
- void mark_loop_prework(uint worker_id, TaskTerminator *terminator, ShenandoahReferenceProcessor *rp, StringDedup::Requests* const req, bool update_refs);
+ void mark_loop_prework(uint worker_id, TaskTerminator *terminator, StringDedup::Requests* const req, bool update_refs);
template
static bool in_generation(ShenandoahHeap* const heap, oop obj);
@@ -109,11 +108,11 @@ class ShenandoahMark: public StackObj {
inline void dedup_string(oop obj, StringDedup::Requests* const req);
protected:
template
- void mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahReferenceProcessor *rp,
- ShenandoahGenerationType generation, StringDedup::Requests* const req);
+ void mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahGenerationType generation_type,
+ StringDedup::Requests* const req);
- void mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahReferenceProcessor *rp,
- ShenandoahGenerationType generation, bool cancellable, StringDedupMode dedup_mode, StringDedup::Requests* const req);
+ void mark_loop(uint worker_id, TaskTerminator* terminator, ShenandoahGenerationType generation_type,
+ bool cancellable, StringDedupMode dedup_mode, StringDedup::Requests* const req);
};
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHMARK_HPP
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahOldGC.cpp b/src/hotspot/share/gc/shenandoah/shenandoahOldGC.cpp
index 707c2690b581..d980a9e3e0c2 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahOldGC.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahOldGC.cpp
@@ -49,7 +49,7 @@ void ShenandoahOldGC::op_final_mark() {
assert(!heap->has_forwarded_objects(), "No forwarded objects on this path");
if (ShenandoahVerify) {
- heap->verifier()->verify_roots_no_forwarded();
+ heap->verifier()->verify_roots_no_forwarded(_old_generation);
}
if (!heap->cancelled_gc()) {
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahOldGeneration.cpp b/src/hotspot/share/gc/shenandoah/shenandoahOldGeneration.cpp
index 0d5a13fa5471..6efc1e9d01ac 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahOldGeneration.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahOldGeneration.cpp
@@ -496,7 +496,7 @@ void ShenandoahOldGeneration::prepare_regions_and_collection_set(bool concurrent
ShenandoahFinalMarkUpdateRegionStateClosure cl(complete_marking_context());
parallel_heap_region_iterate(&cl);
- heap->assert_pinned_region_status();
+ heap->assert_pinned_region_status(this);
}
{
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp
index 2bbce179af8d..3a20009efc38 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp
@@ -221,13 +221,13 @@ void ShenandoahRefProcThreadLocal::set_discovered_list_head(oop head) {
*discovered_list_addr() = head;
}
-ShenandoahReferenceProcessor::ShenandoahReferenceProcessor(uint max_workers) :
+ShenandoahReferenceProcessor::ShenandoahReferenceProcessor(ShenandoahGeneration* generation, uint max_workers) :
_soft_reference_policy(nullptr),
_ref_proc_thread_locals(NEW_C_HEAP_ARRAY(ShenandoahRefProcThreadLocal, max_workers, mtGC)),
_pending_list(nullptr),
_pending_list_tail(&_pending_list),
_iterate_discovered_list_id(0U),
- _stats() {
+ _generation(generation) {
for (size_t i = 0; i < max_workers; i++) {
_ref_proc_thread_locals[i].reset();
}
@@ -310,7 +310,7 @@ bool ShenandoahReferenceProcessor::should_discover(oop reference, ReferenceType
return false;
}
- if (!heap->is_in_active_generation(referent)) {
+ if (!_generation->contains(referent)) {
log_trace(gc,ref)("Referent outside of active generation: " PTR_FORMAT, p2i(referent));
return false;
}
@@ -328,13 +328,11 @@ bool ShenandoahReferenceProcessor::should_drop(oop reference, ReferenceType type
return true;
}
- ShenandoahHeap* heap = ShenandoahHeap::heap();
- // Check if the referent is still alive, in which case we should
- // drop the reference.
+ // Check if the referent is still alive, in which case we should drop the reference.
if (type == REF_PHANTOM) {
- return heap->active_generation()->complete_marking_context()->is_marked(raw_referent);
+ return _generation->complete_marking_context()->is_marked(raw_referent);
} else {
- return heap->active_generation()->complete_marking_context()->is_marked_strong(raw_referent);
+ return _generation->complete_marking_context()->is_marked_strong(raw_referent);
}
}
@@ -346,7 +344,7 @@ void ShenandoahReferenceProcessor::make_inactive(oop reference, ReferenceType ty
// next field. An application can't call FinalReference.enqueue(), so there is
// no race to worry about when setting the next field.
assert(reference_next(reference) == nullptr, "Already inactive");
- assert(ShenandoahHeap::heap()->active_generation()->complete_marking_context()->is_marked(reference_referent_raw(reference)), "only make inactive final refs with alive referents");
+ assert(_generation->complete_marking_context()->is_marked(reference_referent_raw(reference)), "only make inactive final refs with alive referents");
reference_set_next(reference, reference);
} else {
// Clear referent
@@ -436,7 +434,7 @@ oop ShenandoahReferenceProcessor::drop(oop reference, ReferenceType type) {
HeapWord* raw_referent = reference_referent_raw(reference);
#ifdef ASSERT
- assert(raw_referent == nullptr || ShenandoahHeap::heap()->active_generation()->complete_marking_context()->is_marked(raw_referent),
+ assert(raw_referent == nullptr || _generation->complete_marking_context()->is_marked(raw_referent),
"only drop references with alive referents");
#endif
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp
index 682c42687545..f407e6cc9f1f 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp
@@ -138,6 +138,8 @@ class ShenandoahReferenceProcessor : public ReferenceDiscoverer {
ReferenceProcessorStats _stats;
+ ShenandoahGeneration* _generation;
+
template
bool is_inactive(oop reference, oop referent, ReferenceType type) const;
bool is_strongly_live(oop referent) const;
@@ -170,7 +172,7 @@ class ShenandoahReferenceProcessor : public ReferenceDiscoverer {
void clean_discovered_list(T* list);
public:
- ShenandoahReferenceProcessor(uint max_workers);
+ ShenandoahReferenceProcessor(ShenandoahGeneration* generation, uint max_workers);
void reset_thread_locals();
void set_mark_closure(uint worker_id, ShenandoahMarkRefsSuperClosure* mark_closure);
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp b/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp
index 11ff92cd9ccf..23edc780e474 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.cpp
@@ -61,7 +61,7 @@ ShenandoahGCStateResetter::~ShenandoahGCStateResetter() {
assert(_heap->gc_state() == _saved_gc_state, "Should be restored");
}
-void ShenandoahRootVerifier::roots_do(OopIterateClosure* oops) {
+void ShenandoahRootVerifier::roots_do(OopIterateClosure* oops, ShenandoahGeneration* generation) {
ShenandoahGCStateResetter resetter;
shenandoah_assert_safepoint();
@@ -75,9 +75,9 @@ void ShenandoahRootVerifier::roots_do(OopIterateClosure* oops) {
OopStorageSet::storage(id)->oops_do(oops);
}
- ShenandoahHeap* heap = ShenandoahHeap::heap();
- if (heap->mode()->is_generational() && heap->active_generation()->is_young()) {
+ if (generation->is_young()) {
shenandoah_assert_safepoint();
+ shenandoah_assert_generational();
ShenandoahGenerationalHeap::heap()->old_generation()->card_scan()->roots_do(oops);
}
@@ -87,7 +87,7 @@ void ShenandoahRootVerifier::roots_do(OopIterateClosure* oops) {
Threads::possibly_parallel_oops_do(true, oops, nullptr);
}
-void ShenandoahRootVerifier::strong_roots_do(OopIterateClosure* oops) {
+void ShenandoahRootVerifier::strong_roots_do(OopIterateClosure* oops, ShenandoahGeneration* generation) {
ShenandoahGCStateResetter resetter;
shenandoah_assert_safepoint();
@@ -98,8 +98,8 @@ void ShenandoahRootVerifier::strong_roots_do(OopIterateClosure* oops) {
OopStorageSet::storage(id)->oops_do(oops);
}
- ShenandoahHeap* heap = ShenandoahHeap::heap();
- if (heap->mode()->is_generational() && heap->active_generation()->is_young()) {
+ if (generation->is_young()) {
+ shenandoah_assert_generational();
ShenandoahGenerationalHeap::heap()->old_generation()->card_scan()->roots_do(oops);
}
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.hpp b/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.hpp
index 405c69c4160e..1f3cb4004657 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRootVerifier.hpp
@@ -43,8 +43,10 @@ class ShenandoahGCStateResetter : public StackObj {
class ShenandoahRootVerifier : public AllStatic {
public:
// Used to seed ShenandoahVerifier, do not honor root type filter
- static void roots_do(OopIterateClosure* cl);
- static void strong_roots_do(OopIterateClosure* cl);
+ // The generation parameter here may be young or global. If it is young,
+ // then the roots will include the remembered set.
+ static void roots_do(OopIterateClosure* cl, ShenandoahGeneration* generation);
+ static void strong_roots_do(OopIterateClosure* cl, ShenandoahGeneration* generation);
};
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHROOTVERIFIER_HPP
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahSTWMark.cpp b/src/hotspot/share/gc/shenandoah/shenandoahSTWMark.cpp
index 365165546dfc..7abdd92f844a 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahSTWMark.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahSTWMark.cpp
@@ -73,16 +73,14 @@ void ShenandoahSTWMark::mark() {
ShenandoahCodeRoots::arm_nmethods();
// Weak reference processing
- assert(ShenandoahHeap::heap()->gc_generation() == _generation, "Marking unexpected generation");
ShenandoahReferenceProcessor* rp = _generation->ref_processor();
- shenandoah_assert_generations_reconciled();
rp->reset_thread_locals();
rp->set_soft_reference_policy(heap->soft_ref_policy()->should_clear_all_soft_refs());
// Init mark, do not expect forwarded pointers in roots
if (ShenandoahVerify) {
assert(Thread::current()->is_VM_thread(), "Must be");
- heap->verifier()->verify_roots_no_forwarded();
+ heap->verifier()->verify_roots_no_forwarded(_generation);
}
start_mark();
@@ -117,7 +115,6 @@ void ShenandoahSTWMark::mark() {
}
void ShenandoahSTWMark::mark_roots(uint worker_id) {
- assert(ShenandoahHeap::heap()->gc_generation() == _generation, "Marking unexpected generation");
ShenandoahReferenceProcessor* rp = _generation->ref_processor();
auto queue = task_queues()->queue(worker_id);
switch (_generation->type()) {
@@ -146,14 +143,10 @@ void ShenandoahSTWMark::mark_roots(uint worker_id) {
}
void ShenandoahSTWMark::finish_mark(uint worker_id) {
- assert(ShenandoahHeap::heap()->gc_generation() == _generation, "Marking unexpected generation");
ShenandoahPhaseTimings::Phase phase = _full_gc ? ShenandoahPhaseTimings::full_gc_mark : ShenandoahPhaseTimings::degen_gc_stw_mark;
ShenandoahWorkerTimingsTracker timer(phase, ShenandoahPhaseTimings::ParallelMark, worker_id);
- ShenandoahReferenceProcessor* rp = _generation->ref_processor();
- shenandoah_assert_generations_reconciled();
StringDedup::Requests requests;
- mark_loop(worker_id, &_terminator, rp,
- _generation->type(), false /* not cancellable */,
+ mark_loop(worker_id, &_terminator, _generation->type(), false /* not cancellable */,
ShenandoahStringDedup::is_enabled() ? ALWAYS_DEDUP : NO_DEDUP, &requests);
}
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp
index 0137492f06f8..6b45842f7817 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.cpp
@@ -50,16 +50,14 @@ void VM_ShenandoahOperation::doit_epilogue() {
void VM_ShenandoahOperation::log_active_generation(const char* prefix) {
ShenandoahGeneration* agen = ShenandoahHeap::heap()->active_generation();
- ShenandoahGeneration* ggen = ShenandoahHeap::heap()->gc_generation();
- log_debug(gc, heap)("%s: active_generation is %s, gc_generation is %s", prefix,
- agen == nullptr ? "nullptr" : shenandoah_generation_name(agen->type()),
- ggen == nullptr ? "nullptr" : shenandoah_generation_name(ggen->type()));
+ log_debug(gc, heap)("%s: active_generation is %s", prefix,
+ agen == nullptr ? "nullptr" : shenandoah_generation_name(agen->type()));
}
void VM_ShenandoahOperation::set_active_generation() {
if (evaluate_at_safepoint()) {
assert(SafepointSynchronize::is_at_safepoint(), "Error??");
- ShenandoahHeap::heap()->set_active_generation();
+ ShenandoahHeap::heap()->set_active_generation(_generation);
}
}
@@ -77,42 +75,70 @@ void VM_ShenandoahReferenceOperation::doit_epilogue() {
Heap_lock->unlock();
}
+VM_ShenandoahInitMark::VM_ShenandoahInitMark(ShenandoahConcurrentGC* gc)
+ : VM_ShenandoahOperation(gc->generation()), _gc(gc) {
+}
+
void VM_ShenandoahInitMark::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Init Mark", SvcGCMarker::CONCURRENT);
set_active_generation();
_gc->entry_init_mark();
}
+VM_ShenandoahFinalMarkStartEvac::VM_ShenandoahFinalMarkStartEvac(ShenandoahConcurrentGC* gc)
+ : VM_ShenandoahOperation(gc->generation()), _gc(gc) {
+}
+
void VM_ShenandoahFinalMarkStartEvac::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Final Mark", SvcGCMarker::CONCURRENT);
set_active_generation();
_gc->entry_final_mark();
}
+VM_ShenandoahFullGC::VM_ShenandoahFullGC(GCCause::Cause gc_cause, ShenandoahFullGC* full_gc)
+ : VM_ShenandoahReferenceOperation(full_gc->generation()), _gc_cause(gc_cause), _full_gc(full_gc) {
+}
+
void VM_ShenandoahFullGC::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Full GC", SvcGCMarker::FULL);
set_active_generation();
_full_gc->entry_full(_gc_cause);
}
+VM_ShenandoahDegeneratedGC::VM_ShenandoahDegeneratedGC(ShenandoahDegenGC* gc)
+ : VM_ShenandoahReferenceOperation(gc->generation()), _gc(gc) {
+}
+
void VM_ShenandoahDegeneratedGC::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Degenerated GC", SvcGCMarker::CONCURRENT);
set_active_generation();
_gc->entry_degenerated();
}
+VM_ShenandoahInitUpdateRefs::VM_ShenandoahInitUpdateRefs(ShenandoahConcurrentGC* gc)
+ : VM_ShenandoahOperation(gc->generation()), _gc(gc) {
+}
+
void VM_ShenandoahInitUpdateRefs::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Init Update Refs", SvcGCMarker::CONCURRENT);
set_active_generation();
_gc->entry_init_update_refs();
}
+VM_ShenandoahFinalUpdateRefs::VM_ShenandoahFinalUpdateRefs(ShenandoahConcurrentGC* gc)
+ : VM_ShenandoahOperation(gc->generation()), _gc(gc) {
+}
+
void VM_ShenandoahFinalUpdateRefs::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Final Update Refs", SvcGCMarker::CONCURRENT);
set_active_generation();
_gc->entry_final_update_refs();
}
+VM_ShenandoahFinalRoots::VM_ShenandoahFinalRoots(ShenandoahConcurrentGC* gc)
+ : VM_ShenandoahOperation(gc->generation()), _gc(gc) {
+}
+
void VM_ShenandoahFinalRoots::doit() {
ShenandoahGCPauseMark mark(_gc_id, "Final Roots", SvcGCMarker::CONCURRENT);
set_active_generation();
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp
index 09971bb26302..986696fefa14 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVMOperations.hpp
@@ -46,10 +46,15 @@ class ShenandoahFullGC;
class VM_ShenandoahOperation : public VM_Operation {
protected:
uint _gc_id;
+ ShenandoahGeneration* _generation;
void set_active_generation();
public:
- VM_ShenandoahOperation() : _gc_id(GCId::current()) {};
+ explicit VM_ShenandoahOperation(ShenandoahGeneration* generation)
+ : _gc_id(GCId::current())
+ , _generation(generation) {
+ }
+
bool skip_thread_oop_barriers() const override { return true; }
void log_active_generation(const char* prefix);
@@ -59,93 +64,74 @@ class VM_ShenandoahOperation : public VM_Operation {
class VM_ShenandoahReferenceOperation : public VM_ShenandoahOperation {
public:
- VM_ShenandoahReferenceOperation() : VM_ShenandoahOperation() {};
+ explicit VM_ShenandoahReferenceOperation(ShenandoahGeneration* generation)
+ : VM_ShenandoahOperation(generation) {};
bool doit_prologue() override;
void doit_epilogue() override;
};
class VM_ShenandoahInitMark: public VM_ShenandoahOperation {
-private:
ShenandoahConcurrentGC* const _gc;
public:
- VM_ShenandoahInitMark(ShenandoahConcurrentGC* gc) :
- VM_ShenandoahOperation(),
- _gc(gc) {};
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahInitMark; }
- const char* name() const { return "Shenandoah Init Marking"; }
- virtual void doit();
+ explicit VM_ShenandoahInitMark(ShenandoahConcurrentGC* gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahInitMark; }
+ const char* name() const override { return "Shenandoah Init Marking"; }
+ void doit() override;
};
class VM_ShenandoahFinalMarkStartEvac: public VM_ShenandoahOperation {
-private:
ShenandoahConcurrentGC* const _gc;
public:
- VM_ShenandoahFinalMarkStartEvac(ShenandoahConcurrentGC* gc) :
- VM_ShenandoahOperation(),
- _gc(gc) {};
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahFinalMarkStartEvac; }
- const char* name() const { return "Shenandoah Final Mark and Start Evacuation"; }
- virtual void doit();
+ explicit VM_ShenandoahFinalMarkStartEvac(ShenandoahConcurrentGC* gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahFinalMarkStartEvac; }
+ const char* name() const override { return "Shenandoah Final Mark and Start Evacuation"; }
+ void doit() override;
};
class VM_ShenandoahDegeneratedGC: public VM_ShenandoahReferenceOperation {
-private:
ShenandoahDegenGC* const _gc;
public:
- VM_ShenandoahDegeneratedGC(ShenandoahDegenGC* gc) :
- VM_ShenandoahReferenceOperation(),
- _gc(gc) {};
-
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahDegeneratedGC; }
- const char* name() const { return "Shenandoah Degenerated GC"; }
- virtual void doit();
+ explicit VM_ShenandoahDegeneratedGC(ShenandoahDegenGC* gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahDegeneratedGC; }
+ const char* name() const override { return "Shenandoah Degenerated GC"; }
+ void doit() override;
};
class VM_ShenandoahFullGC : public VM_ShenandoahReferenceOperation {
-private:
GCCause::Cause _gc_cause;
ShenandoahFullGC* const _full_gc;
public:
- VM_ShenandoahFullGC(GCCause::Cause gc_cause, ShenandoahFullGC* full_gc) :
- VM_ShenandoahReferenceOperation(),
- _gc_cause(gc_cause),
- _full_gc(full_gc) {};
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahFullGC; }
- const char* name() const { return "Shenandoah Full GC"; }
- virtual void doit();
+ explicit VM_ShenandoahFullGC(GCCause::Cause gc_cause, ShenandoahFullGC* full_gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahFullGC; }
+ const char* name() const override { return "Shenandoah Full GC"; }
+ void doit() override;
};
class VM_ShenandoahInitUpdateRefs: public VM_ShenandoahOperation {
ShenandoahConcurrentGC* const _gc;
public:
- VM_ShenandoahInitUpdateRefs(ShenandoahConcurrentGC* gc) :
- VM_ShenandoahOperation(),
- _gc(gc) {};
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahInitUpdateRefs; }
- const char* name() const { return "Shenandoah Init Update References"; }
- virtual void doit();
+ explicit VM_ShenandoahInitUpdateRefs(ShenandoahConcurrentGC* gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahInitUpdateRefs; }
+ const char* name() const override { return "Shenandoah Init Update References"; }
+ void doit() override;
};
class VM_ShenandoahFinalUpdateRefs: public VM_ShenandoahOperation {
ShenandoahConcurrentGC* const _gc;
public:
- VM_ShenandoahFinalUpdateRefs(ShenandoahConcurrentGC* gc) :
- VM_ShenandoahOperation(),
- _gc(gc) {};
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahFinalUpdateRefs; }
- const char* name() const { return "Shenandoah Final Update References"; }
- virtual void doit();
+ explicit VM_ShenandoahFinalUpdateRefs(ShenandoahConcurrentGC* gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahFinalUpdateRefs; }
+ const char* name() const override { return "Shenandoah Final Update References"; }
+ void doit() override;
};
class VM_ShenandoahFinalRoots: public VM_ShenandoahOperation {
ShenandoahConcurrentGC* const _gc;
public:
- VM_ShenandoahFinalRoots(ShenandoahConcurrentGC* gc) :
- VM_ShenandoahOperation(),
- _gc(gc) {};
- VM_Operation::VMOp_Type type() const { return VMOp_ShenandoahFinalRoots; }
- const char* name() const { return "Shenandoah Final Roots"; }
- virtual void doit();
+ explicit VM_ShenandoahFinalRoots(ShenandoahConcurrentGC* gc);
+ VM_Operation::VMOp_Type type() const override { return VMOp_ShenandoahFinalRoots; }
+ const char* name() const override { return "Shenandoah Final Roots"; }
+ void doit() override;
};
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHVMOPERATIONS_HPP
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
index 0644f7b0e0a8..94875635b469 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
@@ -70,7 +70,8 @@ class ShenandoahVerifyOopClosure : public BasicOopIterateClosure {
ShenandoahGeneration* _generation;
public:
- ShenandoahVerifyOopClosure(ShenandoahVerifierStack* stack, MarkBitMap* map, ShenandoahLivenessData* ld,
+ ShenandoahVerifyOopClosure(ShenandoahGeneration* generation, ShenandoahVerifierStack* stack,
+ MarkBitMap* map, ShenandoahLivenessData* ld,
const char* phase, ShenandoahVerifier::VerifyOptions options) :
_phase(phase),
_options(options),
@@ -80,7 +81,7 @@ class ShenandoahVerifyOopClosure : public BasicOopIterateClosure {
_ld(ld),
_interior_loc(nullptr),
_loc(nullptr),
- _generation(nullptr) {
+ _generation(generation) {
if (options._verify_marked == ShenandoahVerifier::_verify_marked_complete_except_references ||
options._verify_marked == ShenandoahVerifier::_verify_marked_complete_satb_empty ||
options._verify_marked == ShenandoahVerifier::_verify_marked_disable) {
@@ -92,12 +93,6 @@ class ShenandoahVerifyOopClosure : public BasicOopIterateClosure {
// Otherwise do all fields.
_ref_mode = DO_FIELDS;
}
-
- if (_heap->mode()->is_generational()) {
- _generation = _heap->gc_generation();
- assert(_generation != nullptr, "Expected active generation in this mode");
- shenandoah_assert_generations_reconciled();
- }
}
ReferenceIterationMode reference_iteration_mode() override {
@@ -131,11 +126,7 @@ class ShenandoahVerifyOopClosure : public BasicOopIterateClosure {
}
}
- bool in_generation(oop obj) {
- if (_generation == nullptr) {
- return true;
- }
-
+ bool in_generation(oop obj) const {
ShenandoahHeapRegion* region = _heap->heap_region_containing(obj);
return _generation->contains(region);
}
@@ -195,9 +186,8 @@ class ShenandoahVerifyOopClosure : public BasicOopIterateClosure {
// fallthrough for fast failure for un-live regions:
case ShenandoahVerifier::_verify_liveness_conservative:
check(ShenandoahAsserts::_safe_oop, obj, obj_reg->has_live() ||
- (obj_reg->is_old() && _heap->gc_generation()->is_young()),
+ (obj_reg->is_old() && _generation->is_young()),
"Object must belong to region with live data");
- shenandoah_assert_generations_reconciled();
break;
default:
assert(false, "Unhandled liveness verification");
@@ -272,12 +262,12 @@ class ShenandoahVerifyOopClosure : public BasicOopIterateClosure {
"Must be marked in incomplete bitmap");
break;
case ShenandoahVerifier::_verify_marked_complete:
- check(ShenandoahAsserts::_safe_all, obj, _heap->gc_generation()->complete_marking_context()->is_marked(obj),
+ check(ShenandoahAsserts::_safe_all, obj, _generation->complete_marking_context()->is_marked(obj),
"Must be marked in complete bitmap");
break;
case ShenandoahVerifier::_verify_marked_complete_except_references:
case ShenandoahVerifier::_verify_marked_complete_satb_empty:
- check(ShenandoahAsserts::_safe_all, obj, _heap->gc_generation()->complete_marking_context()->is_marked(obj),
+ check(ShenandoahAsserts::_safe_all, obj, _generation->complete_marking_context()->is_marked(obj),
"Must be marked in complete bitmap, except j.l.r.Reference referents");
break;
default:
@@ -579,9 +569,11 @@ class ShenandoahVerifierReachableTask : public WorkerTask {
ShenandoahLivenessData* _ld;
MarkBitMap* _bitmap;
volatile size_t _processed;
+ ShenandoahGeneration* _generation;
public:
- ShenandoahVerifierReachableTask(MarkBitMap* bitmap,
+ ShenandoahVerifierReachableTask(ShenandoahGeneration* generation,
+ MarkBitMap* bitmap,
ShenandoahLivenessData* ld,
const char* label,
ShenandoahVerifier::VerifyOptions options) :
@@ -591,7 +583,8 @@ class ShenandoahVerifierReachableTask : public WorkerTask {
_heap(ShenandoahHeap::heap()),
_ld(ld),
_bitmap(bitmap),
- _processed(0) {};
+ _processed(0),
+ _generation(generation) {};
size_t processed() const {
return _processed;
@@ -607,20 +600,20 @@ class ShenandoahVerifierReachableTask : public WorkerTask {
// extended parallelism would buy us out.
if (((ShenandoahVerifyLevel == 2) && (worker_id == 0))
|| (ShenandoahVerifyLevel >= 3)) {
- ShenandoahVerifyOopClosure cl(&stack, _bitmap, _ld,
+ ShenandoahVerifyOopClosure cl(_generation, &stack, _bitmap, _ld,
ShenandoahMessageBuffer("%s, Roots", _label),
_options);
if (_heap->unload_classes()) {
- ShenandoahRootVerifier::strong_roots_do(&cl);
+ ShenandoahRootVerifier::strong_roots_do(&cl, _generation);
} else {
- ShenandoahRootVerifier::roots_do(&cl);
+ ShenandoahRootVerifier::roots_do(&cl, _generation);
}
}
size_t processed = 0;
if (ShenandoahVerifyLevel >= 3) {
- ShenandoahVerifyOopClosure cl(&stack, _bitmap, _ld,
+ ShenandoahVerifyOopClosure cl(_generation, &stack, _bitmap, _ld,
ShenandoahMessageBuffer("%s, Reachable", _label),
_options);
while (!stack.is_empty()) {
@@ -656,7 +649,8 @@ class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
ShenandoahGeneration* _generation;
public:
- ShenandoahVerifierMarkedRegionTask(MarkBitMap* bitmap,
+ ShenandoahVerifierMarkedRegionTask(ShenandoahGeneration* generation,
+ MarkBitMap* bitmap,
ShenandoahLivenessData* ld,
const char* label,
ShenandoahVerifier::VerifyOptions options) :
@@ -668,13 +662,7 @@ class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
_ld(ld),
_claimed(0),
_processed(0),
- _generation(nullptr) {
- if (_heap->mode()->is_generational()) {
- _generation = _heap->gc_generation();
- assert(_generation != nullptr, "Expected active generation in this mode.");
- shenandoah_assert_generations_reconciled();
- }
- };
+ _generation(generation) {}
size_t processed() {
return Atomic::load(&_processed);
@@ -687,7 +675,7 @@ class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
}
ShenandoahVerifierStack stack;
- ShenandoahVerifyOopClosure cl(&stack, _bitmap, _ld,
+ ShenandoahVerifyOopClosure cl(_generation, &stack, _bitmap, _ld,
ShenandoahMessageBuffer("%s, Marked", _label),
_options);
@@ -710,14 +698,14 @@ class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
}
}
- bool in_generation(ShenandoahHeapRegion* r) {
- return _generation == nullptr || _generation->contains(r);
+ bool in_generation(ShenandoahHeapRegion* r) const {
+ return _generation->contains(r);
}
virtual void work_humongous(ShenandoahHeapRegion *r, ShenandoahVerifierStack& stack, ShenandoahVerifyOopClosure& cl) {
size_t processed = 0;
HeapWord* obj = r->bottom();
- if (_heap->gc_generation()->complete_marking_context()->is_marked(cast_to_oop(obj))) {
+ if (_generation->complete_marking_context()->is_marked(cast_to_oop(obj))) {
verify_and_follow(obj, stack, cl, &processed);
}
Atomic::add(&_processed, processed, memory_order_relaxed);
@@ -725,7 +713,7 @@ class ShenandoahVerifierMarkedRegionTask : public WorkerTask {
virtual void work_regular(ShenandoahHeapRegion *r, ShenandoahVerifierStack &stack, ShenandoahVerifyOopClosure &cl) {
size_t processed = 0;
- ShenandoahMarkingContext* ctx = _heap->gc_generation()->complete_marking_context();
+ ShenandoahMarkingContext* ctx = _generation->complete_marking_context();
HeapWord* tams = ctx->top_at_mark_start(r);
// Bitmaps, before TAMS
@@ -802,7 +790,8 @@ class VerifyThreadGCState : public ThreadClosure {
}
};
-void ShenandoahVerifier::verify_at_safepoint(const char* label,
+void ShenandoahVerifier::verify_at_safepoint(ShenandoahGeneration* generation,
+ const char* label,
VerifyRememberedSet remembered,
VerifyForwarded forwarded,
VerifyMarked marked,
@@ -904,16 +893,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char* label,
log_debug(gc)("Safepoint verification finished heap usage verification");
- ShenandoahGeneration* generation;
if (_heap->mode()->is_generational()) {
- generation = _heap->gc_generation();
- guarantee(generation != nullptr, "Need to know which generation to verify.");
- shenandoah_assert_generations_reconciled();
- } else {
- generation = nullptr;
- }
-
- if (generation != nullptr) {
ShenandoahHeapLocker lock(_heap->lock());
switch (remembered) {
@@ -960,11 +940,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char* label,
// Internal heap region checks
if (ShenandoahVerifyLevel >= 1) {
ShenandoahVerifyHeapRegionClosure cl(label, regions);
- if (generation != nullptr) {
- generation->heap_region_iterate(&cl);
- } else {
- _heap->heap_region_iterate(&cl);
- }
+ generation->heap_region_iterate(&cl);
}
log_debug(gc)("Safepoint verification finished heap region closure verification");
@@ -988,7 +964,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char* label,
// This verifies what application can see, since it only cares about reachable objects.
size_t count_reachable = 0;
if (ShenandoahVerifyLevel >= 2) {
- ShenandoahVerifierReachableTask task(_verification_bit_map, ld, label, options);
+ ShenandoahVerifierReachableTask task(generation, _verification_bit_map, ld, label, options);
_heap->workers()->run_task(&task);
count_reachable = task.processed();
}
@@ -1007,8 +983,8 @@ void ShenandoahVerifier::verify_at_safepoint(const char* label,
(marked == _verify_marked_complete ||
marked == _verify_marked_complete_except_references ||
marked == _verify_marked_complete_satb_empty)) {
- guarantee(_heap->gc_generation()->is_mark_complete(), "Marking context should be complete");
- ShenandoahVerifierMarkedRegionTask task(_verification_bit_map, ld, label, options);
+ guarantee(generation->is_mark_complete(), "Marking context should be complete");
+ ShenandoahVerifierMarkedRegionTask task(generation, _verification_bit_map, ld, label, options);
_heap->workers()->run_task(&task);
count_marked = task.processed();
} else {
@@ -1023,7 +999,7 @@ void ShenandoahVerifier::verify_at_safepoint(const char* label,
if (ShenandoahVerifyLevel >= 4 && marked == _verify_marked_complete && liveness == _verify_liveness_complete) {
for (size_t i = 0; i < _heap->num_regions(); i++) {
ShenandoahHeapRegion* r = _heap->get_region(i);
- if (generation != nullptr && !generation->contains(r)) {
+ if (!generation->contains(r)) {
continue;
}
@@ -1050,16 +1026,15 @@ void ShenandoahVerifier::verify_at_safepoint(const char* label,
}
log_debug(gc)("Safepoint verification finished accumulation of liveness data");
-
-
log_info(gc)("Verify %s, Level %zd (%zu reachable, %zu marked)",
label, ShenandoahVerifyLevel, count_reachable, count_marked);
FREE_C_HEAP_ARRAY(ShenandoahLivenessData, ld);
}
-void ShenandoahVerifier::verify_generic(VerifyOption vo) {
+void ShenandoahVerifier::verify_generic(ShenandoahGeneration* generation, VerifyOption vo) {
verify_at_safepoint(
+ generation,
"Generic Verification",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_allow, // conservatively allow forwarded
@@ -1072,7 +1047,7 @@ void ShenandoahVerifier::verify_generic(VerifyOption vo) {
);
}
-void ShenandoahVerifier::verify_before_concmark() {
+void ShenandoahVerifier::verify_before_concmark(ShenandoahGeneration* generation) {
VerifyRememberedSet verify_remembered_set = _verify_remembered_before_marking;
if (_heap->mode()->is_generational() &&
!_heap->old_generation()->is_mark_complete()) {
@@ -1080,6 +1055,7 @@ void ShenandoahVerifier::verify_before_concmark() {
verify_remembered_set = _verify_remembered_disable;
}
verify_at_safepoint(
+ generation,
"Before Mark",
verify_remembered_set,
// verify read-only remembered set from bottom() to top()
@@ -1093,8 +1069,9 @@ void ShenandoahVerifier::verify_before_concmark() {
);
}
-void ShenandoahVerifier::verify_after_concmark() {
+void ShenandoahVerifier::verify_after_concmark(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"After Mark",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
@@ -1107,8 +1084,9 @@ void ShenandoahVerifier::verify_after_concmark() {
);
}
-void ShenandoahVerifier::verify_after_concmark_with_promotions() {
+void ShenandoahVerifier::verify_after_concmark_with_promotions(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"After Mark",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
@@ -1122,8 +1100,9 @@ void ShenandoahVerifier::verify_after_concmark_with_promotions() {
);
}
-void ShenandoahVerifier::verify_before_evacuation() {
+void ShenandoahVerifier::verify_before_evacuation(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"Before Evacuation",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
@@ -1137,13 +1116,14 @@ void ShenandoahVerifier::verify_before_evacuation() {
);
}
-void ShenandoahVerifier::verify_before_update_refs() {
+void ShenandoahVerifier::verify_before_update_refs(ShenandoahGeneration* generation) {
VerifyRememberedSet verify_remembered_set = _verify_remembered_before_updating_references;
if (_heap->mode()->is_generational() &&
!_heap->old_generation()->is_mark_complete()) {
verify_remembered_set = _verify_remembered_disable;
}
verify_at_safepoint(
+ generation,
"Before Updating References",
verify_remembered_set, // verify read-write remembered set
_verify_forwarded_allow, // forwarded references allowed
@@ -1157,8 +1137,9 @@ void ShenandoahVerifier::verify_before_update_refs() {
}
// We have not yet cleanup (reclaimed) the collection set
-void ShenandoahVerifier::verify_after_update_refs() {
+void ShenandoahVerifier::verify_after_update_refs(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"After Updating References",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // no forwarded references
@@ -1171,8 +1152,9 @@ void ShenandoahVerifier::verify_after_update_refs() {
);
}
-void ShenandoahVerifier::verify_after_degenerated() {
+void ShenandoahVerifier::verify_after_degenerated(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"After Degenerated GC",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_none, // all objects are non-forwarded
@@ -1185,8 +1167,9 @@ void ShenandoahVerifier::verify_after_degenerated() {
);
}
-void ShenandoahVerifier::verify_before_fullgc() {
+void ShenandoahVerifier::verify_before_fullgc(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"Before Full GC",
_verify_remembered_disable, // do not verify remembered set
_verify_forwarded_allow, // can have forwarded objects
@@ -1199,8 +1182,9 @@ void ShenandoahVerifier::verify_before_fullgc() {
);
}
-void ShenandoahVerifier::verify_after_fullgc() {
+void ShenandoahVerifier::verify_after_fullgc(ShenandoahGeneration* generation) {
verify_at_safepoint(
+ generation,
"After Full GC",
_verify_remembered_after_full_gc, // verify read-write remembered set
_verify_forwarded_none, // all objects are non-forwarded
@@ -1269,14 +1253,14 @@ class ShenandoahVerifyInToSpaceClosure : public BasicOopIterateClosure {
void do_oop(oop* p) override { do_oop_work(p); }
};
-void ShenandoahVerifier::verify_roots_in_to_space() {
+void ShenandoahVerifier::verify_roots_in_to_space(ShenandoahGeneration* generation) {
ShenandoahVerifyInToSpaceClosure cl;
- ShenandoahRootVerifier::roots_do(&cl);
+ ShenandoahRootVerifier::roots_do(&cl, generation);
}
-void ShenandoahVerifier::verify_roots_no_forwarded() {
+void ShenandoahVerifier::verify_roots_no_forwarded(ShenandoahGeneration* generation) {
ShenandoahVerifyNoForwarded cl;
- ShenandoahRootVerifier::roots_do(&cl);
+ ShenandoahRootVerifier::roots_do(&cl, generation);
}
template
@@ -1314,7 +1298,6 @@ class ShenandoahVerifyRemSetClosure : public BasicOopIterateClosure {
template
void ShenandoahVerifier::help_verify_region_rem_set(Scanner* scanner, ShenandoahHeapRegion* r,
HeapWord* registration_watermark, const char* message) {
- shenandoah_assert_generations_reconciled();
ShenandoahOldGeneration* old_gen = _heap->old_generation();
assert(old_gen->is_mark_complete() || old_gen->is_parsable(), "Sanity");
diff --git a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.hpp b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.hpp
index aba6379e0223..e49990fdc620 100644
--- a/src/hotspot/share/gc/shenandoah/shenandoahVerifier.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahVerifier.hpp
@@ -196,7 +196,8 @@ class ShenandoahVerifier : public CHeapObj {
};
private:
- void verify_at_safepoint(const char* label,
+ void verify_at_safepoint(ShenandoahGeneration* generation,
+ const char* label,
VerifyRememberedSet remembered,
VerifyForwarded forwarded,
VerifyMarked marked,
@@ -210,20 +211,20 @@ class ShenandoahVerifier : public CHeapObj {
ShenandoahVerifier(ShenandoahHeap* heap, MarkBitMap* verification_bitmap) :
_heap(heap), _verification_bit_map(verification_bitmap) {};
- void verify_before_concmark();
- void verify_after_concmark();
- void verify_after_concmark_with_promotions();
- void verify_before_evacuation();
- void verify_before_update_refs();
- void verify_after_update_refs();
- void verify_before_fullgc();
- void verify_after_fullgc();
- void verify_after_degenerated();
- void verify_generic(VerifyOption option);
+ void verify_before_concmark(ShenandoahGeneration* generation);
+ void verify_after_concmark(ShenandoahGeneration* generation);
+ void verify_after_concmark_with_promotions(ShenandoahGeneration* generation);
+ void verify_before_evacuation(ShenandoahGeneration* generation);
+ void verify_before_update_refs(ShenandoahGeneration* generation);
+ void verify_after_update_refs(ShenandoahGeneration* generation);
+ void verify_before_fullgc(ShenandoahGeneration* generation);
+ void verify_after_fullgc(ShenandoahGeneration* generation);
+ void verify_after_degenerated(ShenandoahGeneration* generation);
+ void verify_generic(ShenandoahGeneration* generation, VerifyOption option);
// Roots should only contain to-space oops
- void verify_roots_in_to_space();
- void verify_roots_no_forwarded();
+ void verify_roots_in_to_space(ShenandoahGeneration* generation);
+ void verify_roots_no_forwarded(ShenandoahGeneration* generation);
// Check that generation usages are accurate before rebuilding free set
void verify_before_rebuilding_free_set();
diff --git a/src/java.base/share/classes/java/util/ServiceLoader.java b/src/java.base/share/classes/java/util/ServiceLoader.java
index 5e4fa4ed2eff..f47bb30cd5f9 100644
--- a/src/java.base/share/classes/java/util/ServiceLoader.java
+++ b/src/java.base/share/classes/java/util/ServiceLoader.java
@@ -621,7 +621,7 @@ private Constructor> getConstructor(Class> clazz) {
Constructor> ctor = null;
try {
ctor = clazz.getConstructor();
- } catch (NoSuchMethodException | LinkageError e) {
+ } catch (Throwable e) {
String cn = clazz.getName();
fail(service, cn + " Unable to get public no-arg constructor", e);
}
@@ -1086,7 +1086,7 @@ private Class> nextProviderClass() {
String cn = pending.next();
try {
return Class.forName(cn, false, loader);
- } catch (ClassNotFoundException | LinkageError e) {
+ } catch (ClassNotFoundException e) {
fail(service, "Provider " + cn + " not found", e);
return null;
}
diff --git a/src/java.base/share/legal/zlib.md b/src/java.base/share/legal/zlib.md
index c729c4248d48..d346a4d0c986 100644
--- a/src/java.base/share/legal/zlib.md
+++ b/src/java.base/share/legal/zlib.md
@@ -1,4 +1,4 @@
-## zlib v1.3.2
+## zlib v1.4
### zlib License
diff --git a/src/java.base/share/native/libzip/zlib/ChangeLog b/src/java.base/share/native/libzip/zlib/ChangeLog
index 312753edadef..228a03afa1d7 100644
--- a/src/java.base/share/native/libzip/zlib/ChangeLog
+++ b/src/java.base/share/native/libzip/zlib/ChangeLog
@@ -1,6 +1,37 @@
ChangeLog file for zlib
+Changes in 1.4 (4 Nov 2026)
+- Change CMake library names on MSVC
+- Return z_off_t default to long for portability
+- Fail gzopen() with "x" if O_EXCL not available
+- Deliver all gzip data before reporting error
+- Fix gzwrite() buffer overflow (CVE-2026-85091)
+- Fix inflateGetDictionary() write past buffer on invalid window size
+- Fix window write overrun after inflateSync()
+- Fix read before provided data after repeated inflatePrime()'s
+- Fix write past pending buffer after repeated deflatePrime()'s
+- Fix copy of uninitialized memory by inflateBack() on invalid data
+- Fix copy of uninitialized memory after gzseek() as first write action
+- Fix read outside window after a deflateResetKeep() mid-stream
+- Avoid out-of-bounds pointer arithmetic in infback9() (CVE-2026-4738)
+- Fix several vulnerabilities in contrib/minizip
+- Fix truncated stream detection in gzread()
+- Fix pending skip handling in gzread()
+- Fix loss of zero fill on repeated gzseek()'s when writing
+- Fix inaccurate total_in after Z_NEED_DICT returned
+- Detect and report bad deflateSetDictionary() calls
+- Avoid undefined behaviors in C language usage
+- Fix minizip extra field overflows when almost full and need Zip64
+- Don't assume NULL is defined in compress.c and uncompr.c
+- Use the generated zconf.h when building test programs out of tree
+- Improve portability and functionality of CMake builds
+- Provide 64-bit file offsets on Windows with #defines as on Linux
+- Improve portability to Android, AIX, PowerPC, s390x, and Windows
+- Use a PCG random number generator instead of rand() in minizip
+- Clarify documentation
+- (See https://github.com/madler/zlib for all 195 commits)
+
Changes in 1.3.2 (17 Feb 2026)
- Continued rewrite of CMake build [Vollstrecker]
- Various portability improvements
diff --git a/src/java.base/share/native/libzip/zlib/README b/src/java.base/share/native/libzip/zlib/README
index 2b1e6f36fe3e..265c8b47d316 100644
--- a/src/java.base/share/native/libzip/zlib/README
+++ b/src/java.base/share/native/libzip/zlib/README
@@ -1,6 +1,6 @@
ZLIB DATA COMPRESSION LIBRARY
-zlib 1.3.2 is a general purpose data compression library. All the code is
+zlib 1.4 is a general purpose data compression library. All the code is
thread safe (though see the FAQ for caveats). The data format used by the zlib
library is described by RFCs (Request for Comments) 1950 to 1952 at
https://datatracker.ietf.org/doc/html/rfc1950 (zlib format), rfc1951 (deflate
@@ -31,7 +31,7 @@ Mark Nelson wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available at
https://zlib.net/nelson/ .
-The changes made in version 1.3.2 are documented in the file ChangeLog.
+The changes made in version 1.4 are documented in the file ChangeLog.
Unsupported third party contributions are provided in directory contrib/ .
diff --git a/src/java.base/share/native/libzip/zlib/compress.c b/src/java.base/share/native/libzip/zlib/compress.c
index 54346ad2a2f1..832788e9248f 100644
--- a/src/java.base/share/native/libzip/zlib/compress.c
+++ b/src/java.base/share/native/libzip/zlib/compress.c
@@ -52,8 +52,8 @@ int ZEXPORT compress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
const uInt max = (uInt)-1;
z_size_t left;
- if ((sourceLen > 0 && source == NULL) ||
- destLen == NULL || (*destLen > 0 && dest == NULL))
+ if ((sourceLen > 0 && source == Z_NULL) ||
+ destLen == Z_NULL || (*destLen > 0 && dest == Z_NULL))
return Z_STREAM_ERROR;
left = *destLen;
diff --git a/src/java.base/share/native/libzip/zlib/deflate.c b/src/java.base/share/native/libzip/zlib/deflate.c
index 0ec56ec5691f..5918d8cb00b4 100644
--- a/src/java.base/share/native/libzip/zlib/deflate.c
+++ b/src/java.base/share/native/libzip/zlib/deflate.c
@@ -76,7 +76,7 @@
#include "deflate.h"
const char deflate_copyright[] =
- " deflate 1.3.2 Copyright 1995-2026 Jean-loup Gailly and Mark Adler ";
+ " deflate 1.4 Copyright 1995-2026 Jean-loup Gailly and Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -469,7 +469,6 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method,
s->status = INIT_STATE; /* to pass state test in deflateReset() */
s->wrap = wrap;
- s->gzhead = Z_NULL;
s->w_bits = (uInt)windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
@@ -592,7 +591,8 @@ int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
return Z_STREAM_ERROR;
s = strm->state;
wrap = s->wrap;
- if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
+ if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead ||
+ (wrap == 0 && (long)s->strstart != s->block_start))
return Z_STREAM_ERROR;
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
@@ -695,7 +695,20 @@ int ZEXPORT deflateResetKeep(z_streamp strm) {
adler32(0L, Z_NULL, 0);
s->last_flush = -2;
- _tr_init(s);
+ s->gzhead = Z_NULL;
+
+ {
+ /* Retain the hash work done for level 0. */
+ uInt matches = s->level == 0 ? s->matches : 0;
+ _tr_init(s);
+ s->matches = matches;
+ }
+
+ /* Keep the window and the hash, but drop what was left unfinished */
+ s->block_start = (long)s->strstart;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
return Z_OK;
}
@@ -707,6 +720,7 @@ local void lm_init(deflate_state *s) {
s->window_size = (ulg)2L*s->w_size;
CLEAR_HASH(s);
+ s->matches = 0; /* the hash is clear */
/* Set the default configuration parameters:
*/
@@ -769,18 +783,23 @@ int ZEXPORT deflateUsed(z_streamp strm, int *bits) {
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
deflate_state *s;
int put;
+ int need;
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
s = strm->state;
-#ifdef LIT_MEM
- if (bits < 0 || bits > 16 ||
- (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3))
+ if (bits < 0 || bits > 16)
return Z_BUF_ERROR;
-#else
- if (bits < 0 || bits > 16 ||
- s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
+ if (s->pending_out != s->pending_buf) {
+ /* move partially flushed pending output to buffer start */
+ Bytef *to = s->pending_buf, *from = s->pending_out;
+ ulg n = s->pending;
+ while (n--)
+ *to++ = *from++;
+ s->pending_out = s->pending_buf;
+ }
+ need = (s->bi_valid + bits) >> 3;
+ if (s->pending_buf_size - s->pending < (ulg)need)
return Z_BUF_ERROR;
-#endif
do {
put = Buf_size - s->bi_valid;
if (put > bits)
@@ -1340,39 +1359,49 @@ int ZEXPORT deflateEnd(z_streamp strm) {
*/
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) {
#ifdef MAXSEG_64K
- (void)dest;
(void)source;
+ if (dest != Z_NULL)
+ dest->state = Z_NULL;
return Z_STREAM_ERROR;
#else
deflate_state *ds;
deflate_state *ss;
-
- if (deflateStateCheck(source) || dest == Z_NULL) {
+ if (dest == Z_NULL)
+ return Z_STREAM_ERROR;
+ if (deflateStateCheck(source)) {
+ dest->state = Z_NULL;
return Z_STREAM_ERROR;
}
ss = source->state;
- zmemcpy(dest, source, sizeof(z_stream));
-
- ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
- if (ds == Z_NULL) return Z_MEM_ERROR;
- zmemzero(ds, sizeof(deflate_state));
- dest->state = (struct internal_state FAR *) ds;
+ ds = (deflate_state *) ZALLOC(source, 1, sizeof(deflate_state));
+ if (ds == Z_NULL) {
+ dest->state = Z_NULL;
+ return Z_MEM_ERROR;
+ }
zmemcpy(ds, ss, sizeof(deflate_state));
- ds->strm = dest;
-
- ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
- ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
- ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
- ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS);
-
+ ds->window = (Bytef *) ZALLOC(source, ds->w_size, 2*sizeof(Byte));
+ ds->prev = (Posf *) ZALLOC(source, ds->w_size, sizeof(Pos));
+ ds->head = (Posf *) ZALLOC(source, ds->hash_size, sizeof(Pos));
+ ds->pending_buf = (uchf *) ZALLOC(source, ds->lit_bufsize, LIT_BUFS);
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
ds->pending_buf == Z_NULL) {
- deflateEnd (dest);
+ TRY_FREE(source, ds->pending_buf);
+ TRY_FREE(source, ds->head);
+ TRY_FREE(source, ds->prev);
+ TRY_FREE(source, ds->window);
+ ZFREE(source, ds);
+ dest->state = Z_NULL;
return Z_MEM_ERROR;
}
+
+ /* copy the stream and attach the new state */
+ zmemcpy(dest, source, sizeof(z_stream));
+ dest->state = (struct internal_state FAR *) ds;
+ ds->strm = dest;
+
/* following zmemcpy's do not work for 16-bit MSDOS */
zmemcpy(ds->window, ss->window, ss->high_water);
zmemcpy(ds->prev, ss->prev,
@@ -1665,7 +1694,10 @@ local void check_match(deflate_state *s, IPos start, IPos match, int length) {
/* Same but force premature exit if necessary. */
#define FLUSH_BLOCK(s, last) { \
FLUSH_BLOCK_ONLY(s, last); \
- if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
+ if (s->strm->avail_out == 0) { \
+ if (!(last)) return need_more; \
+ if (s->pending != 0 || s->wrap != 0) return finish_started; \
+ } \
}
/* Maximum stored block length in deflate format (not including header). */
@@ -1700,7 +1732,7 @@ local block_state deflate_stored(deflate_state *s, int flush) {
* possible. If flushing, copy the remaining available input to next_out as
* stored blocks, if there is enough space.
*/
- int last = 0;
+ int last = 0, all;
unsigned len, left, have;
unsigned used = s->strm->avail_in;
do {
@@ -1715,11 +1747,14 @@ local block_state deflate_stored(deflate_state *s, int flush) {
/* maximum stored block length that will fit in avail_out: */
have = s->strm->avail_out - have;
left = (unsigned)(s->strstart - s->block_start); /* window bytes */
- if (len > (ulg)left + s->strm->avail_in)
+ if (left < len && s->strm->avail_in < len - left)
len = left + s->strm->avail_in; /* limit len to the input */
if (len > have)
len = have; /* limit len to the output */
+ /* all is true if len is all of the available input */
+ all = len >= left && len - left == s->strm->avail_in;
+
/* If the stored block would be less than min_block in length, or if
* unable to copy all of the available input when flushing, then try
* copying to the window and the pending buffer instead. Also don't
@@ -1727,13 +1762,13 @@ local block_state deflate_stored(deflate_state *s, int flush) {
*/
if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
flush == Z_NO_FLUSH ||
- len != left + s->strm->avail_in))
+ !all))
break;
/* Make a dummy stored block in pending to get the header bytes,
* including any pending bits. This also updates the debugging counts.
*/
- last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
+ last = flush == Z_FINISH && all ? 1 : 0;
_tr_stored_block(s, (char *)0, 0L, last);
/* Replace the lengths in the dummy stored block with len. */
@@ -2038,7 +2073,8 @@ local block_state deflate_slow(deflate_state *s, int flush) {
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
/* Do not insert strings in hash table beyond this. */
- check_match(s, s->strstart - 1, s->prev_match, (int)s->prev_length);
+ check_match(s, s->strstart - 1, s->prev_match,
+ (int)s->prev_length);
_tr_tally_dist(s, s->strstart - 1 - s->prev_match,
s->prev_length - MIN_MATCH, bflush);
diff --git a/src/java.base/share/native/libzip/zlib/gzguts.h b/src/java.base/share/native/libzip/zlib/gzguts.h
index 0be646016ed8..70ca11af0bc3 100644
--- a/src/java.base/share/native/libzip/zlib/gzguts.h
+++ b/src/java.base/share/native/libzip/zlib/gzguts.h
@@ -116,8 +116,10 @@
# define vsnprintf _vsnprintf
# endif
# endif
-# elif !defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L
-/* Otherwise if C89/90, assume no C99 snprintf() or vsnprintf() */
+# elif (!defined(__STDC_VERSION__) || __STDC_VERSION__-0 < 199901L) && \
+ (!defined(__cplusplus) || __cplusplus < 201103L)
+/* Otherwise if C89/90 (and not C++11 or later), assume no C99 snprintf() or
+ vsnprintf() */
# ifndef NO_snprintf
# define NO_snprintf
# endif
@@ -152,14 +154,28 @@
# include
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
#else
+# include
# ifndef NO_STRERROR
-# include
# define zstrerror() strerror(errno)
# else
# define zstrerror() "stdio error (consult errno)"
# endif
#endif
+#ifdef EAGAIN
+# ifdef EWOULDBLOCK
+# define BLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
+# else
+# define BLOCKED(e) ((e) == EAGAIN)
+# endif
+#else
+# ifdef EWOULDBLOCK
+# define BLOCKED(e) ((e) == EWOULDBLOCK)
+# else
+# define BLOCKED(e) (0)
+# endif
+#endif
+
/* provide prototypes for these when building zlib without LFS */
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
@@ -238,3 +254,10 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error);
(possible z_off64_t types off_t, off64_t, and long are all signed) */
unsigned ZLIB_INTERNAL gz_intmax(void);
#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
+
+/* largest value representable in z_off64_t */
+#ifndef CHAR_BIT
+# define CHAR_BIT 8
+#endif
+#define GZ_OFF_MAX \
+ ((((z_off64_t)1 << (sizeof(z_off64_t) * CHAR_BIT - 2)) - 1) * 2 + 1)
diff --git a/src/java.base/share/native/libzip/zlib/gzlib.c b/src/java.base/share/native/libzip/zlib/gzlib.c
index 9489bcc1f12e..c62db8580075 100644
--- a/src/java.base/share/native/libzip/zlib/gzlib.c
+++ b/src/java.base/share/native/libzip/zlib/gzlib.c
@@ -92,9 +92,9 @@ char ZLIB_INTERNAL *gz_strwinerror(DWORD error) {
/* Reset gzip file state */
local void gz_reset(gz_statep state) {
state->x.have = 0; /* no output data available */
+ state->past = 0; /* have not read past end yet */
if (state->mode == GZ_READ) { /* for reading ... */
state->eof = 0; /* not at end of file */
- state->past = 0; /* have not read past end yet */
state->how = LOOK; /* look for gzip header */
state->junk = -1; /* mark first member */
}
@@ -112,9 +112,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
gz_statep state;
z_size_t len;
int oflag = 0;
-#ifdef O_EXCL
int exclusive = 0;
-#endif
/* check input */
if (path == NULL || mode == NULL)
@@ -160,11 +158,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
oflag |= O_CLOEXEC;
break;
#endif
-#ifdef O_EXCL
case 'x':
exclusive = 1;
break;
-#endif
case 'f':
state->strategy = Z_FILTERED;
break;
@@ -220,10 +216,21 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
/* if reading, direct == 1 for auto-detect, -1 for gzip only; if writing or
appending, direct == 0 for gzip, 1 for transparent (copy in to out) */
+#ifndef O_EXCL
+ if (exclusive && state->mode != GZ_READ && fd < 0) {
+ /* exclusive creation request can't be honored -- fail out */
+ free(state);
+ return NULL;
+ }
+#endif
+
/* save the path name for error messages */
#ifdef WIDECHAR
- if (fd == -2)
+ if (fd == -2) {
len = wcstombs(NULL, path, 0);
+ if (len == (z_size_t)-1)
+ len = 0; /* not representable in the current locale */
+ }
else
#endif
len = strlen((const char *)path);
@@ -234,9 +241,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
}
#ifdef WIDECHAR
if (fd == -2) {
- if (len)
- wcstombs(state->path, path, len + 1);
- else
+ if (len == 0 || wcstombs(state->path, path, len + 1) != len)
*(state->path) = 0;
}
else
@@ -245,7 +250,7 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
#else
- strcpy(state->path, path);
+ strcpy(state->path, (const char *)path);
#endif
}
@@ -279,9 +284,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
if (oflag & O_NONBLOCK)
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
#endif
-#ifdef O_CLOEXEC
+#if defined(O_CLOEXEC) && defined(FD_CLOEXEC)
if (oflag & O_CLOEXEC)
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | O_CLOEXEC);
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
#endif
state->fd = fd;
}
@@ -323,7 +328,7 @@ gzFile ZEXPORT gzdopen(int fd, const char *mode) {
char *path; /* identifier for error messages */
gzFile gz;
- if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
+ if (fd < 0 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
return NULL;
#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
(void)snprintf(path, 7 + 3 * sizeof(int), "", fd);
@@ -390,7 +395,7 @@ int ZEXPORT gzrewind(gzFile file) {
/* -- see zlib.h -- */
z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
unsigned n;
- z_off64_t ret;
+ z_off64_t ret, pos;
gz_statep state;
/* get internal structure and check integrity */
@@ -408,18 +413,19 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
if (whence != SEEK_SET && whence != SEEK_CUR)
return -1;
- /* normalize offset to a SEEK_CUR specification */
- if (whence == SEEK_SET)
- offset -= state->x.pos;
- else {
- offset += state->past ? 0 : state->skip;
- state->skip = 0;
- }
+ /* compute the absolute position */
+ pos = whence == SEEK_SET ? 0 :
+ state->x.pos + (state->past ? 0 : state->skip);
+ if (offset > GZ_OFF_MAX - pos)
+ return -1; /* would overflow z_off64_t */
+ if (offset < -pos)
+ return -1; /* before start of file */
+ pos += offset;
/* if within raw area while reading, just go there */
- if (state->mode == GZ_READ && state->how == COPY &&
- state->x.pos + offset >= 0) {
- ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
+ if (state->mode == GZ_READ && state->how == COPY) {
+ ret = LSEEK(state->fd, pos - state->x.pos - (z_off64_t)state->x.have,
+ SEEK_CUR);
if (ret == -1)
return -1;
state->x.have = 0;
@@ -428,20 +434,18 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
state->skip = 0;
gz_error(state, Z_OK, NULL);
state->strm.avail_in = 0;
- state->x.pos += offset;
- return state->x.pos;
+ state->x.pos = pos;
+ return pos;
}
- /* calculate skip amount, rewinding if needed for back seek when reading */
- if (offset < 0) {
+ /* rewind if needed for back seek when reading */
+ if (pos < state->x.pos) {
if (state->mode != GZ_READ) /* writing -- can't go backwards */
return -1;
- offset += state->x.pos;
- if (offset < 0) /* before start of file! */
- return -1;
- if (gzrewind(file) == -1) /* rewind, then skip to offset */
+ if (gzrewind(file) == -1) /* rewind, then skip to pos */
return -1;
}
+ offset = pos - state->x.pos;
/* if reading, skip what's in output buffer (one less gzgetc() check) */
if (state->mode == GZ_READ) {
@@ -455,7 +459,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
/* request skip (if not zero) */
state->skip = offset;
- return state->x.pos + offset;
+ return pos;
}
/* -- see zlib.h -- */
@@ -584,10 +588,6 @@ void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) {
state->msg = NULL;
}
- /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
- if (err != Z_OK && err != Z_BUF_ERROR && !state->again)
- state->x.have = 0;
-
/* set error code, and if no message, then done */
state->err = err;
if (msg == NULL)
diff --git a/src/java.base/share/native/libzip/zlib/gzread.c b/src/java.base/share/native/libzip/zlib/gzread.c
index 89144d2e56fe..ce7da3d0c999 100644
--- a/src/java.base/share/native/libzip/zlib/gzread.c
+++ b/src/java.base/share/native/libzip/zlib/gzread.c
@@ -57,7 +57,7 @@ local int gz_load(gz_statep state, unsigned char *buf, unsigned len,
*have += (unsigned)ret;
} while (*have < len);
if (ret < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (BLOCKED(errno)) {
state->again = 1;
if (*have != 0)
return 0;
@@ -149,6 +149,13 @@ local int gz_look(gz_statep state) {
if we're looking for a gzip member after the first one, which is not at
the start, then proceed directly to look for a gzip member next */
if (state->direct == -1 || state->junk == 0) {
+ /* wait for input before committing to another gzip member */
+ if (state->junk == 0 && strm->avail_in == 0) {
+ if (gz_avail(state) == -1)
+ return -1;
+ if (strm->avail_in == 0)
+ return 0;
+ }
inflateReset(strm);
state->how = GZIP;
state->junk = state->junk != -1;
@@ -177,7 +184,7 @@ local int gz_look(gz_statep state) {
strm->next_in[2] == 8 && strm->next_in[3] < 32) {
inflateReset(strm);
state->how = GZIP;
- state->junk = 1;
+ state->junk = 0;
state->direct = 0;
return 0;
}
@@ -272,6 +279,11 @@ local int gz_decomp(gz_statep state) {
local int gz_fetch(gz_statep state) {
z_streamp strm = &(state->strm);
+ /* after a serious error, only what is already in the output buffer is
+ delivered -- don't try to decompress any more */
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+ return -1;
+
do {
switch(state->how) {
case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */
@@ -300,32 +312,46 @@ local int gz_fetch(gz_statep state) {
return 0;
}
+/* Apply as much of a pending skip request as the output already available in
+ state->x allows. */
+local void gz_skip_have(gz_statep state) {
+ unsigned n;
+
+ n = GT_OFF(state->x.have) ||
+ (z_off64_t)state->x.have > state->skip ?
+ (unsigned)state->skip : state->x.have;
+ state->x.have -= n;
+ state->x.next += n;
+ state->x.pos += n;
+ state->skip -= n;
+}
+
/* Skip state->skip (> 0) uncompressed bytes of output. Return -1 on error, 0
on success. */
local int gz_skip(gz_statep state) {
- unsigned n;
-
/* skip over len bytes or reach end-of-file, whichever comes first */
do {
/* skip over whatever is in output buffer */
- if (state->x.have) {
- n = GT_OFF(state->x.have) ||
- (z_off64_t)state->x.have > state->skip ?
- (unsigned)state->skip : state->x.have;
- state->x.have -= n;
- state->x.next += n;
- state->x.pos += n;
- state->skip -= n;
- }
+ if (state->x.have)
+ gz_skip_have(state);
/* output buffer empty -- return if we're at the end of the input */
- else if (state->eof && state->strm.avail_in == 0)
+ else if (state->eof && state->strm.avail_in == 0) {
+ if (state->how == GZIP && state->err == Z_OK)
+ gz_error(state, Z_BUF_ERROR, "unexpected end of file");
+ state->skip = 0;
+ state->past = 1;
break;
+ }
/* need more data to skip -- load up output buffer */
else {
- /* get more output, looking for header if required */
- if (gz_fetch(state) == -1)
+ /* get more output, looking for header if required. If the fetch
+ stalled but provided some output, consume it before returning
+ so that x.have > 0 always implies the data is at the current
+ logical position (x.pos), as assumed by the gzgetc() fast path
+ in zlib.h and gzread.c */
+ if (gz_fetch(state) == -1 && state->x.have == 0)
return -1;
}
} while (state->skip);
@@ -373,8 +399,11 @@ local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
}
/* output buffer empty -- return if we're at the end of the input */
- else if (state->eof && state->strm.avail_in == 0)
+ else if (state->eof && state->strm.avail_in == 0) {
+ if (state->how == GZIP && state->err == Z_OK)
+ gz_error(state, Z_BUF_ERROR, "unexpected end of file");
break;
+ }
/* need output data -- for small len or new stream load up our output
buffer, so that gzgetc() can be fast */
@@ -427,15 +456,21 @@ int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) {
if (state->mode != GZ_READ)
return -1;
- /* check that there was no (serious) error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+ /* check that there was no (serious) error -- if there was, deliver any
+ data read before the error until it is exhausted, and only then return
+ the error */
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+ state->x.have == 0)
return -1;
- gz_error(state, Z_OK, NULL);
+ if (state->again)
+ gz_error(state, Z_OK, NULL);
/* since an int is returned, make sure len fits in one, otherwise return
- with an error (this avoids a flaw in the interface) */
+ with an error (this avoids a flaw in the interface) -- keep a pending
+ serious error, which is the one the caller needs to see */
if ((int)len < 0) {
- gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
+ if (state->err == Z_OK || state->err == Z_BUF_ERROR)
+ gz_error(state, Z_STREAM_ERROR, "request does not fit in an int");
return -1;
}
@@ -472,15 +507,22 @@ z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
if (state->mode != GZ_READ)
return 0;
- /* check that there was no (serious) error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+ /* check that there was no (serious) error -- if there was, deliver any
+ data read before the error until it is exhausted, and only then return
+ the error */
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+ state->x.have == 0)
return 0;
- gz_error(state, Z_OK, NULL);
+ if (state->again)
+ gz_error(state, Z_OK, NULL);
- /* compute bytes to read -- error on overflow */
+ /* compute bytes to read -- error on overflow, keeping a pending serious
+ error, which is the one the caller needs to see */
len = nitems * size;
if (size && len / size != nitems) {
- gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
+ if (state->err == Z_OK || state->err == Z_BUF_ERROR)
+ gz_error(state, Z_STREAM_ERROR,
+ "request does not fit in a size_t");
return 0;
}
@@ -505,10 +547,14 @@ int ZEXPORT gzgetc(gzFile file) {
if (state->mode != GZ_READ)
return -1;
- /* check that there was no (serious) error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+ /* check that there was no (serious) error -- if there was, deliver any
+ data read before the error until it is exhausted, and only then return
+ the error, as the gzgetc() macro does */
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+ state->x.have == 0)
return -1;
- gz_error(state, Z_OK, NULL);
+ if (state->again)
+ gz_error(state, Z_OK, NULL);
/* try output buffer (no need to check for skip request) */
if (state->x.have) {
@@ -540,10 +586,15 @@ int ZEXPORT gzungetc(int c, gzFile file) {
if (state->how == LOOK && state->x.have == 0)
(void)gz_look(state);
- /* check that there was no (serious) error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+ /* check that there was no (serious) error -- a character can still be
+ pushed back after one, since it is data that was read before the
+ error, and it will be returned before the error is signaled -- but only
+ if there is an output buffer to put it in */
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+ state->size == 0)
return -1;
- gz_error(state, Z_OK, NULL);
+ if (state->again)
+ gz_error(state, Z_OK, NULL);
/* process a skip request */
if (state->skip && gz_skip(state) == -1)
@@ -565,7 +616,8 @@ int ZEXPORT gzungetc(int c, gzFile file) {
/* if no room, give up (must have already done a gzungetc()) */
if (state->x.have == (state->size << 1)) {
- gz_error(state, Z_DATA_ERROR, "out of room to push characters");
+ if (state->err == Z_OK || state->err == Z_BUF_ERROR)
+ gz_error(state, Z_DATA_ERROR, "out of room to push characters");
return -1;
}
@@ -601,10 +653,14 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
if (state->mode != GZ_READ)
return NULL;
- /* check that there was no (serious) error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again)
+ /* check that there was no (serious) error -- if there was, deliver any
+ data read before the error until it is exhausted, and only then return
+ the error */
+ if (state->err != Z_OK && state->err != Z_BUF_ERROR && !state->again &&
+ state->x.have == 0)
return NULL;
- gz_error(state, Z_OK, NULL);
+ if (state->again)
+ gz_error(state, Z_OK, NULL);
/* process a skip request */
if (state->skip && gz_skip(state) == -1)
@@ -616,8 +672,9 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
left = (unsigned)len - 1;
if (left) do {
/* assure that something is in the output buffer */
- if (state->x.have == 0 && gz_fetch(state) == -1)
- break; /* error */
+ if (state->x.have == 0 && gz_fetch(state) == -1 &&
+ state->x.have == 0)
+ break; /* error, and nothing left to return */
if (state->x.have == 0) { /* end of file */
state->past = 1; /* read past end */
break; /* return what we have */
@@ -641,7 +698,7 @@ char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
/* append a terminating zero to the string (we don't check for a zero in
the contents, let the user worry about that) -- return the terminated
string, or if nothing was read, NULL */
- if (buf == str)
+ if (buf == str && len > 1)
return NULL;
buf[0] = 0;
return str;
@@ -658,8 +715,10 @@ int ZEXPORT gzdirect(gzFile file) {
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
- if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0)
+ if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) {
(void)gz_look(state);
+ gz_skip_have(state); /* apply skip to current buffer */
+ }
/* return 1 if transparent, 0 if processing a gzip stream */
return state->direct == 1;
diff --git a/src/java.base/share/native/libzip/zlib/gzwrite.c b/src/java.base/share/native/libzip/zlib/gzwrite.c
index b11c318d5432..cf933bef87b8 100644
--- a/src/java.base/share/native/libzip/zlib/gzwrite.c
+++ b/src/java.base/share/native/libzip/zlib/gzwrite.c
@@ -65,8 +65,8 @@ local int gz_init(gz_statep state) {
gz_error(state, Z_MEM_ERROR, "out of memory");
return -1;
}
- strm->next_in = NULL;
}
+ strm->next_in = NULL;
/* mark state as initialized */
state->size = state->want;
@@ -103,7 +103,7 @@ local int gz_comp(gz_statep state, int flush) {
put = strm->avail_in > max ? max : strm->avail_in;
writ = (int)write(state->fd, strm->next_in, put);
if (writ < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
+ if (BLOCKED(errno))
state->again = 1;
gz_error(state, Z_ERRNO, zstrerror());
return -1;
@@ -138,7 +138,7 @@ local int gz_comp(gz_statep state, int flush) {
(unsigned)(strm->next_out - state->x.next);
writ = (int)write(state->fd, state->x.next, put);
if (writ < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
+ if (BLOCKED(errno))
state->again = 1;
gz_error(state, Z_ERRNO, zstrerror());
return -1;
@@ -180,6 +180,11 @@ local int gz_zero(gz_statep state) {
unsigned n;
z_streamp strm = &(state->strm);
+ /* allocate memory if this is the first time through -- the input buffer
+ must exist before it is zeroed below */
+ if (state->size == 0 && gz_init(state) == -1)
+ return -1;
+
/* consume whatever's left in the input buffer */
if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
return -1;
@@ -199,8 +204,14 @@ local int gz_zero(gz_statep state) {
n -= strm->avail_in;
state->x.pos += n;
state->skip -= n;
- if (ret == -1)
+ if (ret == -1) {
+ /* discard any unconsumed zero fill -- it was not yet accounted
+ for in state->skip, so it will be generated again when the
+ operation is retried */
+ strm->avail_in = 0;
+ strm->next_in = state->in;
return -1;
+ }
} while (state->skip);
return 0;
}
@@ -266,9 +277,13 @@ local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
n -= state->strm.avail_in;
state->x.pos += n;
len -= n;
- if (ret == -1)
+ if (ret == -1) {
+ state->strm.avail_in = 0;
+ state->strm.next_in = state->in;
return state->again ? put - len : 0;
+ }
} while (len);
+ state->strm.next_in = state->in;
}
/* input was all buffered or compressed */
@@ -395,9 +410,10 @@ int ZEXPORT gzputs(gzFile file, const char *s) {
return len && put == 0 ? -1 : (int)put;
}
-#if (((!defined(STDC) && !defined(Z_HAVE_STDARG_H)) || !defined(NO_vsnprintf)) && \
- (defined(STDC) || defined(Z_HAVE_STDARG_H) || !defined(NO_snprintf))) || \
- defined(ZLIB_INSECURE)
+#if (((!defined(STDC) && !defined(Z_HAVE_STDARG_H)) || \
+ !defined(NO_vsnprintf)) && \
+ (defined(STDC) || defined(Z_HAVE_STDARG_H) || \
+ !defined(NO_snprintf))) || defined(ZLIB_INSECURE)
/* If the second half of the input buffer is occupied, write out the contents.
If there is any input remaining due to a non-blocking stall on write, move
it to the start of the buffer. Return true if this did not open up the
@@ -407,7 +423,8 @@ local int gz_vacate(gz_statep state) {
z_streamp strm;
strm = &(state->strm);
- if (strm->next_in + strm->avail_in <= state->in + state->size)
+ if (strm->next_in == NULL ||
+ strm->next_in + strm->avail_in <= state->in + state->size)
return 0;
(void)gz_comp(state, Z_NO_FLUSH);
if (strm->avail_in == 0) {
@@ -467,6 +484,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
a Z_BUF_ERROR to let the application know that this gzprintf()
needs to be retried. */
gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+ return state->err;
}
if (!state->again)
return state->err;
@@ -502,6 +520,14 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
/* write out buffer if more than half is occupied */
ret = gz_vacate(state);
+ if (ret) {
+ /* discard unwritten formatted output */
+ strm->avail_in -= (unsigned)len;
+ state->x.pos -= len;
+ if (state->again)
+ gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+ return state->err;
+ }
if (state->err && !state->again)
return state->err;
return len;
@@ -575,6 +601,7 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
a Z_BUF_ERROR to let the application know that this gzprintf()
needs to be retried. */
gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+ return state->err;
}
if (!state->again)
return state->err;
@@ -615,6 +642,14 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3,
/* write out buffer if more than half is occupied */
ret = gz_vacate(state);
+ if (ret) {
+ /* discard unwritten formatted output */
+ strm->avail_in -= (unsigned)len;
+ state->x.pos -= len;
+ if (state->again)
+ gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf");
+ return state->err;
+ }
if (state->err && !state->again)
return state->err;
return (int)len;
diff --git a/src/java.base/share/native/libzip/zlib/infback.c b/src/java.base/share/native/libzip/zlib/infback.c
index 0becbb9eb4f6..c2286bd20699 100644
--- a/src/java.base/share/native/libzip/zlib/infback.c
+++ b/src/java.base/share/native/libzip/zlib/infback.c
@@ -447,8 +447,6 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc,
/* use inflate_fast() if we have enough input and output */
if (have >= 6 && left >= 258) {
RESTORE();
- if (state->whave < state->wsize)
- state->whave = state->wsize - left;
inflate_fast(strm, state->wsize);
LOAD();
break;
diff --git a/src/java.base/share/native/libzip/zlib/inflate.c b/src/java.base/share/native/libzip/zlib/inflate.c
index c548f98f6de3..16bc832948e3 100644
--- a/src/java.base/share/native/libzip/zlib/inflate.c
+++ b/src/java.base/share/native/libzip/zlib/inflate.c
@@ -151,6 +151,14 @@ int ZEXPORT inflateReset(z_streamp strm) {
if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
+ if (state->wbits != state->reqbits) {
+ if (state->window != Z_NULL) {
+ ZFREE(strm, state->window);
+ state->window = Z_NULL;
+ }
+ state->wbits = state->reqbits;
+ }
+ state->wrap = state->reqwrap;
state->wsize = 0;
state->whave = 0;
state->wnext = 0;
@@ -189,8 +197,8 @@ int ZEXPORT inflateReset2(z_streamp strm, int windowBits) {
}
/* update state and reset the rest of it */
- state->wrap = wrap;
- state->wbits = (unsigned)windowBits;
+ state->reqwrap = state->wrap = wrap;
+ state->reqbits = state->wbits = (unsigned)windowBits;
return inflateReset(strm);
}
@@ -561,13 +569,13 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
}
DROPBITS(4);
len = BITS(4) + 8;
- if (state->wbits == 0)
- state->wbits = len;
- if (len > 15 || len > state->wbits) {
+ if (len > 15 || (state->wbits != 0 && len > state->wbits)) {
strm->msg = (z_const char *)"invalid window size";
state->mode = BAD;
break;
}
+ if (state->wbits == 0)
+ state->wbits = len;
state->dmax = 1U << len;
state->flags = 0; /* indicate zlib header */
Tracev((stderr, "inflate: zlib header ok\n"));
@@ -724,6 +732,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
case DICT:
if (state->havedict == 0) {
RESTORE();
+ strm->total_in += in - strm->avail_in;
return Z_NEED_DICT;
}
strm->adler = state->check = adler32(0L, Z_NULL, 0);
@@ -936,7 +945,7 @@ int ZEXPORT inflate(z_streamp strm, int flush) {
state->mode = LEN;
/* fallthrough */
case LEN:
- if (have >= 6 && left >= 258) {
+ if (have >= 6 && left >= 258 && bits < 8) {
RESTORE();
inflate_fast(strm, out);
LOAD();
@@ -1215,7 +1224,8 @@ int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
int ret;
/* check state */
- if (inflateStateCheck(strm)) return Z_STREAM_ERROR;
+ if (inflateStateCheck(strm) || dictionary == Z_NULL)
+ return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
if (state->wrap != 0 && state->mode != DICT)
return Z_STREAM_ERROR;
@@ -1320,15 +1330,23 @@ int ZEXPORT inflateSync(z_streamp strm) {
/* return no joy or set up to restart inflate() on a new block */
if (state->have != 4) return Z_DATA_ERROR;
- if (state->flags == -1)
- state->wrap = 0; /* if no header yet, treat as raw */
- else
- state->wrap &= ~4; /* no point in computing a check value now */
flags = state->flags;
in = strm->total_in; out = strm->total_out;
inflateReset(strm);
strm->total_in = in; strm->total_out = out;
state->flags = flags;
+ if (flags == -1)
+ state->wrap = 0; /* if no header yet, treat as raw */
+ else
+ state->wrap &= ~4; /* no point in computing a check value now */
+ if (state->wbits == 0) {
+ /* we never got to see a header for the window size -- set to max */
+ if (state->window != Z_NULL) {
+ ZFREE(strm, state->window);
+ state->window = Z_NULL;
+ }
+ state->wbits = 15;
+ }
state->mode = TYPE;
return Z_OK;
}
@@ -1355,14 +1373,21 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
unsigned char FAR *window;
/* check input */
- if (inflateStateCheck(source) || dest == Z_NULL)
+ if (dest == Z_NULL)
return Z_STREAM_ERROR;
+ if (inflateStateCheck(source)) {
+ dest->state = Z_NULL;
+ return Z_STREAM_ERROR;
+ }
state = (struct inflate_state FAR *)source->state;
/* allocate space */
copy = (struct inflate_state FAR *)
ZALLOC(source, 1, sizeof(struct inflate_state));
- if (copy == Z_NULL) return Z_MEM_ERROR;
+ if (copy == Z_NULL) {
+ dest->state = Z_NULL;
+ return Z_MEM_ERROR;
+ }
zmemzero(copy, sizeof(struct inflate_state));
window = Z_NULL;
if (state->window != Z_NULL) {
@@ -1370,6 +1395,7 @@ int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) {
ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
if (window == Z_NULL) {
ZFREE(source, copy);
+ dest->state = Z_NULL;
return Z_MEM_ERROR;
}
}
@@ -1415,6 +1441,10 @@ int ZEXPORT inflateValidate(z_streamp strm, int check) {
state->wrap |= 4;
else
state->wrap &= ~4;
+ if (check && state->reqwrap)
+ state->reqwrap |= 4;
+ else
+ state->reqwrap &= ~4;
return Z_OK;
}
diff --git a/src/java.base/share/native/libzip/zlib/inflate.h b/src/java.base/share/native/libzip/zlib/inflate.h
index 7828fb5db38e..1f2783e58cf8 100644
--- a/src/java.base/share/native/libzip/zlib/inflate.h
+++ b/src/java.base/share/native/libzip/zlib/inflate.h
@@ -109,6 +109,7 @@ struct inflate_state {
int last; /* true if processing last block */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
bit 2 true to validate check value */
+ int reqwrap; /* requested wrap */
int havedict; /* true if dictionary provided */
int flags; /* gzip header method and flags, 0 if zlib, or
-1 if raw or no header yet */
@@ -117,7 +118,8 @@ struct inflate_state {
unsigned long total; /* protected copy of output count */
gz_headerp head; /* where to save gzip header information */
/* sliding window */
- unsigned wbits; /* log base 2 of requested window size */
+ unsigned reqbits; /* requested log base 2 of window size */
+ unsigned wbits; /* current log base 2 of window size */
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned wnext; /* window write index */
diff --git a/src/java.base/share/native/libzip/zlib/inftrees.c b/src/java.base/share/native/libzip/zlib/inftrees.c
index 5f5d6b4baef2..7486efef8ee9 100644
--- a/src/java.base/share/native/libzip/zlib/inftrees.c
+++ b/src/java.base/share/native/libzip/zlib/inftrees.c
@@ -47,7 +47,7 @@
#define MAXBITS 15
const char inflate_copyright[] =
- " inflate 1.3.2 Copyright 1995-2026 Mark Adler ";
+ " inflate 1.4 Copyright 1995-2026 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
@@ -95,7 +95,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
- 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 75};
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 71, 77};
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
diff --git a/src/java.base/share/native/libzip/zlib/inftrees.h b/src/java.base/share/native/libzip/zlib/inftrees.h
index b9b4fc2fb2bc..51f67b68c65b 100644
--- a/src/java.base/share/native/libzip/zlib/inftrees.h
+++ b/src/java.base/share/native/libzip/zlib/inftrees.h
@@ -70,8 +70,14 @@ typedef struct {
inflate_table() calls in inflate.c and infback.c. If the root table size is
changed, then these maximum sizes would be need to be recalculated and
updated. */
-#define ENOUGH_LENS 852
-#define ENOUGH_DISTS 592
+#ifndef PKZIP_BUG_WORKAROUND
+# define ENOUGH_LENS 852
+# define ENOUGH_DISTS 592
+#else
+/* That workaround permits 288 literal/length codes and 32 distance codes. */
+# define ENOUGH_LENS 854
+# define ENOUGH_DISTS 594
+#endif
#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
/* Type of code to build for inflate_table() */
diff --git a/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java b/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java
index dfde58f0122d..46affe2cd5e2 100644
--- a/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java
+++ b/src/java.base/share/native/libzip/zlib/patches/ChangeLog_java
@@ -1,6 +1,6 @@
-Changes in JDK's in-tree zlib compared to upstream zlib 1.3.2
+Changes in JDK's in-tree zlib compared to upstream zlib 1.4
-(1) renamed adler32.c -> zadler32.c, crc32c -> zcrc32.c
+(1) renamed adler32.c -> zadler32.c, crc32.c -> zcrc32.c
diff --git a/src/java.base/share/native/libzip/zlib/trees.c b/src/java.base/share/native/libzip/zlib/trees.c
index cc7b136bcf68..bf5c1b24149e 100644
--- a/src/java.base/share/native/libzip/zlib/trees.c
+++ b/src/java.base/share/native/libzip/zlib/trees.c
@@ -251,7 +251,7 @@ local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) {
tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
- n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
+ n, (isgraph(n & 0xff) ? n : ' '), len, tree[n].Code, next_code[len] - 1));
}
}
diff --git a/src/java.base/share/native/libzip/zlib/uncompr.c b/src/java.base/share/native/libzip/zlib/uncompr.c
index 25da59461c37..d55a4f2d66ca 100644
--- a/src/java.base/share/native/libzip/zlib/uncompr.c
+++ b/src/java.base/share/native/libzip/zlib/uncompr.c
@@ -57,8 +57,8 @@ int ZEXPORT uncompress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
const uInt max = (uInt)-1;
z_size_t len, left;
- if (sourceLen == NULL || (*sourceLen > 0 && source == NULL) ||
- destLen == NULL || (*destLen > 0 && dest == NULL))
+ if (sourceLen == Z_NULL || (*sourceLen > 0 && source == Z_NULL) ||
+ destLen == Z_NULL || (*destLen > 0 && dest == Z_NULL))
return Z_STREAM_ERROR;
len = *sourceLen;
diff --git a/src/java.base/share/native/libzip/zlib/zconf.h b/src/java.base/share/native/libzip/zlib/zconf.h
index d4589739a0ae..542e462ac177 100644
--- a/src/java.base/share/native/libzip/zlib/zconf.h
+++ b/src/java.base/share/native/libzip/zlib/zconf.h
@@ -523,6 +523,10 @@ typedef uLong FAR uLongf;
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
# define Z_LFS64
+#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && \
+ !defined(UNDER_CE) && (defined(__MINGW32__) || !defined(__GNUC__))
+# define Z_LFS64 /* native Windows has 64-bit file offsets */
+# define Z_WINLFS
#endif
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
@@ -540,7 +544,7 @@ typedef uLong FAR uLongf;
#endif
#ifndef z_off_t
-# define z_off_t long long
+# define z_off_t long
#endif
#if !defined(_WIN32) && defined(Z_LARGE64)
@@ -555,6 +559,11 @@ typedef uLong FAR uLongf;
# define z_off64_t z_off_t
#endif
+#if defined(Z_WINLFS) && defined(Z_WANT64) && !defined(Z_SOLO)
+# undef z_off_t
+# define z_off_t z_off64_t
+#endif
+
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
#pragma map(deflateInit_,"DEIN")
diff --git a/src/java.base/share/native/libzip/zlib/zcrc32.c b/src/java.base/share/native/libzip/zlib/zcrc32.c
index 133cbe158aa4..0161f1ee20e8 100644
--- a/src/java.base/share/native/libzip/zlib/zcrc32.c
+++ b/src/java.base/share/native/libzip/zlib/zcrc32.c
@@ -710,7 +710,7 @@ uLong ZEXPORT crc32_z(uLong crc, const unsigned char FAR *buf, z_size_t len) {
#endif
/* Initialize the CRC for each braid. */
- crc0 = crc;
+ crc0 = (z_crc_t)crc;
#if N > 1
crc1 = 0;
#if N > 2
diff --git a/src/java.base/share/native/libzip/zlib/zlib.h b/src/java.base/share/native/libzip/zlib/zlib.h
index 90230f4f23fb..15b6b927a10c 100644
--- a/src/java.base/share/native/libzip/zlib/zlib.h
+++ b/src/java.base/share/native/libzip/zlib/zlib.h
@@ -23,7 +23,7 @@
*/
/* zlib.h -- interface of the 'zlib' general purpose compression library
- version 1.3.2, February 17th, 2026
+ version 1.4, November 4th, 2026
Copyright (C) 1995-2026 Jean-loup Gailly and Mark Adler
@@ -65,11 +65,11 @@
extern "C" {
#endif
-#define ZLIB_VERSION "1.3.2"
-#define ZLIB_VERNUM 0x1320
+#define ZLIB_VERSION "1.4"
+#define ZLIB_VERNUM 0x1400
#define ZLIB_VER_MAJOR 1
-#define ZLIB_VER_MINOR 3
-#define ZLIB_VER_REVISION 2
+#define ZLIB_VER_MINOR 4
+#define ZLIB_VER_REVISION 0
#define ZLIB_VER_SUBREVISION 0
/*
@@ -720,7 +720,9 @@ ZEXTERN int ZEXPORT deflateCopy(z_streamp dest,
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being Z_NULL). msg is left unchanged in both source and
- destination.
+ destination. If deflateCopy fails and dest is not Z_NULL, then dest->state
+ is set to Z_NULL with dest otherwise unchanged, so that deflateEnd(dest) can
+ be called safely, though dest is not a usable stream.
*/
ZEXTERN int ZEXPORT deflateReset(z_streamp strm);
@@ -793,17 +795,17 @@ ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen);
ZEXTERN z_size_t ZEXPORT deflateBound_z(z_streamp strm, z_size_t sourceLen);
/*
deflateBound() returns an upper bound on the compressed size after
- deflation of sourceLen bytes. It must be called after deflateInit() or
- deflateInit2(), and after deflateSetHeader(), if used. This would be used
- to allocate an output buffer for deflation in a single pass, and so would be
- called before deflate(). If that first deflate() call is provided the
- sourceLen input bytes, an output buffer allocated to the size returned by
- deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
- to return Z_STREAM_END. Note that it is possible for the compressed size to
- be larger than the value returned by deflateBound() if flush options other
- than Z_FINISH or Z_NO_FLUSH are used.
-
- delfateBound_z() is the same, but takes and returns a size_t length. Note
+ deflation of sourceLen bytes. It must be called after deflateInit() or
+ deflateInit2(), and after deflateSetHeader() or deflateSetDictionary(), if
+ used. This would be used to allocate an output buffer for deflation in a
+ single pass, and so would be called before deflate(). If that first
+ deflate() call is provided the sourceLen input bytes, an output buffer
+ allocated to the size returned by deflateBound(), and the flush value
+ Z_FINISH, then deflate() is guaranteed to return Z_STREAM_END. Note that it
+ is possible for the compressed size to be larger than the value returned by
+ deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH are used.
+
+ deflateBound_z() is the same, but takes and returns a size_t length. Note
that a long is 32 bits on Windows.
*/
@@ -813,7 +815,7 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
/*
deflatePending() returns the number of bytes and bits of output that have
been generated, but not yet provided in the available output. The bytes not
- provided would be due to the available output space having being consumed.
+ provided would be due to the available output space having been consumed.
The number of bits of output not provided are between 0 and 7, where they
await more bits to join them in order to fill out a full byte. If pending
or bits are Z_NULL, then those values are not set.
@@ -893,8 +895,7 @@ ZEXTERN int ZEXPORT inflateInit2(z_streamp strm,
instead. windowBits must be greater than or equal to the windowBits value
provided to deflateInit2() while compressing, or it must be equal to 15 if
deflateInit2() was not used. If a compressed stream with a larger window
- size is given as input, inflate() will return with the error code
- Z_DATA_ERROR instead of trying to allocate a larger window.
+ size is given as input, inflate() may return with a Z_DATA_ERROR.
windowBits can also be zero to request that inflate use the window size in
the zlib header of the compressed stream.
@@ -1004,7 +1005,9 @@ ZEXTERN int ZEXPORT inflateCopy(z_streamp dest,
inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being Z_NULL). msg is left unchanged in both source and
- destination.
+ destination. If inflateCopy fails and dest is not Z_NULL, then dest->state
+ is set to Z_NULL with dest otherwise unchanged, so that inflateEnd(dest) can
+ be called safely, though dest is not a usable stream.
*/
ZEXTERN int ZEXPORT inflateReset(z_streamp strm);
@@ -1119,9 +1122,10 @@ ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
a terminating zero. If any of extra, name, or comment are not present in
the header, then that field's pointer is set to Z_NULL. This allows the use
of deflateSetHeader() with the returned structure to duplicate the header.
- Note that if those fields initially pointed to allocated memory, then the
- application will need to save them elsewhere so that they can be eventually
- freed.
+ Though take care that none of the fields were truncated before so using it,
+ lest havoc ensue. Note that if those fields initially pointed to allocated
+ memory, then the application will need to save them elsewhere so that they
+ can be eventually freed.
If inflateGetHeader is not used, then the header information is simply
discarded. The header is always checked for validity, including the header
@@ -1418,8 +1422,8 @@ ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode);
errno can be checked to determine if the reason gzopen failed was that the
file could not be opened. Note that if 'N' is in mode for non-blocking, the
open() itself can fail in order to not block. In that case gzopen() will
- return NULL and errno will be EAGAIN or ENONBLOCK. The call to gzopen() can
- then be re-tried. If the application would like to block on opening the
+ return NULL and errno will be EAGAIN or EWOULDBLOCK. The call to gzopen()
+ can then be re-tried. If the application would like to block on opening the
file, then it can use open() without O_NONBLOCK, and then gzdopen() with the
resulting file descriptor and 'N' in the mode, which will set it to non-
blocking.
@@ -1525,9 +1529,12 @@ ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems,
gzfread() returns the number of full items read of size size, or zero if
the end of the file was reached and a full item could not be read, or if
there was an error. gzerror() must be consulted if zero is returned in
- order to determine if there was an error. If the multiplication of size and
- nitems overflows, i.e. the product does not fit in a z_size_t, then nothing
- is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
+ order to determine if there was an error. If some data was read before an
+ error, then that data is returned until exhausted, after which the next call
+ will return zero and gzerror() will report the error. If the multiplication
+ of size and nitems overflows, i.e. the product does not fit in a z_size_t,
+ then nothing is read, zero is returned, and the error state is set to
+ Z_STREAM_ERROR.
In the event that the end of file is reached and only a partial item is
available at the end, i.e. the remaining uncompressed data length is not a
@@ -1593,7 +1600,7 @@ ZEXTERN int ZEXPORTVA gzprintf();
these possibilities can be determined using zlibCompileFlags().
If a Z_BUF_ERROR is returned, then nothing was written due to a stall on
- the non-blocking write destination.
+ the non-blocking write destination. The operation can be retried.
*/
ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s);
@@ -1701,7 +1708,9 @@ ZEXTERN z_off_t ZEXPORT gzseek(gzFile file,
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
- would be before the current position.
+ would be before the current position, or if the resulting position would
+ not be representable in the offset type. If gzseek returns -1, the stream
+ position is unchanged.
*/
ZEXTERN int ZEXPORT gzrewind(gzFile file);
@@ -1802,7 +1811,8 @@ ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum);
If errnum is not NULL, *errnum is set to zlib error number. If an error
occurred in the file system and not in the compression library, *errnum is
set to Z_ERRNO and the application may consult errno to get the exact error
- code.
+ code. The error is reported by gzerror() as soon as it is detected, which
+ may be before all of the data read prior to the error has been returned.
The application must not modify the returned string. Future calls to
this function may invalidate the previously returned string. If file is
@@ -1996,7 +2006,8 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
* both are true, the application gets the *64 functions, and the regular
* functions are changed to 64 bits) -- in case these are set on systems
- * without large file support, _LFS64_LARGEFILE must also be true
+ * without large file support, _LFS64_LARGEFILE must also be true, except on
+ * native Windows, where 64-bit offsets are always available
*/
#ifdef Z_LARGE64
ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *);
@@ -2053,7 +2064,7 @@ ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */
#endif /* !Z_SOLO */
-/* undocumented functions */
+/* undocumented functions (not part of the zlib API) */
ZEXTERN const char * ZEXPORT zError(int);
ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp);
ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void);
diff --git a/src/java.base/share/native/libzip/zlib/zutil.c b/src/java.base/share/native/libzip/zlib/zutil.c
index c57c162ffde8..ae5e85102786 100644
--- a/src/java.base/share/native/libzip/zlib/zutil.c
+++ b/src/java.base/share/native/libzip/zlib/zutil.c
@@ -195,7 +195,6 @@ int ZLIB_INTERNAL zmemcmp(const void FAR *s1, const void FAR *s2, z_size_t n) {
void ZLIB_INTERNAL zmemzero(void FAR *b, z_size_t len) {
uchf *p = b;
- if (len == 0) return;
while (len) {
*p++ = 0;
len--;
@@ -252,7 +251,11 @@ voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
} else {
buf = farmalloc(bsize + 16L);
}
- if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
+ if (buf == NULL) return NULL;
+ if (next_ptr >= MAX_PTR) {
+ farfree(buf);
+ return NULL;
+ }
table[next_ptr].org_ptr = buf;
/* Normalize the pointer to seg:0 */
diff --git a/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c b/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c
index 0195e1b178cf..e5deee6fe57c 100644
--- a/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c
+++ b/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -349,8 +349,12 @@ sun_jpeg_fill_suspended_buffer(j_decompress_ptr cinfo)
memmove(src->inbuf, src->pub.next_input_byte, offset);
}
RELEASE_ARRAYS(env, src);
- buflen = (*env)->GetArrayLength(env, src->hInputBuffer) - offset;
- if (buflen <= 0) {
+ buflen = (*env)->GetArrayLength(env, src->hInputBuffer);
+ if (offset > buflen) {
+ ERREXIT(cinfo, JERR_BUFFER_SIZE);
+ }
+ buflen -= offset;
+ if (buflen == 0) {
if (!GET_ARRAYS(env, src)) {
cinfo->err->error_exit((struct jpeg_common_struct *) cinfo);
}
@@ -365,6 +369,9 @@ sun_jpeg_fill_suspended_buffer(j_decompress_ptr cinfo)
if (ret <= 0) {
/* Silently accept truncated JPEG files */
WARNMS(cinfo, JWRN_JPEG_EOF);
+ if (buflen < 2) {
+ ERREXIT(cinfo, JERR_INPUT_EOF);
+ }
src->inbuf[offset] = (JOCTET) 0xFF;
src->inbuf[offset + 1] = (JOCTET) JPEG_EOI;
ret = 2;
diff --git a/test/hotspot/jtreg/compiler/vectorapi/VectorMaskCompareNotTest.java b/test/hotspot/jtreg/compiler/vectorapi/VectorMaskCompareNotTest.java
index 9a2f440ea822..a5da6a87cd72 100644
--- a/test/hotspot/jtreg/compiler/vectorapi/VectorMaskCompareNotTest.java
+++ b/test/hotspot/jtreg/compiler/vectorapi/VectorMaskCompareNotTest.java
@@ -35,7 +35,7 @@
* @library /test/lib /
* @summary test combining vector not operation with compare
* @modules jdk.incubator.vector
- * @requires vm.opt.final.MaxVectorSize == "null" | vm.opt.final.MaxVectorSize >= 16
+ * @requires vm.opt.final.MaxVectorSize == null | vm.opt.final.MaxVectorSize >= 16
*
* @run driver compiler.vectorapi.VectorMaskCompareNotTest
*/
diff --git a/test/hotspot/jtreg/compiler/vectorapi/reshape/TestVectorReinterpret.java b/test/hotspot/jtreg/compiler/vectorapi/reshape/TestVectorReinterpret.java
index 7f00fece7e61..831536a157af 100644
--- a/test/hotspot/jtreg/compiler/vectorapi/reshape/TestVectorReinterpret.java
+++ b/test/hotspot/jtreg/compiler/vectorapi/reshape/TestVectorReinterpret.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@
* @modules jdk.incubator.vector
* @modules java.base/jdk.internal.misc
* @summary Test that vector reinterpret intrinsics work as intended.
- * @requires os.arch != "riscv64" | vm.cpu.features ~= ".*rvv.*"
+ * @requires vm.opt.final.MaxVectorSize == null | vm.opt.final.MaxVectorSize >= 16
* @library /test/lib /
* @run main compiler.vectorapi.reshape.TestVectorReinterpret
*/
diff --git a/test/jdk/java/util/ServiceLoader/LinkageErrorsTest.java b/test/jdk/java/util/ServiceLoader/LinkageErrorsTest.java
index 209dce752673..7de8eb29ebdc 100644
--- a/test/jdk/java/util/ServiceLoader/LinkageErrorsTest.java
+++ b/test/jdk/java/util/ServiceLoader/LinkageErrorsTest.java
@@ -51,61 +51,6 @@
class LinkageErrorsTest {
- /**
- * Test iteration over service providers when loading a service provider class
- * fails with a linkage error.
- */
- @Test
- void testLoadClassThrows() throws Exception {
- Map sources = Map.of(
- "Service",
- """
- public interface Service {}
- """,
- "Super",
- """
- class Super {}
- """,
- "Provider1",
- """
- public class Provider1 implements Service {
- public Provider1() {}
- }
- """,
- "Provider2",
- """
- public class Provider2 extends Super implements Service {
- public Provider2() {}
- }
- """
- );
- Path classesDir = compile(sources);
-
- // delete Provider2's super class to prevent Provider2 from loading
- Files.delete(classesDir.resolve("Super.class"));
-
- // create services configuration file that lists two providers
- createServicesConfigFile(classesDir, "Service", "Provider1", "Provider2");
-
- // load the service interface
- var loader = new URLClassLoader(new URL[] { classesDir.toUri().toURL() });
- Class> service = loader.loadClass("Service");
- assertSame(loader, service.getClassLoader());
-
- // find and collect all service providers and ServiceConfigurationErrors
- var providers = new ArrayList