Skip to content

Commit 9a36f8a

Browse files
fiskstefankxmas92
committed
8299673: Simplify object pinning interactions with string deduplication
Co-authored-by: Stefan Karlsson <stefank@openjdk.org> Co-authored-by: Axel Boldt-Christmas <aboldtch@openjdk.org> Reviewed-by: kbarrett, stefank, dholmes
1 parent 3462438 commit 9a36f8a

File tree

14 files changed

+85
-88
lines changed

14 files changed

+85
-88
lines changed

src/hotspot/share/gc/epsilon/epsilonHeap.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ class EpsilonHeap : public CollectedHeap {
110110
void object_iterate(ObjectClosure* cl) override;
111111

112112
// Object pinning support: every object is implicitly pinned
113-
bool supports_object_pinning() const override { return true; }
114-
oop pin_object(JavaThread* thread, oop obj) override { return obj; }
113+
void pin_object(JavaThread* thread, oop obj) override { }
115114
void unpin_object(JavaThread* thread, oop obj) override { }
116115

117116
// No support for block parsing.

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
#include "gc/shared/gcBehaviours.hpp"
8080
#include "gc/shared/gcHeapSummary.hpp"
8181
#include "gc/shared/gcId.hpp"
82-
#include "gc/shared/gcLocker.hpp"
82+
#include "gc/shared/gcLocker.inline.hpp"
8383
#include "gc/shared/gcTimer.hpp"
8484
#include "gc/shared/gcTraceTime.inline.hpp"
8585
#include "gc/shared/generationSpec.hpp"
@@ -2399,6 +2399,14 @@ bool G1CollectedHeap::is_obj_dead_cond(const oop obj,
23992399
return false; // keep some compilers happy
24002400
}
24012401

2402+
void G1CollectedHeap::pin_object(JavaThread* thread, oop obj) {
2403+
GCLocker::lock_critical(thread);
2404+
}
2405+
2406+
void G1CollectedHeap::unpin_object(JavaThread* thread, oop obj) {
2407+
GCLocker::unlock_critical(thread);
2408+
}
2409+
24022410
void G1CollectedHeap::print_heap_regions() const {
24032411
LogTarget(Trace, gc, heap, region) lt;
24042412
if (lt.is_enabled()) {

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,9 @@ class G1CollectedHeap : public CollectedHeap {
13121312
G1HeapSummary create_g1_heap_summary();
13131313
G1EvacSummary create_g1_evac_summary(G1EvacStats* stats);
13141314

1315+
void pin_object(JavaThread* thread, oop obj) override;
1316+
void unpin_object(JavaThread* thread, oop obj) override;
1317+
13151318
// Printing
13161319
private:
13171320
void print_heap_regions() const;

src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,7 @@
3535
#include "gc/parallel/psScavenge.hpp"
3636
#include "gc/parallel/psVMOperations.hpp"
3737
#include "gc/shared/gcHeapSummary.hpp"
38-
#include "gc/shared/gcLocker.hpp"
38+
#include "gc/shared/gcLocker.inline.hpp"
3939
#include "gc/shared/gcWhen.hpp"
4040
#include "gc/shared/genArguments.hpp"
4141
#include "gc/shared/gcInitLogger.hpp"
@@ -860,3 +860,11 @@ GrowableArray<MemoryPool*> ParallelScavengeHeap::memory_pools() {
860860
memory_pools.append(_old_pool);
861861
return memory_pools;
862862
}
863+
864+
void ParallelScavengeHeap::pin_object(JavaThread* thread, oop obj) {
865+
GCLocker::lock_critical(thread);
866+
}
867+
868+
void ParallelScavengeHeap::unpin_object(JavaThread* thread, oop obj) {
869+
GCLocker::unlock_critical(thread);
870+
}

src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class ParallelScavengeHeap : public CollectedHeap {
273273
bool can_load_archived_objects() const override { return UseCompressedOops; }
274274
HeapWord* allocate_loaded_archive_space(size_t size) override;
275275
void complete_loaded_archive_space(MemRegion archive_space) override;
276+
277+
void pin_object(JavaThread* thread, oop obj) override;
278+
void unpin_object(JavaThread* thread, oop obj) override;
276279
};
277280

278281
// Class that can be used to print information about the

src/hotspot/share/gc/serial/serialHeap.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
#include "gc/serial/defNewGeneration.inline.hpp"
2727
#include "gc/serial/serialHeap.hpp"
2828
#include "gc/serial/tenuredGeneration.inline.hpp"
29+
#include "gc/shared/gcLocker.inline.hpp"
2930
#include "gc/shared/genMemoryPools.hpp"
3031
#include "gc/shared/strongRootsScope.hpp"
3132
#include "gc/shared/suspendibleThreadSet.hpp"
@@ -123,3 +124,11 @@ void SerialHeap::complete_loaded_archive_space(MemRegion archive_space) {
123124
assert(old_gen()->used_region().contains(archive_space), "Archive space not contained in old gen");
124125
old_gen()->complete_loaded_archive_space(archive_space);
125126
}
127+
128+
void SerialHeap::pin_object(JavaThread* thread, oop obj) {
129+
GCLocker::lock_critical(thread);
130+
}
131+
132+
void SerialHeap::unpin_object(JavaThread* thread, oop obj) {
133+
GCLocker::unlock_critical(thread);
134+
}

src/hotspot/share/gc/serial/serialHeap.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class SerialHeap : public GenCollectedHeap {
108108
bool can_load_archived_objects() const override { return UseCompressedOops; }
109109
HeapWord* allocate_loaded_archive_space(size_t size) override;
110110
void complete_loaded_archive_space(MemRegion archive_space) override;
111+
112+
void pin_object(JavaThread* thread, oop obj) override;
113+
void unpin_object(JavaThread* thread, oop obj) override;
111114
};
112115

113116
#endif // SHARE_GC_SERIAL_SERIALHEAP_HPP

src/hotspot/share/gc/shared/collectedHeap.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -635,19 +635,6 @@ void CollectedHeap::reset_promotion_should_fail() {
635635

636636
#endif // #ifndef PRODUCT
637637

638-
bool CollectedHeap::supports_object_pinning() const {
639-
return false;
640-
}
641-
642-
oop CollectedHeap::pin_object(JavaThread* thread, oop obj) {
643-
ShouldNotReachHere();
644-
return NULL;
645-
}
646-
647-
void CollectedHeap::unpin_object(JavaThread* thread, oop obj) {
648-
ShouldNotReachHere();
649-
}
650-
651638
bool CollectedHeap::is_archived_object(oop object) const {
652639
return false;
653640
}

src/hotspot/share/gc/shared/collectedHeap.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -501,11 +501,11 @@ class CollectedHeap : public CHeapObj<mtGC> {
501501
virtual WorkerThreads* safepoint_workers() { return NULL; }
502502

503503
// Support for object pinning. This is used by JNI Get*Critical()
504-
// and Release*Critical() family of functions. If supported, the GC
505-
// must guarantee that pinned objects never move.
506-
virtual bool supports_object_pinning() const;
507-
virtual oop pin_object(JavaThread* thread, oop obj);
508-
virtual void unpin_object(JavaThread* thread, oop obj);
504+
// and Release*Critical() family of functions. The GC must guarantee
505+
// that pinned objects never move and don't get reclaimed as garbage.
506+
// These functions are potentially safepointing.
507+
virtual void pin_object(JavaThread* thread, oop obj) = 0;
508+
virtual void unpin_object(JavaThread* thread, oop obj) = 0;
509509

510510
// Is the given object inside a CDS archive area?
511511
virtual bool is_archived_object(oop object) const;

src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
23
* Copyright (c) 2013, 2022, Red Hat, Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
@@ -1916,9 +1917,8 @@ void ShenandoahHeap::unregister_nmethod(nmethod* nm) {
19161917
ShenandoahCodeRoots::unregister_nmethod(nm);
19171918
}
19181919

1919-
oop ShenandoahHeap::pin_object(JavaThread* thr, oop o) {
1920+
void ShenandoahHeap::pin_object(JavaThread* thr, oop o) {
19201921
heap_region_containing(o)->record_pin();
1921-
return o;
19221922
}
19231923

19241924
void ShenandoahHeap::unpin_object(JavaThread* thr, oop o) {

0 commit comments

Comments
 (0)