提交 91bb7a1e 编写于 作者: K kbarrett

8234779: Provide idiom for declaring classes noncopyable

Summary: Add NONCOPYABLE macro and uses.
Reviewed-by: dholmes, pliden, coleenp
上级 05645ee1
......@@ -28,6 +28,7 @@
#include "os_aix.inline.hpp"
#include "runtime/os.hpp"
#include "runtime/os_perf.hpp"
#include "utilities/globalDefinitions.hpp"
#include CPU_HEADER(vm_version_ext)
......@@ -893,8 +894,7 @@ class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtIntern
friend class NetworkPerformanceInterface;
private:
NetworkPerformance();
NetworkPerformance(const NetworkPerformance& rhs); // no impl
NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
NONCOPYABLE(NetworkPerformance);
bool initialize();
~NetworkPerformance();
int network_utilization(NetworkInterface** network_interfaces) const;
......
......@@ -26,6 +26,7 @@
#include "memory/resourceArea.hpp"
#include "runtime/os.hpp"
#include "runtime/os_perf.hpp"
#include "utilities/globalDefinitions.hpp"
#include "vm_version_ext_x86.hpp"
#ifdef __APPLE__
......@@ -72,8 +73,8 @@ class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
int cpu_load_total_process(double* cpu_load);
int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
CPUPerformance(const CPUPerformance& rhs); // no impl
CPUPerformance& operator=(const CPUPerformance& rhs); // no impl
NONCOPYABLE(CPUPerformance);
public:
CPUPerformance();
bool initialize();
......@@ -264,8 +265,7 @@ class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
private:
SystemProcesses();
bool initialize();
SystemProcesses(const SystemProcesses& rhs); // no impl
SystemProcesses& operator=(const SystemProcesses& rhs); // no impl
NONCOPYABLE(SystemProcesses);
~SystemProcesses();
//information about system processes
......@@ -412,8 +412,7 @@ class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtIntern
friend class NetworkPerformanceInterface;
private:
NetworkPerformance();
NetworkPerformance(const NetworkPerformance& rhs); // no impl
NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
NONCOPYABLE(NetworkPerformance);
bool initialize();
~NetworkPerformance();
int network_utilization(NetworkInterface** network_interfaces) const;
......
......@@ -25,6 +25,8 @@
#ifndef OS_BSD_VM_SEMAPHORE_BSD_HPP
#define OS_BSD_VM_SEMAPHORE_BSD_HPP
#include "utilities/globalDefinitions.hpp"
#ifndef __APPLE__
// Use POSIX semaphores.
# include "semaphore_posix.hpp"
......@@ -37,9 +39,7 @@
class OSXSemaphore : public CHeapObj<mtInternal>{
semaphore_t _semaphore;
// Prevent copying and assignment.
OSXSemaphore(const OSXSemaphore&);
OSXSemaphore& operator=(const OSXSemaphore&);
NONCOPYABLE(OSXSemaphore);
public:
OSXSemaphore(uint value = 0);
......
......@@ -28,6 +28,7 @@
#include "os_linux.inline.hpp"
#include "runtime/os.hpp"
#include "runtime/os_perf.hpp"
#include "utilities/globalDefinitions.hpp"
#include CPU_HEADER(vm_version_ext)
......@@ -957,8 +958,7 @@ class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtIntern
friend class NetworkPerformanceInterface;
private:
NetworkPerformance();
NetworkPerformance(const NetworkPerformance& rhs); // no impl
NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
NONCOPYABLE(NetworkPerformance);
bool initialize();
~NetworkPerformance();
int64_t read_counter(const char* iface, const char* counter) const;
......
......@@ -26,15 +26,14 @@
#define OS_POSIX_VM_SEMAPHORE_POSIX_HPP
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
#include <semaphore.h>
class PosixSemaphore : public CHeapObj<mtInternal> {
sem_t _semaphore;
// Prevent copying and assignment.
PosixSemaphore(const PosixSemaphore&);
PosixSemaphore& operator=(const PosixSemaphore&);
NONCOPYABLE(PosixSemaphore);
public:
PosixSemaphore(uint value = 0);
......
......@@ -28,6 +28,7 @@
#include "runtime/os.hpp"
#include "runtime/os_perf.hpp"
#include "os_solaris.inline.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#include CPU_HEADER(vm_version_ext)
......@@ -747,8 +748,7 @@ class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtIntern
friend class NetworkPerformanceInterface;
private:
NetworkPerformance();
NetworkPerformance(const NetworkPerformance& rhs); // no impl
NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
NONCOPYABLE(NetworkPerformance);
bool initialize();
~NetworkPerformance();
int network_utilization(NetworkInterface** network_interfaces) const;
......
......@@ -30,6 +30,7 @@
#include "pdh_interface.hpp"
#include "runtime/os_perf.hpp"
#include "runtime/os.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#include "vm_version_ext_x86.hpp"
#include <math.h>
......@@ -1381,8 +1382,7 @@ class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtIntern
bool _iphlp_attached;
NetworkPerformance();
NetworkPerformance(const NetworkPerformance& rhs); // no impl
NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
NONCOPYABLE(NetworkPerformance);
bool initialize();
~NetworkPerformance();
int network_utilization(NetworkInterface** network_interfaces) const;
......
......@@ -26,15 +26,14 @@
#define OS_WINDOWS_VM_SEMAPHORE_WINDOWS_HPP
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
#include <windows.h>
class WindowsSemaphore : public CHeapObj<mtInternal> {
HANDLE _semaphore;
// Prevent copying and assignment.
WindowsSemaphore(const WindowsSemaphore&);
WindowsSemaphore& operator=(const WindowsSemaphore&);
NONCOPYABLE(WindowsSemaphore);
public:
WindowsSemaphore(uint value = 0);
......
......@@ -48,9 +48,7 @@ class OopStorage::ActiveArray {
ActiveArray(size_t size);
~ActiveArray();
// Noncopyable
ActiveArray(const ActiveArray&);
ActiveArray& operator=(const ActiveArray&);
NONCOPYABLE(ActiveArray);
static size_t blocks_offset();
Block* const* base_ptr() const;
......@@ -153,9 +151,7 @@ class OopStorage::Block /* No base class, to avoid messing up alignment. */ {
template<typename F, typename BlockPtr>
static bool iterate_impl(F f, BlockPtr b);
// Noncopyable.
Block(const Block&);
Block& operator=(const Block&);
NONCOPYABLE(Block);
public:
const AllocationListEntry& allocation_list_entry() const;
......
......@@ -26,7 +26,7 @@
#define SHARE_GC_SHARED_OOPSTORAGEPARSTATE_HPP
#include "gc/shared/oopStorage.hpp"
#include "utilities/macros.hpp"
#include "utilities/globalDefinitions.hpp"
//////////////////////////////////////////////////////////////////////////////
// Support for parallel and optionally concurrent state iteration.
......@@ -146,9 +146,7 @@ class OopStorage::BasicParState {
uint _estimated_thread_count;
bool _concurrent;
// Noncopyable.
BasicParState(const BasicParState&);
BasicParState& operator=(const BasicParState&);
NONCOPYABLE(BasicParState);
struct IterationData;
......
......@@ -25,6 +25,7 @@
#define SHARE_GC_Z_ZARRAY_HPP
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
template <typename T>
class ZArray {
......@@ -35,9 +36,7 @@ private:
size_t _size;
size_t _capacity;
// Copy and assignment are not allowed
ZArray(const ZArray<T>& array);
ZArray<T>& operator=(const ZArray<T>& array);
NONCOPYABLE(ZArray);
void expand(size_t new_capacity);
......
......@@ -26,6 +26,7 @@
#include "memory/allocation.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
template <typename T> class ZList;
......@@ -68,9 +69,7 @@ private:
ZListNode<T> _head;
size_t _size;
// Passing by value and assignment is not allowed
ZList(const ZList<T>& list);
ZList<T>& operator=(const ZList<T>& list);
NONCOPYABLE(ZList);
void verify() const {
assert(_head._next->_prev == &_head, "List corrupt");
......
......@@ -28,6 +28,7 @@
#include "jni.h"
#include "jfr/utilities/jfrAllocation.hpp"
#include "utilities/exceptions.hpp"
#include "utilities/globalDefinitions.hpp"
class JavaCallArguments;
class JavaThread;
......@@ -86,8 +87,7 @@ class JfrJavaArguments : public StackObj {
int _java_stack_slots;
Parameters();
Parameters(const Parameters&); // no impl
Parameters& operator=(const Parameters&); // no impl
NONCOPYABLE(Parameters);
void push(const JavaValue& value);
void push_large(const JavaValue& value);
......
......@@ -28,6 +28,7 @@
#include "logging/log.hpp"
#include "memory/allocation.hpp"
#include "oops/array.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/resourceHash.hpp"
......
......@@ -28,6 +28,7 @@
#include "memory/allocation.hpp"
#include "memory/metaspace.hpp"
#include "utilities/align.hpp"
#include "utilities/globalDefinitions.hpp"
// Array for metadata allocation
......@@ -48,9 +49,7 @@ protected:
}
private:
// Turn off copy constructor and assignment operator.
Array(const Array<T>&);
void operator=(const Array<T>&);
NONCOPYABLE(Array);
void* operator new(size_t size, ClassLoaderData* loader_data, int length, TRAPS) throw() {
size_t word_size = Array::size(length);
......
......@@ -26,6 +26,7 @@
#define SHARE_VM_RUNTIME_OS_PERF_HPP
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#define FUNCTIONALITY_NOT_IMPLEMENTED -8
......@@ -200,9 +201,8 @@ class NetworkInterface : public ResourceObj {
uint64_t _bytes_out;
NetworkInterface* _next;
NetworkInterface(); // no impl
NetworkInterface(const NetworkInterface& rhs); // no impl
NetworkInterface& operator=(const NetworkInterface& rhs); // no impl
NONCOPYABLE(NetworkInterface);
public:
NetworkInterface(const char* name, uint64_t bytes_in, uint64_t bytes_out, NetworkInterface* next) :
_name(NULL),
......@@ -278,8 +278,8 @@ class NetworkPerformanceInterface : public CHeapObj<mtInternal> {
private:
class NetworkPerformance;
NetworkPerformance* _impl;
NetworkPerformanceInterface(const NetworkPerformanceInterface& rhs); // no impl
NetworkPerformanceInterface& operator=(const NetworkPerformanceInterface& rhs); // no impl
NONCOPYABLE(NetworkPerformanceInterface);
public:
NetworkPerformanceInterface();
bool initialize();
......
......@@ -26,6 +26,7 @@
#define SHARE_VM_RUNTIME_SEMAPHORE_HPP
#include "memory/allocation.hpp"
#include "utilities/globalDefinitions.hpp"
#if defined(LINUX) || defined(SOLARIS) || defined(AIX)
# include "semaphore_posix.hpp"
......@@ -43,9 +44,7 @@ class JavaThread;
class Semaphore : public CHeapObj<mtSynchronizer> {
SemaphoreImpl _impl;
// Prevent copying and assignment of Semaphore instances.
Semaphore(const Semaphore&);
Semaphore& operator=(const Semaphore&);
NONCOPYABLE(Semaphore);
public:
Semaphore(uint value = 0) : _impl(value) {}
......
......@@ -48,6 +48,7 @@
#include "runtime/unhandledOops.hpp"
#include "utilities/align.hpp"
#include "utilities/exceptions.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#ifdef ZERO
# include "stack_zero.hpp"
......@@ -802,9 +803,7 @@ class NonJavaThread::Iterator : public StackObj {
uint _protect_enter;
NonJavaThread* _current;
// Noncopyable.
Iterator(const Iterator&);
Iterator& operator=(const Iterator&);
NONCOPYABLE(Iterator);
public:
Iterator();
......
......@@ -27,6 +27,7 @@
#include "memory/allocation.hpp"
#include "utilities/align.hpp"
#include "utilities/globalDefinitions.hpp"
// Forward decl;
class BitMapClosure;
......@@ -346,9 +347,7 @@ class ArenaBitMap : public BitMap {
ArenaBitMap(Arena* arena, idx_t size_in_bits);
private:
// Don't allow copy or assignment.
ArenaBitMap(const ArenaBitMap&);
ArenaBitMap& operator=(const ArenaBitMap&);
NONCOPYABLE(ArenaBitMap);
};
// A BitMap with storage in the CHeap.
......@@ -357,8 +356,7 @@ class CHeapBitMap : public BitMap {
private:
// Don't allow copy or assignment, to prevent the
// allocated memory from leaking out to other instances.
CHeapBitMap(const CHeapBitMap&);
CHeapBitMap& operator=(const CHeapBitMap&);
NONCOPYABLE(CHeapBitMap);
// NMT memory type
MEMFLAGS _flags;
......
......@@ -59,6 +59,19 @@
// For C++11 the declarations should be changed to deleted definitions.
#define NONCOPYABLE(C) C(C const&); C& operator=(C const&) /* next token must be ; */
// Declare the named class to be noncopyable. This macro must be used in
// a private part of the class's definition, followed by a semi-colon.
// Doing so provides private declarations for the class's copy constructor
// and assignment operator. Because these operations are private, most
// potential callers will fail to compile because they are inaccessible.
// The operations intentionally lack a definition, to provoke link-time
// failures for calls from contexts where they are accessible, e.g. from
// within the class or from a friend of the class.
// Note: The lack of definitions is still not completely bullet-proof, as
// an apparent call might be optimized away by copy elision.
// For C++11 the declarations should be changed to deleted definitions.
#define NONCOPYABLE(C) C(C const&); C& operator=(C const&) /* next token must be ; */
//----------------------------------------------------------------------------------------------------
// Printf-style formatters for fixed- and variable-width types as pointers and
// integers. These are derived from the definitions in inttypes.h. If the platform
......
......@@ -43,8 +43,7 @@ DEBUG_ONLY(class ResourceMark;)
// -XX:+DisplayVMOutputToStderr
class outputStream : public ResourceObj {
private:
outputStream(const outputStream&);
outputStream& operator=(const outputStream&);
NONCOPYABLE(outputStream);
protected:
int _indentation; // current indentation
......
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, 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
......@@ -57,9 +57,7 @@ class SingleWriterSynchronizer {
DEBUG_ONLY(volatile uint _writers;)
// Noncopyable.
SingleWriterSynchronizer(const SingleWriterSynchronizer&);
SingleWriterSynchronizer& operator=(const SingleWriterSynchronizer&);
NONCOPYABLE(SingleWriterSynchronizer);
public:
SingleWriterSynchronizer();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册