# HG changeset patch # User eosterlund # Date 1420478789 0 # Mon Jan 05 17:26:29 2015 +0000 # Node ID 6071457ed63effef2f1b34c1ae593707b8f1a496 # Parent 760291a06def2007c46a80c1d2e289bfd1763aa7 code minimum diff --git a/src/cpu/x86/vm/stubGenerator_x86_64.cpp b/src/cpu/x86/vm/stubGenerator_x86_64.cpp --- a/src/cpu/x86/vm/stubGenerator_x86_64.cpp +++ b/src/cpu/x86/vm/stubGenerator_x86_64.cpp @@ -530,7 +530,7 @@ return start; } - // Support for jint atomic::xchg(jint exchange_value, volatile jint* dest) + // Support for jint Atomic::xchg(jint exchange_value, volatile jint* dest) // // Arguments : // c_rarg0: exchange_value @@ -549,7 +549,7 @@ return start; } - // Support for intptr_t atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) + // Support for intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) // // Arguments : // c_rarg0: exchange_value @@ -568,8 +568,8 @@ return start; } - // Support for jint atomic::atomic_cmpxchg(jint exchange_value, volatile jint* dest, - // jint compare_value) + // Support for jint Atomic::cmpxchg(jint exchange_value, volatile jint* dest, + // jint compare_value) // // Arguments : // c_rarg0: exchange_value @@ -594,8 +594,8 @@ return start; } - // Support for jbyte atomic::atomic_cmpxchg(jbyte exchange_value, volatile jbyte* dest, - // jbyte compare_value) + // Support for jbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte* dest, + // jbyte compare_value) // // Arguments : // c_rarg0: exchange_value @@ -620,9 +620,8 @@ return start; } - // Support for jlong atomic::atomic_cmpxchg(jlong exchange_value, - // volatile jlong* dest, - // jlong compare_value) + // Support for jlong Atomic::cmpxchg(jlong exchange_value, volatile jlong* dest, + // jlong compare_value) // Arguments : // c_rarg0: exchange_value // c_rarg1: dest @@ -646,7 +645,7 @@ return start; } - // Support for jint atomic::add(jint add_value, volatile jint* dest) + // Support for jint Atomic::add(jint add_value, volatile jint* dest) // // Arguments : // c_rarg0: add_value @@ -668,7 +667,7 @@ return start; } - // Support for intptr_t atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) + // Support for intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) // // Arguments : // c_rarg0: add_value diff --git a/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.hpp b/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.hpp new file mode 100644 --- /dev/null +++ b/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_HPP +#define OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_HPP + +class AtomicPlatform : public AtomicBase { + public: + inline static jbyte cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); +}; + +#endif // OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_HPP + diff --git a/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp b/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp --- a/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp +++ b/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.inline.hpp @@ -88,8 +88,7 @@ return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest); } -#define VM_HAS_SPECIALIZED_CMPXCHG_BYTE -inline jbyte Atomic::cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { +inline jbyte AtomicPlatform::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { int mp = os::is_MP(); __asm__ volatile (LOCK_IF_MP(%4) "cmpxchgb %1,(%3)" : "=a" (exchange_value) @@ -98,7 +97,7 @@ return exchange_value; } -inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { +inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { int mp = os::is_MP(); __asm__ volatile (LOCK_IF_MP(%4) "cmpxchgl %1,(%3)" : "=a" (exchange_value) diff --git a/src/os_cpu/linux_x86/vm/atomic_linux_x86.hpp b/src/os_cpu/linux_x86/vm/atomic_linux_x86.hpp new file mode 100644 --- /dev/null +++ b/src/os_cpu/linux_x86/vm/atomic_linux_x86.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef OS_CPU_LINUX_X86_VM_ATOMIC_LINUX_X86_HPP +#define OS_CPU_LINUX_X86_VM_ATOMIC_LINUX_X86_HPP + +class AtomicPlatform : public AtomicBase { + public: + inline static jbyte cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); +}; + +#endif // OS_CPU_LINUX_X86_VM_ATOMIC_LINUX_X86_HPP + diff --git a/src/os_cpu/linux_x86/vm/atomic_linux_x86.inline.hpp b/src/os_cpu/linux_x86/vm/atomic_linux_x86.inline.hpp --- a/src/os_cpu/linux_x86/vm/atomic_linux_x86.inline.hpp +++ b/src/os_cpu/linux_x86/vm/atomic_linux_x86.inline.hpp @@ -84,12 +84,11 @@ return exchange_value; } -inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) { +inline void* Atomic::xchg_ptr (void* exchange_value, volatile void* dest) { return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest); } -#define VM_HAS_SPECIALIZED_CMPXCHG_BYTE -inline jbyte Atomic::cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { +inline jbyte AtomicPlatform::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { int mp = os::is_MP(); __asm__ volatile (LOCK_IF_MP(%4) "cmpxchgb %1,(%3)" : "=a" (exchange_value) @@ -98,7 +97,7 @@ return exchange_value; } -inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { +inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { int mp = os::is_MP(); __asm__ volatile (LOCK_IF_MP(%4) "cmpxchgl %1,(%3)" : "=a" (exchange_value) diff --git a/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.hpp b/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.hpp new file mode 100644 --- /dev/null +++ b/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_HPP +#define OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_HPP + +class AtomicPlatform : public AtomicBase { + public: + inline static jbyte cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); +}; + +#endif // OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_HPP + diff --git a/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.inline.hpp b/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.inline.hpp --- a/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.inline.hpp +++ b/src/os_cpu/solaris_x86/vm/atomic_solaris_x86.inline.hpp @@ -84,16 +84,15 @@ return _Atomic_xchg(exchange_value, dest); } -#define VM_HAS_SPECIALIZED_CMPXCHG_BYTE -inline jbyte Atomic::cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { +inline jbyte AtomicPlatform::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { return _Atomic_cmpxchg_byte(exchange_value, dest, compare_value IS_MP_ARG()); } -inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { +inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { return _Atomic_cmpxchg(exchange_value, dest, compare_value IS_MP_ARG()); } -inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) { +inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) { return _Atomic_cmpxchg_long(exchange_value, dest, compare_value IS_MP_ARG()); } diff --git a/src/os_cpu/windows_x86/vm/atomic_windows_x86.hpp b/src/os_cpu/windows_x86/vm/atomic_windows_x86.hpp new file mode 100644 --- /dev/null +++ b/src/os_cpu/windows_x86/vm/atomic_windows_x86.hpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1999, 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef OS_CPU_WINDOWS_X86_VM_ATOMIC_WINDOWS_X86_HPP +#define OS_CPU_WINDOWS_X86_VM_ATOMIC_WINDOWS_X86_HPP + +class AtomicPlatform : public AtomicBase { + public: + inline static jbyte cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); +}; + +#endif // OS_CPU_WINDOWS_X86_VM_ATOMIC_WINDOWS_X86_HPP + diff --git a/src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp b/src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp --- a/src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp +++ b/src/os_cpu/windows_x86/vm/atomic_windows_x86.inline.hpp @@ -119,24 +119,23 @@ return (void *)(os::atomic_xchg_ptr_func)((intptr_t)exchange_value, (volatile intptr_t*)dest); } -inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { +inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { return (*os::atomic_cmpxchg_func)(exchange_value, dest, compare_value); } -#define VM_HAS_SPECIALIZED_CMPXCHG_BYTE -inline jbyte Atomic::cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { +inline jbyte AtomicPlatform::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { return (*os::atomic_cmpxchg_byte_func)(exchange_value, dest, compare_value); } -inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) { +inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) { return (*os::atomic_cmpxchg_long_func)(exchange_value, dest, compare_value); } -inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) { +inline intptr_t Atomic::cmpxchg_ptr (intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) { return (intptr_t)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value); } -inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) { +inline void* Atomic::cmpxchg_ptr (void* exchange_value, volatile void* dest, void* compare_value) { return (void*)cmpxchg((jlong)exchange_value, (volatile jlong*)dest, (jlong)compare_value); } @@ -217,8 +216,7 @@ return (void*)xchg((jint)exchange_value, (volatile jint*)dest); } -#define VM_HAS_SPECIALIZED_CMPXCHG_BYTE -inline jbyte Atomic::cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { +inline jbyte AtomicPlatform::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { // alternative for InterlockedCompareExchange int mp = os::is_MP(); __asm { @@ -230,7 +228,7 @@ } } -inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { +inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) { // alternative for InterlockedCompareExchange int mp = os::is_MP(); __asm { @@ -242,7 +240,7 @@ } } -inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) { +inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) { int mp = os::is_MP(); jint ex_lo = (jint)exchange_value; jint ex_hi = *( ((jint*)&exchange_value) + 1 ); diff --git a/src/share/vm/runtime/atomic.cpp b/src/share/vm/runtime/atomic.cpp --- a/src/share/vm/runtime/atomic.cpp +++ b/src/share/vm/runtime/atomic.cpp @@ -28,10 +28,9 @@ /* * This is the default implementation of byte-sized cmpxchg. It emulates jbyte-sized cmpxchg * in terms of jint-sized cmpxchg. Platforms may override this by defining their own inline definition - * as well as defining VM_HAS_SPECIALIZED_CMPXCHG_BYTE. This will cause the platform specific - * implementation to be used instead. + * in their AtomicPlatform class. */ -jbyte Atomic::cmpxchg_general(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { +jbyte AtomicBase::cmpxchg_general(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { assert(sizeof(jbyte) == 1, "assumption."); uintptr_t dest_addr = (uintptr_t)dest; uintptr_t offset = dest_addr % sizeof(jint); @@ -42,7 +41,7 @@ jbyte* new_val_as_bytes = (jbyte*)(&new_val); new_val_as_bytes[offset] = exchange_value; while (cur_as_bytes[offset] == compare_value) { - jint res = cmpxchg(new_val, dest_int, cur); + jint res = Atomic::cmpxchg(new_val, dest_int, cur); if (res == cur) break; cur = res; new_val = cur; diff --git a/src/share/vm/runtime/atomic.hpp b/src/share/vm/runtime/atomic.hpp --- a/src/share/vm/runtime/atomic.hpp +++ b/src/share/vm/runtime/atomic.hpp @@ -26,11 +26,42 @@ #define SHARE_VM_RUNTIME_ATOMIC_HPP #include "memory/allocation.hpp" +#include "utilities/traits/selectBaseClass.hpp" -class Atomic : AllStatic { - private: +class AtomicPlatform; + +class AtomicBase : AllStatic { + protected: static jbyte cmpxchg_general(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); + public: + inline static jbyte cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { + return cmpxchg_general(exchange_value, dest, compare_value); + } +}; +// Linux +#ifdef TARGET_OS_ARCH_linux_x86 +# include "atomic_linux_x86.hpp" +#endif + +// Solaris +#ifdef TARGET_OS_ARCH_solaris_x86 +# include "atomic_solaris_x86.hpp" +#endif + +// Windows +#ifdef TARGET_OS_ARCH_windows_x86 +# include "atomic_windows_x86.hpp" +#endif + +// BSD +#ifdef TARGET_OS_ARCH_bsd_x86 +# include "atomic_bsd_x86.hpp" +#endif + +typedef SelectBaseClass::type AtomicSuper; + +class Atomic : public AtomicSuper { public: // Atomic operations on jlong types are not available on all 32-bit // platforms. If atomic ops on jlongs are defined here they must only diff --git a/src/share/vm/runtime/atomic.inline.hpp b/src/share/vm/runtime/atomic.inline.hpp --- a/src/share/vm/runtime/atomic.inline.hpp +++ b/src/share/vm/runtime/atomic.inline.hpp @@ -66,6 +66,7 @@ #ifdef TARGET_OS_ARCH_bsd_x86 # include "atomic_bsd_x86.inline.hpp" #endif + #ifdef TARGET_OS_ARCH_bsd_zero # include "atomic_bsd_zero.inline.hpp" #endif @@ -87,12 +88,8 @@ dec_ptr((volatile intptr_t*) dest); } -#ifndef VM_HAS_SPECIALIZED_CMPXCHG_BYTE -// See comment in atomic.cpp how to override. -inline jbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte *dest, jbyte comparand) -{ - return cmpxchg_general(exchange_value, dest, comparand); +inline jbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) { + return AtomicSuper::cmpxchg(exchange_value, dest, compare_value); } -#endif // VM_HAS_SPECIALIZED_CMPXCHG_BYTE #endif // SHARE_VM_RUNTIME_ATOMIC_INLINE_HPP diff --git a/src/share/vm/utilities/traits/isSame.cpp b/src/share/vm/utilities/traits/isSame.cpp new file mode 100644 --- /dev/null +++ b/src/share/vm/utilities/traits/isSame.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "utilities/debug.hpp" +#include "utilities/traits/isSame.hpp" + +class IsSameTest { + enum EnumType {}; + enum EnumType2 {}; + union UnionType {}; + union UnionType2 {}; + class ClassType {}; + class ClassType2 {}; + class DerivedClassType: ClassType {}; + class DerivedClassType2: ClassType2 {}; + struct StructType {}; + struct StructType2 {}; + typedef int PrimitiveType; + typedef long PrimitiveType2; + + static void test() { + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + STATIC_ASSERT((IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((!IsSame::value)); + + STATIC_ASSERT((IsSame::value)); + } +}; + diff --git a/src/share/vm/utilities/traits/isSame.hpp b/src/share/vm/utilities/traits/isSame.hpp new file mode 100644 --- /dev/null +++ b/src/share/vm/utilities/traits/isSame.hpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_UTILITIES_TRAITS_IS_SAME_HPP +#define SHARE_VM_UTILITIES_TRAITS_IS_SAME_HPP + +/** + * IsSame::value is true iff T and U are the same type. + */ +template +class IsSame { + template + struct IsSameInternal { + static const bool value = false; + }; + + template + struct IsSameInternal { + static const bool value = true; + }; +public: + static const bool value = IsSameInternal::value; +}; + +#endif // SHARE_VM_UTILITIES_TRAITS_IS_SAME_HPP + diff --git a/src/share/vm/utilities/traits/selectBaseClass.cpp b/src/share/vm/utilities/traits/selectBaseClass.cpp new file mode 100644 --- /dev/null +++ b/src/share/vm/utilities/traits/selectBaseClass.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "utilities/debug.hpp" +#include "utilities/traits/isSame.hpp" +#include "utilities/traits/selectBaseClass.hpp" + +class SelectBaseClassTest { + class ForwardDeclaredClass; + class Base {}; + class Derived: Base {}; + class Derived2: Derived {}; + class Unrelated {}; + + static void test() { + STATIC_ASSERT((IsSame::type>::value)); + STATIC_ASSERT((IsSame::type>::value)); + STATIC_ASSERT((IsSame::type>::value)); + STATIC_ASSERT((IsSame::type>::value)); + STATIC_ASSERT((IsSame::type>::value)); + } +}; + diff --git a/src/share/vm/utilities/traits/selectBaseClass.hpp b/src/share/vm/utilities/traits/selectBaseClass.hpp new file mode 100644 --- /dev/null +++ b/src/share/vm/utilities/traits/selectBaseClass.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2011, 2013, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_UTILITIES_TRAITS_SELECT_BASE_CLASS_HPP +#define SHARE_VM_UTILITIES_TRAITS_SELECT_BASE_CLASS_HPP + +// This trait is used for injecting optional classes in inheritance hierarchies +// if they have been defined. This trait may not be used in such a way that +// in some instantiations in the same compilation unit, the optional class is +// defined and in others it is not as that can cause inconsistent behaviour. +// The ::type of this trait will be the Optional type if it was defined +// and is a subtype of Required, otherwise it will be Required. +template +class SelectBaseClass { + typedef char yes[1]; + typedef char no[2]; + + template + static yes &check(Optional*, T); + static no &check(Required*, int); + + struct OptionalCheckHost { + operator Required*() const; + operator Optional*(); + }; + + template + struct OptionalCheck { typedef O type; }; + + template + struct OptionalCheck { typedef R type; }; +public: + typedef typename OptionalCheck::type type; +}; + +#endif // SHARE_VM_UTILITIES_TRAITS_SELECT_BASE_CLASS_HPP +