Skip to content

Commit 9f8bfab

Browse files
committed
8288537: Move Devirtualizer out of hotspot/share/memory/iterator.hpp
Reviewed-by: stefank, coleenp
1 parent f080430 commit 9f8bfab

15 files changed

+233
-160
lines changed

src/hotspot/share/gc/serial/defNewGeneration.inline.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, 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
@@ -32,6 +32,7 @@
3232
#include "gc/shared/genOopClosures.inline.hpp"
3333
#include "gc/shared/space.inline.hpp"
3434
#include "oops/access.inline.hpp"
35+
#include "utilities/devirtualizer.inline.hpp"
3536

3637
// Methods of protected closure types
3738

src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
3434
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
3535
#include "gc/shenandoah/shenandoahNMethod.inline.hpp"
36+
#include "memory/iterator.inline.hpp"
3637
#include "oops/compressedOops.inline.hpp"
3738
#include "runtime/atomic.hpp"
3839
#include "runtime/thread.hpp"

src/hotspot/share/gc/shenandoah/shenandoahMark.inline.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "oops/compressedOops.inline.hpp"
4040
#include "oops/oop.inline.hpp"
4141
#include "runtime/prefetch.inline.hpp"
42+
#include "utilities/devirtualizer.inline.hpp"
4243
#include "utilities/powerOfTwo.hpp"
4344

4445
template <StringDedupMode STRING_DEDUP>

src/hotspot/share/memory/iterator.hpp

-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "memory/allocation.hpp"
2929
#include "memory/memRegion.hpp"
3030
#include "oops/oopsHierarchy.hpp"
31-
#include "utilities/bitMap.hpp"
3231

3332
class CodeBlob;
3433
class nmethod;
@@ -370,18 +369,6 @@ class CompareClosure : public Closure {
370369
virtual int do_compare(const E&, const E&) = 0;
371370
};
372371

373-
// Dispatches to the non-virtual functions if OopClosureType has
374-
// a concrete implementation, otherwise a virtual call is taken.
375-
class Devirtualizer {
376-
public:
377-
template <typename OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p);
378-
template <typename OopClosureType> static void do_klass(OopClosureType* closure, Klass* k);
379-
template <typename OopClosureType> static void do_cld(OopClosureType* closure, ClassLoaderData* cld);
380-
template <typename OopClosureType> static bool do_metadata(OopClosureType* closure);
381-
template <typename DerivedOopClosureType> static void do_derived_oop(DerivedOopClosureType* closure, oop* base, derived_pointer* derived);
382-
template <typename BitMapClosureType> static bool do_bit(BitMapClosureType* closure, BitMap::idx_t index);
383-
};
384-
385372
class OopIteratorClosureDispatch {
386373
public:
387374
template <typename OopClosureType> static void oop_oop_iterate(OopClosureType* cl, oop obj, Klass* klass);

src/hotspot/share/memory/iterator.inline.hpp

-136
Original file line numberDiff line numberDiff line change
@@ -63,142 +63,6 @@ inline void ClaimMetadataVisitingOopIterateClosure::do_method(Method* m) {
6363
m->record_gc_epoch();
6464
}
6565

66-
// Implementation of the non-virtual do_oop dispatch.
67-
//
68-
// The same implementation is used for do_metadata, do_klass, and do_cld.
69-
//
70-
// Preconditions:
71-
// - Base has a pure virtual do_oop
72-
// - Only one of the classes in the inheritance chain from OopClosureType to
73-
// Base implements do_oop.
74-
//
75-
// Given the preconditions:
76-
// - If &OopClosureType::do_oop is resolved to &Base::do_oop, then there is no
77-
// implementation of do_oop between Base and OopClosureType. However, there
78-
// must be one implementation in one of the subclasses of OopClosureType.
79-
// In this case we take the virtual call.
80-
//
81-
// - Conversely, if &OopClosureType::do_oop is not resolved to &Base::do_oop,
82-
// then we've found the one and only concrete implementation. In this case we
83-
// take a non-virtual call.
84-
//
85-
// Because of this it's clear when we should call the virtual call and
86-
// when the non-virtual call should be made.
87-
//
88-
// The way we find if &OopClosureType::do_oop is resolved to &Base::do_oop is to
89-
// check if the resulting type of the class of a member-function pointer to
90-
// &OopClosureType::do_oop is equal to the type of the class of a
91-
// &Base::do_oop member-function pointer. Template parameter deduction is used
92-
// to find these types, and then the IsSame trait is used to check if they are
93-
// equal. Finally, SFINAE is used to select the appropriate implementation.
94-
//
95-
// Template parameters:
96-
// T - narrowOop or oop
97-
// Receiver - the resolved type of the class of the
98-
// &OopClosureType::do_oop member-function pointer. That is,
99-
// the klass with the do_oop member function.
100-
// Base - klass with the pure virtual do_oop member function.
101-
// OopClosureType - The dynamic closure type
102-
//
103-
// Parameters:
104-
// closure - The closure to call
105-
// p - The oop (or narrowOop) field to pass to the closure
106-
107-
template <typename T, typename Receiver, typename Base, typename OopClosureType>
108-
static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
109-
call_do_oop(void (Receiver::*)(T*), void (Base::*)(T*), OopClosureType* closure, T* p) {
110-
closure->do_oop(p);
111-
}
112-
113-
template <typename T, typename Receiver, typename Base, typename OopClosureType>
114-
static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
115-
call_do_oop(void (Receiver::*)(T*), void (Base::*)(T*), OopClosureType* closure, T* p) {
116-
// Sanity check
117-
STATIC_ASSERT((!IsSame<OopClosureType, OopIterateClosure>::value));
118-
closure->OopClosureType::do_oop(p);
119-
}
120-
121-
template <typename OopClosureType, typename T>
122-
inline void Devirtualizer::do_oop(OopClosureType* closure, T* p) {
123-
call_do_oop<T>(&OopClosureType::do_oop, &OopClosure::do_oop, closure, p);
124-
}
125-
126-
// Implementation of the non-virtual do_metadata dispatch.
127-
128-
template <typename Receiver, typename Base, typename OopClosureType>
129-
static typename EnableIf<IsSame<Receiver, Base>::value, bool>::type
130-
call_do_metadata(bool (Receiver::*)(), bool (Base::*)(), OopClosureType* closure) {
131-
return closure->do_metadata();
132-
}
133-
134-
template <typename Receiver, typename Base, typename OopClosureType>
135-
static typename EnableIf<!IsSame<Receiver, Base>::value, bool>::type
136-
call_do_metadata(bool (Receiver::*)(), bool (Base::*)(), OopClosureType* closure) {
137-
return closure->OopClosureType::do_metadata();
138-
}
139-
140-
template <typename OopClosureType>
141-
inline bool Devirtualizer::do_metadata(OopClosureType* closure) {
142-
return call_do_metadata(&OopClosureType::do_metadata, &OopIterateClosure::do_metadata, closure);
143-
}
144-
145-
// Implementation of the non-virtual do_klass dispatch.
146-
147-
template <typename Receiver, typename Base, typename OopClosureType>
148-
static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
149-
call_do_klass(void (Receiver::*)(Klass*), void (Base::*)(Klass*), OopClosureType* closure, Klass* k) {
150-
closure->do_klass(k);
151-
}
152-
153-
template <typename Receiver, typename Base, typename OopClosureType>
154-
static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
155-
call_do_klass(void (Receiver::*)(Klass*), void (Base::*)(Klass*), OopClosureType* closure, Klass* k) {
156-
closure->OopClosureType::do_klass(k);
157-
}
158-
159-
template <typename OopClosureType>
160-
inline void Devirtualizer::do_klass(OopClosureType* closure, Klass* k) {
161-
call_do_klass(&OopClosureType::do_klass, &OopIterateClosure::do_klass, closure, k);
162-
}
163-
164-
// Implementation of the non-virtual do_cld dispatch.
165-
166-
template <typename Receiver, typename Base, typename OopClosureType>
167-
static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
168-
call_do_cld(void (Receiver::*)(ClassLoaderData*), void (Base::*)(ClassLoaderData*), OopClosureType* closure, ClassLoaderData* cld) {
169-
closure->do_cld(cld);
170-
}
171-
172-
template <typename Receiver, typename Base, typename OopClosureType>
173-
static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
174-
call_do_cld(void (Receiver::*)(ClassLoaderData*), void (Base::*)(ClassLoaderData*), OopClosureType* closure, ClassLoaderData* cld) {
175-
closure->OopClosureType::do_cld(cld);
176-
}
177-
178-
template <typename OopClosureType>
179-
void Devirtualizer::do_cld(OopClosureType* closure, ClassLoaderData* cld) {
180-
call_do_cld(&OopClosureType::do_cld, &OopIterateClosure::do_cld, closure, cld);
181-
}
182-
183-
// Implementation of the non-virtual do_derived_oop dispatch.
184-
185-
template <typename Receiver, typename Base, typename DerivedOopClosureType>
186-
static typename EnableIf<IsSame<Receiver, Base>::value, void>::type
187-
call_do_derived_oop(void (Receiver::*)(oop*, derived_pointer*), void (Base::*)(oop*, derived_pointer*), DerivedOopClosureType* closure, oop* base, derived_pointer* derived) {
188-
closure->do_derived_oop(base, derived);
189-
}
190-
191-
template <typename Receiver, typename Base, typename DerivedOopClosureType>
192-
static typename EnableIf<!IsSame<Receiver, Base>::value, void>::type
193-
call_do_derived_oop(void (Receiver::*)(oop*, derived_pointer*), void (Base::*)(oop*, derived_pointer*), DerivedOopClosureType* closure, oop* base, derived_pointer* derived) {
194-
closure->DerivedOopClosureType::do_derived_oop(base, derived);
195-
}
196-
197-
template <typename DerivedOopClosureType>
198-
inline void Devirtualizer::do_derived_oop(DerivedOopClosureType* closure, oop* base, derived_pointer* derived) {
199-
call_do_derived_oop(&DerivedOopClosureType::do_derived_oop, &DerivedOopClosure::do_derived_oop, closure, base, derived);
200-
}
201-
20266
// Dispatch table implementation for *Klass::oop_oop_iterate
20367
//
20468
// It allows for a single call to do a multi-dispatch to an optimized version

src/hotspot/share/oops/instanceClassLoaderKlass.inline.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, 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
@@ -28,10 +28,10 @@
2828
#include "oops/instanceClassLoaderKlass.hpp"
2929

3030
#include "classfile/javaClasses.hpp"
31-
#include "memory/iterator.hpp"
3231
#include "oops/instanceKlass.inline.hpp"
3332
#include "oops/oop.inline.hpp"
3433
#include "utilities/debug.hpp"
34+
#include "utilities/devirtualizer.inline.hpp"
3535
#include "utilities/globalDefinitions.hpp"
3636
#include "utilities/macros.hpp"
3737

src/hotspot/share/oops/instanceKlass.inline.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, 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
@@ -29,12 +29,12 @@
2929

3030
#include "classfile/javaClasses.hpp"
3131
#include "classfile/vmSymbols.hpp"
32-
#include "memory/iterator.hpp"
3332
#include "memory/resourceArea.hpp"
3433
#include "oops/klass.inline.hpp"
3534
#include "oops/oop.inline.hpp"
3635
#include "runtime/atomic.hpp"
3736
#include "utilities/debug.hpp"
37+
#include "utilities/devirtualizer.inline.hpp"
3838
#include "utilities/globalDefinitions.hpp"
3939
#include "utilities/macros.hpp"
4040

src/hotspot/share/oops/instanceMirrorKlass.inline.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, 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
@@ -32,6 +32,7 @@
3232
#include "oops/klass.hpp"
3333
#include "oops/oop.inline.hpp"
3434
#include "utilities/debug.hpp"
35+
#include "utilities/devirtualizer.inline.hpp"
3536
#include "utilities/globalDefinitions.hpp"
3637
#include "utilities/macros.hpp"
3738

src/hotspot/share/oops/instanceRefKlass.inline.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, 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
@@ -34,6 +34,7 @@
3434
#include "oops/instanceKlass.inline.hpp"
3535
#include "oops/oop.inline.hpp"
3636
#include "utilities/debug.hpp"
37+
#include "utilities/devirtualizer.inline.hpp"
3738
#include "utilities/globalDefinitions.hpp"
3839
#include "utilities/macros.hpp"
3940

src/hotspot/share/oops/instanceStackChunkKlass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "classfile/javaClasses.inline.hpp"
2727
#include "classfile/vmClasses.hpp"
2828
#include "compiler/oopMap.inline.hpp"
29-
#include "memory/iterator.inline.hpp"
3029
#include "memory/oopFactory.hpp"
3130
#include "memory/resourceArea.hpp"
3231
#include "oops/instanceStackChunkKlass.inline.hpp"
@@ -37,6 +36,7 @@
3736
#include "runtime/registerMap.hpp"
3837
#include "runtime/smallRegisterMap.inline.hpp"
3938
#include "runtime/stackChunkFrameStream.inline.hpp"
39+
#include "utilities/devirtualizer.inline.hpp"
4040
#include "utilities/globalDefinitions.hpp"
4141
#include "utilities/macros.hpp"
4242
#include "utilities/ostream.hpp"

src/hotspot/share/oops/instanceStackChunkKlass.inline.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "gc/shared/collectedHeap.hpp"
3636
#include "gc/shared/gc_globals.hpp"
3737
#include "logging/log.hpp"
38-
#include "memory/iterator.inline.hpp"
3938
#include "oops/instanceKlass.inline.hpp"
4039
#include "oops/klass.hpp"
4140
#include "oops/oop.inline.hpp"
@@ -47,6 +46,7 @@
4746
#include "runtime/stackChunkFrameStream.inline.hpp"
4847
#include "utilities/bitMap.inline.hpp"
4948
#include "utilities/debug.hpp"
49+
#include "utilities/devirtualizer.inline.hpp"
5050
#include "utilities/globalDefinitions.hpp"
5151
#include "utilities/macros.hpp"
5252

src/hotspot/share/oops/objArrayKlass.inline.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, 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
@@ -28,12 +28,12 @@
2828
#include "oops/objArrayKlass.hpp"
2929

3030
#include "memory/memRegion.hpp"
31-
#include "memory/iterator.hpp"
3231
#include "oops/arrayKlass.hpp"
3332
#include "oops/arrayOop.hpp"
3433
#include "oops/klass.hpp"
3534
#include "oops/objArrayOop.inline.hpp"
3635
#include "oops/oop.inline.hpp"
36+
#include "utilities/devirtualizer.inline.hpp"
3737
#include "utilities/macros.hpp"
3838

3939
template <typename T, class OopClosureType>

src/hotspot/share/runtime/stackChunkFrameStream.inline.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "oops/instanceStackChunkKlass.inline.hpp"
3636
#include "runtime/frame.inline.hpp"
3737
#include "utilities/debug.hpp"
38+
#include "utilities/devirtualizer.inline.hpp"
3839
#include "utilities/globalDefinitions.hpp"
3940
#include "utilities/macros.hpp"
4041
#include CPU_HEADER_INLINE(stackChunkFrameStream)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#ifndef SHARE_UTILITIES_DEVIRTUALIZER_HPP
26+
#define SHARE_UTILITIES_DEVIRTUALIZER_HPP
27+
28+
#include "oops/oopsHierarchy.hpp"
29+
#include "utilities/bitMap.hpp"
30+
31+
class ClassLoaderData;
32+
33+
// Dispatches to the non-virtual functions if OopClosureType has
34+
// a concrete implementation, otherwise a virtual call is taken.
35+
class Devirtualizer {
36+
public:
37+
template <typename OopClosureType, typename T> static void do_oop(OopClosureType* closure, T* p);
38+
template <typename OopClosureType> static void do_klass(OopClosureType* closure, Klass* k);
39+
template <typename OopClosureType> static void do_cld(OopClosureType* closure, ClassLoaderData* cld);
40+
template <typename OopClosureType> static bool do_metadata(OopClosureType* closure);
41+
template <typename DerivedOopClosureType> static void do_derived_oop(DerivedOopClosureType* closure, oop* base, derived_pointer* derived);
42+
template <typename BitMapClosureType> static bool do_bit(BitMapClosureType* closure, BitMap::idx_t index);
43+
};
44+
45+
#endif // SHARE_UTILITIES_DEVIRTUALIZER_HPP

0 commit comments

Comments
 (0)