Skip to content

Commit 87131fb

Browse files
committed
8329629: GC interfaces should work directly against nmethod instead of CodeBlob
Reviewed-by: ayang, eosterlund
1 parent 5ea21c3 commit 87131fb

File tree

72 files changed

+332
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+332
-412
lines changed

src/hotspot/share/code/codeCache.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,14 @@ void CodeCache::nmethods_do(void f(nmethod* nm)) {
685685
}
686686
}
687687

688+
void CodeCache::nmethods_do(NMethodClosure* cl) {
689+
assert_locked_or_safepoint(CodeCache_lock);
690+
NMethodIterator iter(NMethodIterator::all_blobs);
691+
while(iter.next()) {
692+
cl->do_nmethod(iter.method());
693+
}
694+
}
695+
688696
void CodeCache::metadata_do(MetadataClosure* f) {
689697
assert_locked_or_safepoint(CodeCache_lock);
690698
NMethodIterator iter(NMethodIterator::all_blobs);
@@ -883,20 +891,6 @@ void CodeCache::do_unloading(bool unloading_occurred) {
883891
}
884892
}
885893

886-
void CodeCache::blobs_do(CodeBlobClosure* f) {
887-
assert_locked_or_safepoint(CodeCache_lock);
888-
FOR_ALL_ALLOCABLE_HEAPS(heap) {
889-
FOR_ALL_BLOBS(cb, *heap) {
890-
f->do_code_blob(cb);
891-
#ifdef ASSERT
892-
if (cb->is_nmethod()) {
893-
Universe::heap()->verify_nmethod((nmethod*)cb);
894-
}
895-
#endif //ASSERT
896-
}
897-
}
898-
}
899-
900894
void CodeCache::verify_clean_inline_caches() {
901895
#ifdef ASSERT
902896
NMethodIterator iter(NMethodIterator::only_not_unloading);

src/hotspot/share/code/codeCache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ class CodeCache : AllStatic {
153153
static bool contains(void *p); // returns whether p is included
154154
static bool contains(nmethod* nm); // returns whether nm is included
155155
static void blobs_do(void f(CodeBlob* cb)); // iterates over all CodeBlobs
156-
static void blobs_do(CodeBlobClosure* f); // iterates over all CodeBlobs
157156
static void nmethods_do(void f(nmethod* nm)); // iterates over all nmethods
157+
static void nmethods_do(NMethodClosure* cl); // iterates over all nmethods
158158
static void metadata_do(MetadataClosure* f); // iterates over metadata in alive nmethods
159159

160160
// Lookup

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class G1CodeRootSetHashTable : public CHeapObj<mtGC> {
152152
clean(always_true);
153153
}
154154

155-
void iterate_at_safepoint(CodeBlobClosure* blk) {
155+
void iterate_at_safepoint(NMethodClosure* blk) {
156156
assert_at_safepoint();
157157
// A lot of code root sets are typically empty.
158158
if (is_empty()) {
@@ -161,7 +161,7 @@ class G1CodeRootSetHashTable : public CHeapObj<mtGC> {
161161

162162
auto do_value =
163163
[&] (nmethod** value) {
164-
blk->do_code_blob(*value);
164+
blk->do_nmethod(*value);
165165
return true;
166166
};
167167
_table_scanner.do_safepoint_scan(do_value);
@@ -288,7 +288,7 @@ void G1CodeRootSet::reset_table_scanner() {
288288
_table->reset_table_scanner();
289289
}
290290

291-
void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const {
291+
void G1CodeRootSet::nmethods_do(NMethodClosure* blk) const {
292292
DEBUG_ONLY(_is_iterating = true;)
293293
_table->iterate_at_safepoint(blk);
294294
DEBUG_ONLY(_is_iterating = false;)
@@ -317,14 +317,14 @@ class CleanCallback : public StackObj {
317317
};
318318

319319
PointsIntoHRDetectionClosure _detector;
320-
CodeBlobToOopClosure _blobs;
320+
NMethodToOopClosure _nmethod_cl;
321321

322322
public:
323-
CleanCallback(HeapRegion* hr) : _detector(hr), _blobs(&_detector, !CodeBlobToOopClosure::FixRelocations) {}
323+
CleanCallback(HeapRegion* hr) : _detector(hr), _nmethod_cl(&_detector, !NMethodToOopClosure::FixRelocations) {}
324324

325325
bool operator()(nmethod** value) {
326326
_detector._points_into = false;
327-
_blobs.do_code_blob(*value);
327+
_nmethod_cl.do_nmethod(*value);
328328
return !_detector._points_into;
329329
}
330330
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class G1CodeRootSet {
5050

5151
// Prepare for MT iteration. Must be called before nmethods_do.
5252
void reset_table_scanner();
53-
void nmethods_do(CodeBlobClosure* blk) const;
53+
void nmethods_do(NMethodClosure* blk) const;
5454

5555
// Remove all nmethods which no longer contain pointers into our "owner" region.
5656
void clean(HeapRegion* owner);

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,7 @@ void G1CollectedHeap::unload_classes_and_code(const char* description, BoolObjec
25182518

25192519
ClassUnloadingContext ctx(workers()->active_workers(),
25202520
false /* unregister_nmethods_during_purge */,
2521-
false /* lock_codeblob_free_separately */);
2521+
false /* lock_nmethod_free_separately */);
25222522
{
25232523
CodeCache::UnlinkingScope scope(is_alive);
25242524
bool unloading_occurred = SystemDictionary::do_unloading(timer);
@@ -2535,7 +2535,7 @@ void G1CollectedHeap::unload_classes_and_code(const char* description, BoolObjec
25352535
}
25362536
{
25372537
GCTraceTime(Debug, gc, phases) t("Free Code Blobs", timer);
2538-
ctx.free_code_blobs();
2538+
ctx.free_nmethods();
25392539
}
25402540
{
25412541
GCTraceTime(Debug, gc, phases) t("Purge Class Loader Data", timer);
@@ -3016,24 +3016,22 @@ void G1CollectedHeap::update_used_after_gc(bool evacuation_failed) {
30163016
}
30173017
}
30183018

3019-
class RebuildCodeRootClosure: public CodeBlobClosure {
3019+
class RebuildCodeRootClosure: public NMethodClosure {
30203020
G1CollectedHeap* _g1h;
30213021

30223022
public:
30233023
RebuildCodeRootClosure(G1CollectedHeap* g1h) :
30243024
_g1h(g1h) {}
30253025

3026-
void do_code_blob(CodeBlob* cb) {
3027-
nmethod* nm = cb->as_nmethod_or_null();
3028-
if (nm != nullptr) {
3029-
_g1h->register_nmethod(nm);
3030-
}
3026+
void do_nmethod(nmethod* nm) {
3027+
assert(nm != nullptr, "Sanity");
3028+
_g1h->register_nmethod(nm);
30313029
}
30323030
};
30333031

30343032
void G1CollectedHeap::rebuild_code_roots() {
3035-
RebuildCodeRootClosure blob_cl(this);
3036-
CodeCache::blobs_do(&blob_cl);
3033+
RebuildCodeRootClosure nmethod_cl(this);
3034+
CodeCache::nmethods_do(&nmethod_cl);
30373035
}
30383036

30393037
void G1CollectedHeap::initialize_serviceability() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void G1FullGCAdjustTask::work(uint worker_id) {
101101
}
102102

103103
CLDToOopClosure adjust_cld(&_adjust, ClassLoaderData::_claim_stw_fullgc_adjust);
104-
CodeBlobToOopClosure adjust_code(&_adjust, CodeBlobToOopClosure::FixRelocations);
104+
NMethodToOopClosure adjust_code(&_adjust, NMethodToOopClosure::FixRelocations);
105105
_root_processor.process_all_roots(&_adjust, &adjust_cld, &adjust_code);
106106

107107
// Now adjust pointers region by region

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void G1FullGCMarkTask::work(uint worker_id) {
4242
Ticks start = Ticks::now();
4343
ResourceMark rm;
4444
G1FullGCMarker* marker = collector()->marker(worker_id);
45-
MarkingCodeBlobClosure code_closure(marker->mark_closure(), !CodeBlobToOopClosure::FixRelocations, true /* keepalive nmethods */);
45+
MarkingNMethodClosure code_closure(marker->mark_closure(), !NMethodToOopClosure::FixRelocations, true /* keepalive nmethods */);
4646

4747
if (ClassUnloading) {
4848
_root_processor.process_strong_roots(marker->mark_closure(),

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void HeapRegion::remove_code_root(nmethod* nm) {
286286
rem_set()->remove_code_root(nm);
287287
}
288288

289-
void HeapRegion::code_roots_do(CodeBlobClosure* blk) const {
289+
void HeapRegion::code_roots_do(NMethodClosure* blk) const {
290290
rem_set()->code_roots_do(blk);
291291
}
292292

@@ -328,28 +328,27 @@ class VerifyCodeRootOopClosure: public OopClosure {
328328
bool has_oops_in_region() { return _has_oops_in_region; }
329329
};
330330

331-
class VerifyCodeRootCodeBlobClosure: public CodeBlobClosure {
331+
class VerifyCodeRootNMethodClosure: public NMethodClosure {
332332
const HeapRegion* _hr;
333333
bool _failures;
334334
public:
335-
VerifyCodeRootCodeBlobClosure(const HeapRegion* hr) :
335+
VerifyCodeRootNMethodClosure(const HeapRegion* hr) :
336336
_hr(hr), _failures(false) {}
337337

338-
void do_code_blob(CodeBlob* cb) {
339-
nmethod* nm = (cb == nullptr) ? nullptr : cb->as_nmethod_or_null();
340-
if (nm != nullptr) {
341-
// Verify that the nemthod is live
342-
VerifyCodeRootOopClosure oop_cl(_hr);
343-
nm->oops_do(&oop_cl);
344-
if (!oop_cl.has_oops_in_region()) {
345-
log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its code roots with no pointers into region",
346-
p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
347-
_failures = true;
348-
} else if (oop_cl.failures()) {
349-
log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has other failures for nmethod " PTR_FORMAT,
350-
p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
351-
_failures = true;
352-
}
338+
void do_nmethod(nmethod* nm) {
339+
assert(nm != nullptr, "Sanity");
340+
341+
// Verify that the nmethod is live
342+
VerifyCodeRootOopClosure oop_cl(_hr);
343+
nm->oops_do(&oop_cl);
344+
if (!oop_cl.has_oops_in_region()) {
345+
log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its code roots with no pointers into region",
346+
p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
347+
_failures = true;
348+
} else if (oop_cl.failures()) {
349+
log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has other failures for nmethod " PTR_FORMAT,
350+
p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
351+
_failures = true;
353352
}
354353
}
355354

@@ -395,10 +394,10 @@ bool HeapRegion::verify_code_roots(VerifyOption vo) const {
395394
return has_code_roots;
396395
}
397396

398-
VerifyCodeRootCodeBlobClosure cb_cl(this);
399-
code_roots_do(&cb_cl);
397+
VerifyCodeRootNMethodClosure nm_cl(this);
398+
code_roots_do(&nm_cl);
400399

401-
return cb_cl.failures();
400+
return nm_cl.failures();
402401
}
403402

404403
void HeapRegion::print() const { print_on(tty); }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ class HeapRegion : public CHeapObj<mtGC> {
540540
void add_code_root(nmethod* nm);
541541
void remove_code_root(nmethod* nm);
542542

543-
// Applies blk->do_code_blob() to each of the entries in
543+
// Applies blk->do_nmethod() to each of the entries in
544544
// the code roots list for this region
545-
void code_roots_do(CodeBlobClosure* blk) const;
545+
void code_roots_do(NMethodClosure* blk) const;
546546

547547
uint node_index() const { return _node_index; }
548548
void set_node_index(uint node_index) { _node_index = node_index; }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void HeapRegionRemSet::bulk_remove_code_roots() {
119119
_code_roots.bulk_remove();
120120
}
121121

122-
void HeapRegionRemSet::code_roots_do(CodeBlobClosure* blk) const {
122+
void HeapRegionRemSet::code_roots_do(NMethodClosure* blk) const {
123123
_code_roots.nmethods_do(blk);
124124
}
125125

0 commit comments

Comments
 (0)