RFR: 8234779: Provide idiom for declaring classes noncopyable
Stefan Karlsson
stefan.karlsson at oracle.com
Wed Nov 27 08:34:41 UTC 2019
Hi Kim,
On 2019-11-27 01:18, Kim Barrett wrote:
> Please review this change that adds a new macro NONCOPYABLE, for
> declaring a class to be noncopyable. This change also modifies a
> bunch of classes to use the new macro. Most of those classes already
> included equivalent code, and we're just replacing that with uses of
> the macro.
Did you consider doing something like this instead of using this macro?
diff --git a/src/hotspot/share/runtime/semaphore.hpp
b/src/hotspot/share/runtime/semaphore.hpp
--- a/src/hotspot/share/runtime/semaphore.hpp
+++ b/src/hotspot/share/runtime/semaphore.hpp
@@ -44,8 +44,7 @@
SemaphoreImpl _impl;
// Prevent copying and assignment of Semaphore instances.
- Semaphore(const Semaphore&);
- Semaphore& operator=(const Semaphore&);
+ NonCopyable _copy_poison;
public:
Semaphore(uint value = 0) : _impl(value) {}
@@ -60,4 +59,10 @@
void wait_with_safepoint_check(JavaThread* thread);
};
+void test_copy_semaphore() {
+ Semaphore s;
+ Semaphore sc1(s);
+ Semaphore sc2; sc2 = s;
+}
+
#endif // SHARE_RUNTIME_SEMAPHORE_HPP
diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp
b/src/hotspot/share/utilities/globalDefinitions.hpp
--- a/src/hotspot/share/utilities/globalDefinitions.hpp
+++ b/src/hotspot/share/utilities/globalDefinitions.hpp
@@ -1193,5 +1193,13 @@
return k0 == k1;
}
+class NonCopyable {
+private:
+ NonCopyable(NonCopyable const&);
+ NonCopyable& operator=(NonCopyable const&);
+
+public:
+ NonCopyable() {}
+};
#endif // SHARE_UTILITIES_GLOBALDEFINITIONS_HPP
Thanks,
StefanK
>
> (A few classes in PtrQueue.hpp that weren't previously made
> noncopyable but should have been are now also using the NONCOPYABLE
> macro.)
>
> CR:
> https://bugs.openjdk.java.net/browse/JDK-8234779
>
> Webrev:
> https://cr.openjdk.java.net/~kbarrett/8234779/open.00/
>
> Testing:
> mach5 tier1
>
> linux fastdebug builds for the following:
> 1. platforms: aarch64, arm32, ppc64le, s390x, zero.
> 2. x86_64 with shenandoah included.
> 3. x86_64 minimal configuration.
>
More information about the hotspot-dev
mailing list