diff --git a/doc/testing.html b/doc/testing.html index 31f4fbd1778..195153c8612 100644 --- a/doc/testing.html +++ b/doc/testing.html @@ -72,6 +72,7 @@ id="toc-notes-for-specific-tests">Notes for Specific Tests
  • Non-US locale
  • PKCS11 Tests
  • +
  • SCTP Tests
  • Testing Ahead-of-time Optimizations
  • @@ -621,6 +622,21 @@ element of the appropriate @Artifact class. (See JTREG="JAVA_OPTIONS=-Djdk.test.lib.artifacts.nsslib-linux_aarch64=/path/to/NSS-libs"

    For more notes about the PKCS11 tests, please refer to test/jdk/sun/security/pkcs11/README.

    +

    SCTP Tests

    +

    The SCTP tests require the SCTP runtime library, which is often not +installed by default in popular Linux distributions. Without this +library, the SCTP tests will be skipped. If you want to enable the SCTP +tests, you should install the SCTP library before running the tests.

    +

    For distributions using the .deb packaging format and the apt tool +(such as Debian, Ubuntu, etc.), try this:

    +
    sudo apt install libsctp1
    +sudo modprobe sctp
    +lsmod | grep sctp
    +

    For distributions using the .rpm packaging format and the dnf tool +(such as Fedora, Red Hat, etc.), try this:

    +
    sudo dnf install -y lksctp-tools
    +sudo modprobe sctp
    +lsmod | grep sctp

    Testing Ahead-of-time Optimizations

    One way to improve test coverage of ahead-of-time (AOT) optimizations diff --git a/doc/testing.md b/doc/testing.md index b95f59de9fd..d0e54aab02b 100644 --- a/doc/testing.md +++ b/doc/testing.md @@ -640,6 +640,32 @@ $ make test TEST="jtreg:sun/security/pkcs11/Secmod/AddTrustedCert.java" \ For more notes about the PKCS11 tests, please refer to test/jdk/sun/security/pkcs11/README. + +### SCTP Tests + +The SCTP tests require the SCTP runtime library, which is often not installed +by default in popular Linux distributions. Without this library, the SCTP tests +will be skipped. If you want to enable the SCTP tests, you should install the +SCTP library before running the tests. + +For distributions using the .deb packaging format and the apt tool +(such as Debian, Ubuntu, etc.), try this: + +``` +sudo apt install libsctp1 +sudo modprobe sctp +lsmod | grep sctp +``` + +For distributions using the .rpm packaging format and the dnf tool +(such as Fedora, Red Hat, etc.), try this: + +``` +sudo dnf install -y lksctp-tools +sudo modprobe sctp +lsmod | grep sctp +``` + ### Testing Ahead-of-time Optimizations One way to improve test coverage of ahead-of-time (AOT) optimizations in diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4 index 5a9fdc57c74..639c3852212 100644 --- a/make/autoconf/flags-cflags.m4 +++ b/make/autoconf/flags-cflags.m4 @@ -69,22 +69,18 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS], # Debug prefix mapping if supported by compiler DEBUG_PREFIX_CFLAGS= - UTIL_ARG_WITH(NAME: native-debug-symbols-level, TYPE: string, - DEFAULT: "", - RESULT: DEBUG_SYMBOLS_LEVEL, + UTIL_ARG_WITH(NAME: native-debug-symbols-level, TYPE: literal, + DEFAULT: [auto], VALID_VALUES: [auto 1 2 3], + CHECK_AVAILABLE: [ + if test x$TOOLCHAIN_TYPE = xmicrosoft; then + AVAILABLE=false + fi + ], DESC: [set the native debug symbol level (GCC and Clang only)], - DEFAULT_DESC: [toolchain default]) - AC_SUBST(DEBUG_SYMBOLS_LEVEL) - - if test "x${TOOLCHAIN_TYPE}" = xgcc || \ - test "x${TOOLCHAIN_TYPE}" = xclang; then - DEBUG_SYMBOLS_LEVEL_FLAGS="-g" - if test "x${DEBUG_SYMBOLS_LEVEL}" != "x"; then - DEBUG_SYMBOLS_LEVEL_FLAGS="-g${DEBUG_SYMBOLS_LEVEL}" - FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_SYMBOLS_LEVEL_FLAGS}], - IF_FALSE: AC_MSG_ERROR("Debug info level ${DEBUG_SYMBOLS_LEVEL} is not supported")) - fi - fi + DEFAULT_DESC: [toolchain default], + IF_AUTO: [ + RESULT="" + ]) # Debug symbols if test "x$TOOLCHAIN_TYPE" = xgcc; then @@ -111,8 +107,8 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS], fi # Debug info level should follow the debug format to be effective. - CFLAGS_DEBUG_SYMBOLS="-gdwarf-4 ${DEBUG_SYMBOLS_LEVEL_FLAGS}" - ASFLAGS_DEBUG_SYMBOLS="${DEBUG_SYMBOLS_LEVEL_FLAGS}" + CFLAGS_DEBUG_SYMBOLS="-gdwarf-4 -g${NATIVE_DEBUG_SYMBOLS_LEVEL}" + ASFLAGS_DEBUG_SYMBOLS="-g${NATIVE_DEBUG_SYMBOLS_LEVEL}" elif test "x$TOOLCHAIN_TYPE" = xclang; then if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then # Check if compiler supports -fdebug-prefix-map. If so, use that to make @@ -132,8 +128,8 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS], IF_FALSE: [GDWARF_FLAGS=""]) # Debug info level should follow the debug format to be effective. - CFLAGS_DEBUG_SYMBOLS="${GDWARF_FLAGS} ${DEBUG_SYMBOLS_LEVEL_FLAGS}" - ASFLAGS_DEBUG_SYMBOLS="${DEBUG_SYMBOLS_LEVEL_FLAGS}" + CFLAGS_DEBUG_SYMBOLS="${GDWARF_FLAGS} -g${NATIVE_DEBUG_SYMBOLS_LEVEL}" + ASFLAGS_DEBUG_SYMBOLS="-g${NATIVE_DEBUG_SYMBOLS_LEVEL}" elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then CFLAGS_DEBUG_SYMBOLS="-Z7" fi diff --git a/make/jdk/src/classes/build/tools/taglet/JSpec.java b/make/jdk/src/classes/build/tools/taglet/JSpec.java index 1c301e94a8a..7e1e0ca215e 100644 --- a/make/jdk/src/classes/build/tools/taglet/JSpec.java +++ b/make/jdk/src/classes/build/tools/taglet/JSpec.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -49,13 +49,15 @@ import static com.sun.source.doctree.DocTree.Kind.*; * The tags can be used as follows: * *

    - * @jls section-number description
    + * @jls chapter.section description
    + * @jls preview-feature-chapter.section description
      * 
    * * For example: * *
      * @jls 3.4 Line Terminators
    + * @jls primitive-types-in-patterns-instanceof-switch-5.7.1 Exact Testing Conversions
      * 
    * * will produce the following HTML, depending on the file containing @@ -64,10 +66,24 @@ import static com.sun.source.doctree.DocTree.Kind.*; *
    {@code
      * 
    See Java Language Specification: *
    3.4 Line terminators + *
    + * 5.7.1 Exact Testing Conversions + * PREVIEW * }
    * - * Copies of JLS and JVMS are expected to have been placed in the {@code specs} - * folder. These documents are not included in open-source repositories. + * In inline tags (note you need manual JLS/JVMS prefix): + *
    + * JLS {@jls 3.4}
    + * 
    + * + * produces (note the section sign and no trailing dot): + *
    + * JLS §3.4
    + * 
    + * + * Copies of JLS, JVMS, and preview JLS and JVMS changes are expected to have + * been placed in the {@code specs} folder. These documents are not included + * in open-source repositories. */ public class JSpec implements Taglet { @@ -87,9 +103,9 @@ public class JSpec implements Taglet { } } - private String tagName; - private String specTitle; - private String idPrefix; + private final String tagName; + private final String specTitle; + private final String idPrefix; JSpec(String tagName, String specTitle, String idPrefix) { this.tagName = tagName; @@ -98,7 +114,7 @@ public class JSpec implements Taglet { } // Note: Matches special cases like @jvms 6.5.checkcast - private static final Pattern TAG_PATTERN = Pattern.compile("(?s)(.+ )?(?[1-9][0-9]*)(?
    [0-9a-z_.]*)( .*)?$"); + private static final Pattern TAG_PATTERN = Pattern.compile("(?s)(.+ )?(?([a-z0-9]+-)+)?(?[1-9][0-9]*)(?
    [0-9a-z_.]*)( .*)?$"); /** * Returns the set of locations in which the tag may be used. @@ -157,19 +173,50 @@ public class JSpec implements Taglet { .trim(); Matcher m = TAG_PATTERN.matcher(tagText); if (m.find()) { + // preview-feature-4.6 is preview-feature-, 4, .6 + String preview = m.group("preview"); // null if no preview feature String chapter = m.group("chapter"); String section = m.group("section"); String rootParent = currentPath().replaceAll("[^/]+", ".."); - String url = String.format("%1$s/specs/%2$s/%2$s-%3$s.html#%2$s-%3$s%4$s", - rootParent, idPrefix, chapter, section); + String url = preview == null ? + String.format("%1$s/specs/%2$s/%2$s-%3$s.html#%2$s-%3$s%4$s", + rootParent, idPrefix, chapter, section) : + String.format("%1$s/specs/%5$s%2$s.html#%2$s-%3$s%4$s", + rootParent, idPrefix, chapter, section, preview); + + var literal = expand(contents).trim(); + var prefix = (preview == null ? "" : preview) + chapter + section; + if (literal.startsWith(prefix)) { + var hasFullTitle = literal.length() > prefix.length(); + if (hasFullTitle) { + // Drop the preview identifier + literal = chapter + section + literal.substring(prefix.length()); + } else { + // No section sign if the tag refers to a chapter, like {@jvms 4} + String sectionSign = section.isEmpty() ? "" : "§"; + // Change whole text to "§chapter.x" in inline tags. + literal = sectionSign + chapter + section; + } + } sb.append("") - .append(expand(contents)) + .append(literal) .append(""); + if (preview != null) { + // Add PREVIEW superscript that links to JLS/JVMS 1.5.1 + // "Restrictions on the Use of Preview Features" + // Similar to how APIs link to the Preview info box warning + var sectionLink = String.format("%1$s/specs/%2$s/%2$s-%3$s.html#%2$s-%3$s%4$s", + rootParent, idPrefix, "1", ".5.1"); + sb.append("PREVIEW"); + } + if (tag.getKind() == DocTree.Kind.UNKNOWN_BLOCK_TAG) { sb.append("
    "); } diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp index b8a9afc123f..27428a5c558 100644 --- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp @@ -5782,6 +5782,9 @@ address MacroAssembler::arrays_equals(Register a1, Register a2, Register tmp3, // return false; bind(A_IS_NOT_NULL); ldrw(cnt1, Address(a1, length_offset)); + ldrw(tmp5, Address(a2, length_offset)); + cmp(cnt1, tmp5); + br(NE, DONE); // If lengths differ, return false // Increase loop counter by diff between base- and actual start-offset. addw(cnt1, cnt1, extra_length); lea(a1, Address(a1, start_offset)); @@ -5848,6 +5851,9 @@ address MacroAssembler::arrays_equals(Register a1, Register a2, Register tmp3, cbz(a1, DONE); ldrw(cnt1, Address(a1, length_offset)); cbz(a2, DONE); + ldrw(tmp5, Address(a2, length_offset)); + cmp(cnt1, tmp5); + br(NE, DONE); // If lengths differ, return false // Increase loop counter by diff between base- and actual start-offset. addw(cnt1, cnt1, extra_length); diff --git a/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp b/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp index afef21b091a..3ab81697280 100644 --- a/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp +++ b/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2025 SAP SE. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2026 SAP SE. 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 @@ -412,12 +412,8 @@ run_stub: } void os::Aix::init_thread_fpu_state(void) { -#if !defined(USE_XLC_BUILTINS) // Disable FP exceptions. __asm__ __volatile__ ("mtfsfi 6,0"); -#else - __mtfsfi(6, 0); -#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/hotspot/os_cpu/aix_ppc/prefetch_aix_ppc.inline.hpp b/src/hotspot/os_cpu/aix_ppc/prefetch_aix_ppc.inline.hpp index c741335b5f0..d9dac0e231f 100644 --- a/src/hotspot/os_cpu/aix_ppc/prefetch_aix_ppc.inline.hpp +++ b/src/hotspot/os_cpu/aix_ppc/prefetch_aix_ppc.inline.hpp @@ -1,6 +1,6 @@ /* * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2013 SAP SE. All rights reserved. + * Copyright (c) 2012, 2026 SAP SE. 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 @@ -29,29 +29,21 @@ // Included in runtime/prefetch.inline.hpp inline void Prefetch::read(const void *loc, intx interval) { -#if !defined(USE_XLC_BUILTINS) __asm__ __volatile__ ( " dcbt 0, %0 \n" : : /*%0*/"r" ( ((address)loc) +((long)interval) ) //: ); -#else - __dcbt(((address)loc) +((long)interval)); -#endif } inline void Prefetch::write(void *loc, intx interval) { -#if !defined(USE_XLC_BUILTINS) __asm__ __volatile__ ( " dcbtst 0, %0 \n" : : /*%0*/"r" ( ((address)loc) +((long)interval) ) //: ); -#else - __dcbtst( ((address)loc) +((long)interval) ); -#endif } #endif // OS_CPU_AIX_PPC_PREFETCH_AIX_PPC_INLINE_HPP diff --git a/src/hotspot/share/cds/aotGrowableArray.cpp b/src/hotspot/share/cds/aotGrowableArray.cpp new file mode 100644 index 00000000000..ec63e7aa57f --- /dev/null +++ b/src/hotspot/share/cds/aotGrowableArray.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2026, 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 "cds/aotGrowableArray.hpp" +#include "cds/aotMetaspace.hpp" +#include "memory/allocation.inline.hpp" +#include "utilities/growableArray.hpp" + +void AOTGrowableArrayHelper::deallocate(void* mem) { + if (!AOTMetaspace::in_aot_cache(mem)) { + GrowableArrayCHeapAllocator::deallocate(mem); + } +} diff --git a/src/hotspot/share/cds/aotGrowableArray.hpp b/src/hotspot/share/cds/aotGrowableArray.hpp new file mode 100644 index 00000000000..0a0c137ed07 --- /dev/null +++ b/src/hotspot/share/cds/aotGrowableArray.hpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2026, 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_AOT_AOTGROWABLEARRAY_HPP +#define SHARE_AOT_AOTGROWABLEARRAY_HPP + +#include +#include + +class AOTGrowableArrayHelper { +public: + static void deallocate(void* mem); +}; + +// An AOTGrowableArray provides the same functionality as a GrowableArray that +// uses the C heap allocator. In addition, AOTGrowableArray can be iterated with +// MetaspaceClosure. This type should be used for growable arrays that need to be +// stored in the AOT cache. See ModuleEntry::_reads for an example. +template +class AOTGrowableArray : public GrowableArrayWithAllocator> { + friend class VMStructs; + friend class GrowableArrayWithAllocator; + + static E* allocate(int max, MemTag mem_tag) { + return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), mem_tag); + } + + E* allocate() { + return allocate(this->_capacity, mtClass); + } + + void deallocate(E* mem) { +#if INCLUDE_CDS + AOTGrowableArrayHelper::deallocate(mem); +#else + GrowableArrayCHeapAllocator::deallocate(mem); +#endif + } + +public: + AOTGrowableArray(int initial_capacity, MemTag mem_tag) : + GrowableArrayWithAllocator( + allocate(initial_capacity, mem_tag), + initial_capacity) {} + + AOTGrowableArray() : AOTGrowableArray(0, mtClassShared) {} + + // methods required by MetaspaceClosure + void metaspace_pointers_do(MetaspaceClosure* it); + int size_in_heapwords() const { return (int)heap_word_size(sizeof(*this)); } + MetaspaceClosureType type() const { return MetaspaceClosureType::GrowableArrayType; } + static bool is_read_only_by_default() { return false; } +}; + +#endif // SHARE_AOT_AOTGROWABLEARRAY_HPP diff --git a/src/hotspot/share/cds/aotGrowableArray.inline.hpp b/src/hotspot/share/cds/aotGrowableArray.inline.hpp new file mode 100644 index 00000000000..8c6e8cb6503 --- /dev/null +++ b/src/hotspot/share/cds/aotGrowableArray.inline.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2026, 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_CDS_AOTGROWABLEARRAY_INLINE_HPP +#define SHARE_CDS_AOTGROWABLEARRAY_INLINE_HPP + +#include "cds/aotGrowableArray.hpp" + +#include "memory/metaspaceClosure.hpp" + +template +void AOTGrowableArray::metaspace_pointers_do(MetaspaceClosure* it) { + it->push_c_array(AOTGrowableArray::data_addr(), AOTGrowableArray::capacity()); +} + +#endif // SHARE_CDS_AOTGROWABLEARRAY_INLINE_HPP diff --git a/src/hotspot/share/cds/aotMapLogger.cpp b/src/hotspot/share/cds/aotMapLogger.cpp index a252eae4b84..5e4e0956824 100644 --- a/src/hotspot/share/cds/aotMapLogger.cpp +++ b/src/hotspot/share/cds/aotMapLogger.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -29,6 +29,8 @@ #include "cds/aotStreamedHeapWriter.hpp" #include "cds/cdsConfig.hpp" #include "cds/filemap.hpp" +#include "classfile/moduleEntry.hpp" +#include "classfile/packageEntry.hpp" #include "classfile/systemDictionaryShared.hpp" #include "classfile/vmClasses.hpp" #include "logging/log.hpp" @@ -141,7 +143,7 @@ public: info._buffered_addr = ref->obj(); info._requested_addr = ref->obj(); info._bytes = ref->size() * BytesPerWord; - info._type = ref->msotype(); + info._type = ref->type(); _objs.append(info); } @@ -214,7 +216,7 @@ void AOTMapLogger::dumptime_log_metaspace_region(const char* name, DumpRegion* r info._buffered_addr = src_info->buffered_addr(); info._requested_addr = info._buffered_addr + _buffer_to_requested_delta; info._bytes = src_info->size_in_bytes(); - info._type = src_info->msotype(); + info._type = src_info->type(); objs.append(info); } @@ -332,43 +334,52 @@ void AOTMapLogger::log_metaspace_objects_impl(address region_base, address regio address buffered_addr = info._buffered_addr; address requested_addr = info._requested_addr; int bytes = info._bytes; - MetaspaceObj::Type type = info._type; - const char* type_name = MetaspaceObj::type_name(type); + MetaspaceClosureType type = info._type; + const char* type_name = MetaspaceClosure::type_name(type); log_as_hex(last_obj_base, buffered_addr, last_obj_base + _buffer_to_requested_delta); switch (type) { - case MetaspaceObj::ClassType: + case MetaspaceClosureType::ClassType: log_klass((Klass*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::ConstantPoolType: + case MetaspaceClosureType::ConstantPoolType: log_constant_pool((ConstantPool*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::ConstantPoolCacheType: + case MetaspaceClosureType::ConstantPoolCacheType: log_constant_pool_cache((ConstantPoolCache*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::ConstMethodType: + case MetaspaceClosureType::ConstMethodType: log_const_method((ConstMethod*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::MethodType: + case MetaspaceClosureType::MethodType: log_method((Method*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::MethodCountersType: + case MetaspaceClosureType::MethodCountersType: log_method_counters((MethodCounters*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::MethodDataType: + case MetaspaceClosureType::MethodDataType: log_method_data((MethodData*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::SymbolType: + case MetaspaceClosureType::ModuleEntryType: + log_module_entry((ModuleEntry*)src, requested_addr, type_name, bytes, current); + break; + case MetaspaceClosureType::PackageEntryType: + log_package_entry((PackageEntry*)src, requested_addr, type_name, bytes, current); + break; + case MetaspaceClosureType::GrowableArrayType: + log_growable_array((GrowableArrayBase*)src, requested_addr, type_name, bytes, current); + break; + case MetaspaceClosureType::SymbolType: log_symbol((Symbol*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::KlassTrainingDataType: + case MetaspaceClosureType::KlassTrainingDataType: log_klass_training_data((KlassTrainingData*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::MethodTrainingDataType: + case MetaspaceClosureType::MethodTrainingDataType: log_method_training_data((MethodTrainingData*)src, requested_addr, type_name, bytes, current); break; - case MetaspaceObj::CompileTrainingDataType: + case MetaspaceClosureType::CompileTrainingDataType: log_compile_training_data((CompileTrainingData*)src, requested_addr, type_name, bytes, current); break; default: @@ -421,6 +432,27 @@ void AOTMapLogger::log_method_data(MethodData* md, address requested_addr, const log_debug(aot, map)(_LOG_PREFIX " %s", p2i(requested_addr), type_name, bytes, md->method()->external_name()); } +void AOTMapLogger::log_module_entry(ModuleEntry* mod, address requested_addr, const char* type_name, + int bytes, Thread* current) { + ResourceMark rm(current); + log_debug(aot, map)(_LOG_PREFIX " %s", p2i(requested_addr), type_name, bytes, + mod->name_as_C_string()); +} + +void AOTMapLogger::log_package_entry(PackageEntry* pkg, address requested_addr, const char* type_name, + int bytes, Thread* current) { + ResourceMark rm(current); + log_debug(aot, map)(_LOG_PREFIX " %s - %s", p2i(requested_addr), type_name, bytes, + pkg->module()->name_as_C_string(), pkg->name_as_C_string()); +} + +void AOTMapLogger::log_growable_array(GrowableArrayBase* arr, address requested_addr, const char* type_name, + int bytes, Thread* current) { + ResourceMark rm(current); + log_debug(aot, map)(_LOG_PREFIX " %d (%d)", p2i(requested_addr), type_name, bytes, + arr->length(), arr->capacity()); +} + void AOTMapLogger::log_klass(Klass* k, address requested_addr, const char* type_name, int bytes, Thread* current) { ResourceMark rm(current); diff --git a/src/hotspot/share/cds/aotMapLogger.hpp b/src/hotspot/share/cds/aotMapLogger.hpp index ba188514861..bf7ce0028b9 100644 --- a/src/hotspot/share/cds/aotMapLogger.hpp +++ b/src/hotspot/share/cds/aotMapLogger.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -28,6 +28,7 @@ #include "cds/archiveBuilder.hpp" #include "memory/allocation.hpp" #include "memory/allStatic.hpp" +#include "memory/metaspaceClosureType.hpp" #include "oops/oopsHierarchy.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/growableArray.hpp" @@ -37,9 +38,13 @@ class ArchiveStreamedHeapInfo; class CompileTrainingData; class DumpRegion; class FileMapInfo; +class GrowableArrayBase; class KlassTrainingData; +class MethodCounters; class MethodTrainingData; +class ModuleEntry; class outputStream; +class PackageEntry; // Write detailed info to a mapfile to analyze contents of the AOT cache/CDS archive. // -Xlog:aot+map* can be used both when creating an AOT cache, or when using an AOT cache. @@ -62,7 +67,7 @@ class AOTMapLogger : AllStatic { address _buffered_addr; address _requested_addr; int _bytes; - MetaspaceObj::Type _type; + MetaspaceClosureType _type; }; public: @@ -142,6 +147,9 @@ private: Thread* current); static void log_klass(Klass* k, address requested_addr, const char* type_name, int bytes, Thread* current); static void log_method(Method* m, address requested_addr, const char* type_name, int bytes, Thread* current); + static void log_module_entry(ModuleEntry* mod, address requested_addr, const char* type_name, int bytes, Thread* current); + static void log_package_entry(PackageEntry* pkg, address requested_addr, const char* type_name, int bytes, Thread* current); + static void log_growable_array(GrowableArrayBase* arr, address requested_addr, const char* type_name, int bytes, Thread* current); static void log_symbol(Symbol* s, address requested_addr, const char* type_name, int bytes, Thread* current); static void log_klass_training_data(KlassTrainingData* ktd, address requested_addr, const char* type_name, int bytes, Thread* current); static void log_method_training_data(MethodTrainingData* mtd, address requested_addr, const char* type_name, int bytes, Thread* current); diff --git a/src/hotspot/share/cds/aotMetaspace.cpp b/src/hotspot/share/cds/aotMetaspace.cpp index 79d789e0c70..683c897d855 100644 --- a/src/hotspot/share/cds/aotMetaspace.cpp +++ b/src/hotspot/share/cds/aotMetaspace.cpp @@ -698,6 +698,9 @@ public: Universe::metaspace_pointers_do(it); vmSymbols::metaspace_pointers_do(it); TrainingData::iterate_roots(it); + if (CDSConfig::is_dumping_full_module_graph()) { + ClassLoaderDataShared::iterate_roots(it); + } // The above code should find all the symbols that are referenced by the // archived classes. We just need to add the extra symbols which @@ -795,6 +798,10 @@ void VM_PopulateDumpSharedSpace::doit() { _builder.make_klasses_shareable(); AOTMetaspace::make_method_handle_intrinsics_shareable(); + if (CDSConfig::is_dumping_full_module_graph()) { + ClassLoaderDataShared::remove_unshareable_info(); + } + dump_java_heap_objects(); dump_shared_symbol_table(_builder.symbols()); @@ -1135,6 +1142,7 @@ void AOTMetaspace::dump_static_archive_impl(StaticArchiveBuilder& builder, TRAPS HeapShared::init_heap_writer(); if (CDSConfig::is_dumping_full_module_graph()) { ClassLoaderDataShared::ensure_module_entry_tables_exist(); + ClassLoaderDataShared::build_tables(CHECK); HeapShared::reset_archived_object_states(CHECK); } diff --git a/src/hotspot/share/cds/archiveBuilder.cpp b/src/hotspot/share/cds/archiveBuilder.cpp index 6bbefea5cd9..9161980c4be 100644 --- a/src/hotspot/share/cds/archiveBuilder.cpp +++ b/src/hotspot/share/cds/archiveBuilder.cpp @@ -243,7 +243,7 @@ bool ArchiveBuilder::gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool re if (get_follow_mode(ref) != make_a_copy) { return false; } - if (ref->msotype() == MetaspaceObj::ClassType) { + if (ref->type() == MetaspaceClosureType::ClassType) { Klass* klass = (Klass*)ref->obj(); assert(klass->is_klass(), "must be"); if (!is_excluded(klass)) { @@ -252,7 +252,7 @@ bool ArchiveBuilder::gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool re assert(klass->is_instance_klass(), "must be"); } } - } else if (ref->msotype() == MetaspaceObj::SymbolType) { + } else if (ref->type() == MetaspaceClosureType::SymbolType) { // Make sure the symbol won't be GC'ed while we are dumping the archive. Symbol* sym = (Symbol*)ref->obj(); sym->increment_refcount(); @@ -271,11 +271,6 @@ void ArchiveBuilder::gather_klasses_and_symbols() { aot_log_info(aot)("Gathering classes and symbols ... "); GatherKlassesAndSymbols doit(this); iterate_roots(&doit); -#if INCLUDE_CDS_JAVA_HEAP - if (CDSConfig::is_dumping_full_module_graph()) { - ClassLoaderDataShared::iterate_symbols(&doit); - } -#endif doit.finish(); if (CDSConfig::is_dumping_static_archive()) { @@ -446,14 +441,14 @@ bool ArchiveBuilder::gather_one_source_obj(MetaspaceClosure::Ref* ref, bool read } #ifdef ASSERT - if (ref->msotype() == MetaspaceObj::MethodType) { + if (ref->type() == MetaspaceClosureType::MethodType) { Method* m = (Method*)ref->obj(); assert(!RegeneratedClasses::has_been_regenerated((address)m->method_holder()), "Should not archive methods in a class that has been regenerated"); } #endif - if (ref->msotype() == MetaspaceObj::MethodDataType) { + if (ref->type() == MetaspaceClosureType::MethodDataType) { MethodData* md = (MethodData*)ref->obj(); md->clean_method_data(false /* always_clean */); } @@ -554,16 +549,16 @@ ArchiveBuilder::FollowMode ArchiveBuilder::get_follow_mode(MetaspaceClosure::Ref if (CDSConfig::is_dumping_dynamic_archive() && AOTMetaspace::in_aot_cache(obj)) { // Don't dump existing shared metadata again. return point_to_it; - } else if (ref->msotype() == MetaspaceObj::MethodDataType || - ref->msotype() == MetaspaceObj::MethodCountersType || - ref->msotype() == MetaspaceObj::KlassTrainingDataType || - ref->msotype() == MetaspaceObj::MethodTrainingDataType || - ref->msotype() == MetaspaceObj::CompileTrainingDataType) { + } else if (ref->type() == MetaspaceClosureType::MethodDataType || + ref->type() == MetaspaceClosureType::MethodCountersType || + ref->type() == MetaspaceClosureType::KlassTrainingDataType || + ref->type() == MetaspaceClosureType::MethodTrainingDataType || + ref->type() == MetaspaceClosureType::CompileTrainingDataType) { return (TrainingData::need_data() || TrainingData::assembling_data()) ? make_a_copy : set_to_null; - } else if (ref->msotype() == MetaspaceObj::AdapterHandlerEntryType) { + } else if (ref->type() == MetaspaceClosureType::AdapterHandlerEntryType) { return CDSConfig::is_dumping_adapters() ? make_a_copy : set_to_null; } else { - if (ref->msotype() == MetaspaceObj::ClassType) { + if (ref->type() == MetaspaceClosureType::ClassType) { Klass* klass = (Klass*)ref->obj(); assert(klass->is_klass(), "must be"); if (RegeneratedClasses::has_been_regenerated(klass)) { @@ -571,7 +566,12 @@ ArchiveBuilder::FollowMode ArchiveBuilder::get_follow_mode(MetaspaceClosure::Ref } if (is_excluded(klass)) { ResourceMark rm; - log_debug(cds, dynamic)("Skipping class (excluded): %s", klass->external_name()); + aot_log_trace(aot)("pointer set to null: class (excluded): %s", klass->external_name()); + return set_to_null; + } + if (klass->is_array_klass() && CDSConfig::is_dumping_dynamic_archive()) { + ResourceMark rm; + aot_log_trace(aot)("pointer set to null: array class not supported in dynamic region: %s", klass->external_name()); return set_to_null; } } @@ -615,15 +615,6 @@ void ArchiveBuilder::dump_rw_metadata() { ResourceMark rm; aot_log_info(aot)("Allocating RW objects ... "); make_shallow_copies(&_rw_region, &_rw_src_objs); - -#if INCLUDE_CDS_JAVA_HEAP - if (CDSConfig::is_dumping_full_module_graph()) { - // Archive the ModuleEntry's and PackageEntry's of the 3 built-in loaders - char* start = rw_region()->top(); - ClassLoaderDataShared::allocate_archived_tables(); - alloc_stats()->record_modules(rw_region()->top() - start, /*read_only*/false); - } -#endif } void ArchiveBuilder::dump_ro_metadata() { @@ -632,15 +623,6 @@ void ArchiveBuilder::dump_ro_metadata() { start_dump_region(&_ro_region); make_shallow_copies(&_ro_region, &_ro_src_objs); - -#if INCLUDE_CDS_JAVA_HEAP - if (CDSConfig::is_dumping_full_module_graph()) { - char* start = ro_region()->top(); - ClassLoaderDataShared::init_archived_tables(); - alloc_stats()->record_modules(ro_region()->top() - start, /*read_only*/true); - } -#endif - RegeneratedClasses::record_regenerated_objects(); } @@ -658,7 +640,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s size_t alignment = SharedSpaceObjectAlignment; // alignment for the dest pointer char* oldtop = dump_region->top(); - if (src_info->msotype() == MetaspaceObj::ClassType) { + if (src_info->type() == MetaspaceClosureType::ClassType) { // Allocate space for a pointer directly in front of the future InstanceKlass, so // we can do a quick lookup from InstanceKlass* -> RunTimeClassInfo* // without building another hashtable. See RunTimeClassInfo::get_for() @@ -674,7 +656,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s alignment = nth_bit(ArchiveBuilder::precomputed_narrow_klass_shift()); } #endif - } else if (src_info->msotype() == MetaspaceObj::SymbolType) { + } else if (src_info->type() == MetaspaceClosureType::SymbolType) { // Symbols may be allocated by using AllocateHeap, so their sizes // may be less than size_in_bytes() indicates. bytes = ((Symbol*)src)->byte_size(); @@ -684,7 +666,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s memcpy(dest, src, bytes); // Update the hash of buffered sorted symbols for static dump so that the symbols have deterministic contents - if (CDSConfig::is_dumping_static_archive() && (src_info->msotype() == MetaspaceObj::SymbolType)) { + if (CDSConfig::is_dumping_static_archive() && (src_info->type() == MetaspaceClosureType::SymbolType)) { Symbol* buffered_symbol = (Symbol*)dest; assert(((Symbol*)src)->is_permanent(), "archived symbols must be permanent"); buffered_symbol->update_identity_hash(); @@ -699,7 +681,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s } } - intptr_t* archived_vtable = CppVtables::get_archived_vtable(src_info->msotype(), (address)dest); + intptr_t* archived_vtable = CppVtables::get_archived_vtable(src_info->type(), (address)dest); if (archived_vtable != nullptr) { *(address*)dest = (address)archived_vtable; ArchivePtrMarker::mark_pointer((address*)dest); @@ -709,7 +691,7 @@ void ArchiveBuilder::make_shallow_copy(DumpRegion *dump_region, SourceObjInfo* s src_info->set_buffered_addr((address)dest); char* newtop = dump_region->top(); - _alloc_stats.record(src_info->msotype(), int(newtop - oldtop), src_info->read_only()); + _alloc_stats.record(src_info->type(), int(newtop - oldtop), src_info->read_only()); DEBUG_ONLY(_alloc_stats.verify((int)dump_region->used(), src_info->read_only())); } @@ -992,15 +974,15 @@ void ArchiveBuilder::make_training_data_shareable() { return; } - if (info.msotype() == MetaspaceObj::KlassTrainingDataType || - info.msotype() == MetaspaceObj::MethodTrainingDataType || - info.msotype() == MetaspaceObj::CompileTrainingDataType) { + if (info.type() == MetaspaceClosureType::KlassTrainingDataType || + info.type() == MetaspaceClosureType::MethodTrainingDataType || + info.type() == MetaspaceClosureType::CompileTrainingDataType) { TrainingData* buffered_td = (TrainingData*)info.buffered_addr(); buffered_td->remove_unshareable_info(); - } else if (info.msotype() == MetaspaceObj::MethodDataType) { + } else if (info.type() == MetaspaceClosureType::MethodDataType) { MethodData* buffered_mdo = (MethodData*)info.buffered_addr(); buffered_mdo->remove_unshareable_info(); - } else if (info.msotype() == MetaspaceObj::MethodCountersType) { + } else if (info.type() == MetaspaceClosureType::MethodCountersType) { MethodCounters* buffered_mc = (MethodCounters*)info.buffered_addr(); buffered_mc->remove_unshareable_info(); } diff --git a/src/hotspot/share/cds/archiveBuilder.hpp b/src/hotspot/share/cds/archiveBuilder.hpp index 9a628439039..9de6c02edc5 100644 --- a/src/hotspot/share/cds/archiveBuilder.hpp +++ b/src/hotspot/share/cds/archiveBuilder.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -134,13 +134,13 @@ private: int _size_in_bytes; int _id; // Each object has a unique serial ID, starting from zero. The ID is assigned // when the object is added into _source_objs. - MetaspaceObj::Type _msotype; + MetaspaceClosureType _type; address _source_addr; // The source object to be copied. address _buffered_addr; // The copy of this object insider the buffer. public: SourceObjInfo(MetaspaceClosure::Ref* ref, bool read_only, FollowMode follow_mode) : _ptrmap_start(0), _ptrmap_end(0), _read_only(read_only), _has_embedded_pointer(false), _follow_mode(follow_mode), - _size_in_bytes(ref->size() * BytesPerWord), _id(0), _msotype(ref->msotype()), + _size_in_bytes(ref->size() * BytesPerWord), _id(0), _type(ref->type()), _source_addr(ref->obj()) { if (follow_mode == point_to_it) { _buffered_addr = ref->obj(); @@ -155,7 +155,7 @@ private: SourceObjInfo(address src, SourceObjInfo* renegerated_obj_info) : _ptrmap_start(0), _ptrmap_end(0), _read_only(false), _follow_mode(renegerated_obj_info->_follow_mode), - _size_in_bytes(0), _msotype(renegerated_obj_info->_msotype), + _size_in_bytes(0), _type(renegerated_obj_info->_type), _source_addr(src), _buffered_addr(renegerated_obj_info->_buffered_addr) {} bool should_copy() const { return _follow_mode == make_a_copy; } @@ -182,7 +182,7 @@ private: } return _buffered_addr; } - MetaspaceObj::Type msotype() const { return _msotype; } + MetaspaceClosureType type() const { return _type; } FollowMode follow_mode() const { return _follow_mode; } }; diff --git a/src/hotspot/share/cds/cppVtables.cpp b/src/hotspot/share/cds/cppVtables.cpp index f2862454286..da68fa70761 100644 --- a/src/hotspot/share/cds/cppVtables.cpp +++ b/src/hotspot/share/cds/cppVtables.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -22,12 +22,14 @@ * */ +#include "cds/aotGrowableArray.hpp" #include "cds/aotMetaspace.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" #include "cds/cdsConfig.hpp" #include "cds/cppVtables.hpp" #include "logging/log.hpp" +#include "memory/resourceArea.hpp" #include "oops/instanceClassLoaderKlass.hpp" #include "oops/instanceMirrorKlass.hpp" #include "oops/instanceRefKlass.hpp" @@ -53,6 +55,19 @@ // + at run time: we clone the actual contents of the vtables from libjvm.so // into our own tables. + +#ifndef PRODUCT + +// AOTGrowableArray has a vtable only when in non-product builds (due to +// the virtual printing functions in AnyObj). + +using GrowableArray_ModuleEntry_ptr = AOTGrowableArray; + +#define DEBUG_CPP_VTABLE_TYPES_DO(f) \ + f(GrowableArray_ModuleEntry_ptr) \ + +#endif + // Currently, the archive contains ONLY the following types of objects that have C++ vtables. #define CPP_VTABLE_TYPES_DO(f) \ f(ConstantPool) \ @@ -68,7 +83,8 @@ f(TypeArrayKlass) \ f(KlassTrainingData) \ f(MethodTrainingData) \ - f(CompileTrainingData) + f(CompileTrainingData) \ + NOT_PRODUCT(DEBUG_CPP_VTABLE_TYPES_DO(f)) class CppVtableInfo { intptr_t _vtable_size; @@ -86,7 +102,7 @@ public: } }; -static inline intptr_t* vtable_of(const Metadata* m) { +static inline intptr_t* vtable_of(const void* m) { return *((intptr_t**)m); } @@ -116,6 +132,7 @@ CppVtableInfo* CppVtableCloner::allocate_and_initialize(const char* name) { template void CppVtableCloner::initialize(const char* name, CppVtableInfo* info) { + ResourceMark rm; T tmp; // Allocate temporary dummy metadata object to get to the original vtable. int n = info->vtable_size(); intptr_t* srcvtable = vtable_of(&tmp); @@ -268,7 +285,7 @@ void CppVtables::serialize(SerializeClosure* soc) { } } -intptr_t* CppVtables::get_archived_vtable(MetaspaceObj::Type msotype, address obj) { +intptr_t* CppVtables::get_archived_vtable(MetaspaceClosureType type, address obj) { if (!_orig_cpp_vtptrs_inited) { CPP_VTABLE_TYPES_DO(INIT_ORIG_CPP_VTPTRS); _orig_cpp_vtptrs_inited = true; @@ -276,19 +293,23 @@ intptr_t* CppVtables::get_archived_vtable(MetaspaceObj::Type msotype, address ob assert(CDSConfig::is_dumping_archive(), "sanity"); int kind = -1; - switch (msotype) { - case MetaspaceObj::SymbolType: - case MetaspaceObj::TypeArrayU1Type: - case MetaspaceObj::TypeArrayU2Type: - case MetaspaceObj::TypeArrayU4Type: - case MetaspaceObj::TypeArrayU8Type: - case MetaspaceObj::TypeArrayOtherType: - case MetaspaceObj::ConstMethodType: - case MetaspaceObj::ConstantPoolCacheType: - case MetaspaceObj::AnnotationsType: - case MetaspaceObj::RecordComponentType: - case MetaspaceObj::AdapterHandlerEntryType: - case MetaspaceObj::AdapterFingerPrintType: + switch (type) { + case MetaspaceClosureType::SymbolType: + case MetaspaceClosureType::TypeArrayU1Type: + case MetaspaceClosureType::TypeArrayU2Type: + case MetaspaceClosureType::TypeArrayU4Type: + case MetaspaceClosureType::TypeArrayU8Type: + case MetaspaceClosureType::TypeArrayOtherType: + case MetaspaceClosureType::CArrayType: + case MetaspaceClosureType::ConstMethodType: + case MetaspaceClosureType::ConstantPoolCacheType: + case MetaspaceClosureType::AnnotationsType: + case MetaspaceClosureType::ModuleEntryType: + case MetaspaceClosureType::PackageEntryType: + case MetaspaceClosureType::RecordComponentType: + case MetaspaceClosureType::AdapterHandlerEntryType: + case MetaspaceClosureType::AdapterFingerPrintType: + PRODUCT_ONLY(case MetaspaceClosureType::GrowableArrayType:) // These have no vtables. break; default: diff --git a/src/hotspot/share/cds/cppVtables.hpp b/src/hotspot/share/cds/cppVtables.hpp index b40ca036023..9e28ba020ee 100644 --- a/src/hotspot/share/cds/cppVtables.hpp +++ b/src/hotspot/share/cds/cppVtables.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -27,6 +27,7 @@ #include "memory/allocation.hpp" #include "memory/allStatic.hpp" +#include "memory/metaspaceClosureType.hpp" #include "utilities/globalDefinitions.hpp" class ArchiveBuilder; @@ -40,7 +41,7 @@ class CppVtables : AllStatic { public: static void dumptime_init(ArchiveBuilder* builder); static void zero_archived_vtables(); - static intptr_t* get_archived_vtable(MetaspaceObj::Type msotype, address obj); + static intptr_t* get_archived_vtable(MetaspaceClosureType type, address obj); static void serialize(SerializeClosure* sc); static bool is_valid_shared_method(const Method* m) NOT_CDS_RETURN_(false); static char* vtables_serialized_base() { return _vtables_serialized_base; } diff --git a/src/hotspot/share/cds/dumpAllocStats.hpp b/src/hotspot/share/cds/dumpAllocStats.hpp index 7d651320e6f..4553f0f6a01 100644 --- a/src/hotspot/share/cds/dumpAllocStats.hpp +++ b/src/hotspot/share/cds/dumpAllocStats.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -27,32 +27,34 @@ #include "classfile/compactHashtable.hpp" #include "memory/allocation.hpp" +#include "memory/metaspaceClosureType.hpp" // This is for dumping detailed statistics for the allocations // in the shared spaces. class DumpAllocStats : public StackObj { public: - // Here's poor man's enum inheritance -#define SHAREDSPACE_OBJ_TYPES_DO(f) \ - METASPACE_OBJ_TYPES_DO(f) \ +#define DUMPED_OBJ_TYPES_DO(f) \ + METASPACE_CLOSURE_TYPES_DO(f) \ f(SymbolHashentry) \ f(SymbolBucket) \ f(StringHashentry) \ f(StringBucket) \ - f(ModulesNatives) \ f(CppVTables) \ f(Other) +#define DUMPED_TYPE_DECLARE(name) name ## Type, +#define DUMPED_TYPE_NAME_CASE(name) case name ## Type: return #name; + enum Type { // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc - SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE) + DUMPED_OBJ_TYPES_DO(DUMPED_TYPE_DECLARE) _number_of_types }; static const char* type_name(Type type) { switch(type) { - SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_NAME_CASE) + DUMPED_OBJ_TYPES_DO(DUMPED_TYPE_NAME_CASE) default: ShouldNotReachHere(); return nullptr; @@ -101,16 +103,12 @@ public: CompactHashtableStats* symbol_stats() { return &_symbol_stats; } CompactHashtableStats* string_stats() { return &_string_stats; } - void record(MetaspaceObj::Type type, int byte_size, bool read_only) { - assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity"); + void record(MetaspaceClosureType type, int byte_size, bool read_only) { + int t = (int)type; + assert(t >= 0 && t < (int)MetaspaceClosureType::_number_of_types, "sanity"); int which = (read_only) ? RO : RW; - _counts[which][type] ++; - _bytes [which][type] += byte_size; - } - - void record_modules(int byte_size, bool read_only) { - int which = (read_only) ? RO : RW; - _bytes [which][ModulesNativesType] += byte_size; + _counts[which][t] ++; + _bytes [which][t] += byte_size; } void record_other_type(int byte_size, bool read_only) { diff --git a/src/hotspot/share/cds/heapShared.cpp b/src/hotspot/share/cds/heapShared.cpp index fdc335f3799..89694c6780e 100644 --- a/src/hotspot/share/cds/heapShared.cpp +++ b/src/hotspot/share/cds/heapShared.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -948,10 +948,6 @@ void HeapShared::archive_subgraphs() { true /* is_full_module_graph */); } } - - if (CDSConfig::is_dumping_full_module_graph()) { - Modules::verify_archived_modules(); - } } // diff --git a/src/hotspot/share/ci/ciField.cpp b/src/hotspot/share/ci/ciField.cpp index 19e05784f4d..e0c818f02fc 100644 --- a/src/hotspot/share/ci/ciField.cpp +++ b/src/hotspot/share/ci/ciField.cpp @@ -216,6 +216,10 @@ ciField::ciField(fieldDescriptor *fd) : static bool trust_final_non_static_fields(ciInstanceKlass* holder) { if (holder == nullptr) return false; + if (holder->trust_final_fields()) { + // Explicit opt-in from system classes + return true; + } // Even if general trusting is disabled, trust system-built closures in these packages. if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke") || holder->is_in_package("java/lang/reflect") || holder->is_in_package("jdk/internal/reflect") || @@ -230,14 +234,6 @@ static bool trust_final_non_static_fields(ciInstanceKlass* holder) { // Trust final fields in records if (holder->is_record()) return true; - // Trust Atomic*FieldUpdaters: they are very important for performance, and make up one - // more reason not to use Unsafe, if their final fields are trusted. See more in JDK-8140483. - if (holder->name() == ciSymbols::java_util_concurrent_atomic_AtomicIntegerFieldUpdater_Impl() || - holder->name() == ciSymbols::java_util_concurrent_atomic_AtomicLongFieldUpdater_CASUpdater() || - holder->name() == ciSymbols::java_util_concurrent_atomic_AtomicLongFieldUpdater_LockedUpdater() || - holder->name() == ciSymbols::java_util_concurrent_atomic_AtomicReferenceFieldUpdater_Impl()) { - return true; - } return TrustFinalNonStaticFields; } diff --git a/src/hotspot/share/ci/ciInstanceKlass.cpp b/src/hotspot/share/ci/ciInstanceKlass.cpp index 64b9acf9146..33bcabc4566 100644 --- a/src/hotspot/share/ci/ciInstanceKlass.cpp +++ b/src/hotspot/share/ci/ciInstanceKlass.cpp @@ -65,6 +65,7 @@ ciInstanceKlass::ciInstanceKlass(Klass* k) : _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods(); _is_hidden = ik->is_hidden(); _is_record = ik->is_record(); + _trust_final_fields = ik->trust_final_fields(); _nonstatic_fields = nullptr; // initialized lazily by compute_nonstatic_fields: _has_injected_fields = -1; _implementor = nullptr; // we will fill these lazily diff --git a/src/hotspot/share/ci/ciInstanceKlass.hpp b/src/hotspot/share/ci/ciInstanceKlass.hpp index a1b2d8dd12d..8ccf1fadfb7 100644 --- a/src/hotspot/share/ci/ciInstanceKlass.hpp +++ b/src/hotspot/share/ci/ciInstanceKlass.hpp @@ -59,6 +59,7 @@ private: bool _has_nonstatic_concrete_methods; bool _is_hidden; bool _is_record; + bool _trust_final_fields; bool _has_trusted_loader; ciFlags _flags; @@ -207,6 +208,10 @@ public: return _is_record; } + bool trust_final_fields() const { + return _trust_final_fields; + } + ciInstanceKlass* get_canonical_holder(int offset); ciField* get_field_by_offset(int field_offset, bool is_static); ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static); diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index c9d9d3632b5..817d0c64d11 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -943,6 +943,7 @@ public: _java_lang_Deprecated_for_removal, _jdk_internal_vm_annotation_AOTSafeClassInitializer, _method_AOTRuntimeSetup, + _jdk_internal_vm_annotation_TrustFinalFields, _annotation_LIMIT }; const Location _location; @@ -1878,6 +1879,11 @@ AnnotationCollector::annotation_index(const ClassLoaderData* loader_data, if (!privileged) break; // only allow in privileged code return _field_Stable; } + case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_TrustFinalFields_signature): { + if (_location != _in_class) break; // only allow for classes + if (!privileged) break; // only allow in privileged code + return _jdk_internal_vm_annotation_TrustFinalFields; + } case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): { if (_location != _in_field && _location != _in_class) { break; // only allow for fields and classes @@ -1992,6 +1998,9 @@ void ClassFileParser::ClassAnnotationCollector::apply_to(InstanceKlass* ik) { if (has_annotation(_jdk_internal_vm_annotation_AOTSafeClassInitializer)) { ik->set_has_aot_safe_initializer(); } + if (has_annotation(_jdk_internal_vm_annotation_TrustFinalFields)) { + ik->set_trust_final_fields(true); + } } #define MAX_ARGS_SIZE 255 diff --git a/src/hotspot/share/classfile/classLoaderDataShared.cpp b/src/hotspot/share/classfile/classLoaderDataShared.cpp index 7a7743edd03..d415fe64bac 100644 --- a/src/hotspot/share/classfile/classLoaderDataShared.cpp +++ b/src/hotspot/share/classfile/classLoaderDataShared.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -33,6 +33,7 @@ #include "classfile/packageEntry.hpp" #include "classfile/systemDictionary.hpp" #include "logging/log.hpp" +#include "memory/metaspaceClosure.hpp" #include "runtime/handles.inline.hpp" #include "runtime/safepoint.hpp" @@ -56,9 +57,9 @@ class ArchivedClassLoaderData { public: ArchivedClassLoaderData() : _packages(nullptr), _modules(nullptr), _unnamed_module(nullptr) {} - void iterate_symbols(ClassLoaderData* loader_data, MetaspaceClosure* closure); - void allocate(ClassLoaderData* loader_data); - void init_archived_entries(ClassLoaderData* loader_data); + void iterate_roots(MetaspaceClosure* closure); + void build_tables(ClassLoaderData* loader_data, TRAPS); + void remove_unshareable_info(); ModuleEntry* unnamed_module() { return _unnamed_module; } @@ -80,17 +81,14 @@ static ModuleEntry* _archived_javabase_moduleEntry = nullptr; static int _platform_loader_root_index = -1; static int _system_loader_root_index = -1; -void ArchivedClassLoaderData::iterate_symbols(ClassLoaderData* loader_data, MetaspaceClosure* closure) { +void ArchivedClassLoaderData::iterate_roots(MetaspaceClosure* it) { assert(CDSConfig::is_dumping_full_module_graph(), "must be"); - assert_valid(loader_data); - if (loader_data != nullptr) { - loader_data->packages()->iterate_symbols(closure); - loader_data->modules() ->iterate_symbols(closure); - loader_data->unnamed_module()->iterate_symbols(closure); - } + it->push(&_packages); + it->push(&_modules); + it->push(&_unnamed_module); } -void ArchivedClassLoaderData::allocate(ClassLoaderData* loader_data) { +void ArchivedClassLoaderData::build_tables(ClassLoaderData* loader_data, TRAPS) { assert(CDSConfig::is_dumping_full_module_graph(), "must be"); assert_valid(loader_data); if (loader_data != nullptr) { @@ -98,19 +96,28 @@ void ArchivedClassLoaderData::allocate(ClassLoaderData* loader_data) { // address of the Symbols, which may be relocated at runtime due to ASLR. // So we store the packages/modules in Arrays. At runtime, we create // the hashtables using these arrays. - _packages = loader_data->packages()->allocate_archived_entries(); - _modules = loader_data->modules() ->allocate_archived_entries(); - _unnamed_module = loader_data->unnamed_module()->allocate_archived_entry(); + _packages = loader_data->packages()->build_aot_table(loader_data, CHECK); + _modules = loader_data->modules()->build_aot_table(loader_data, CHECK); + _unnamed_module = loader_data->unnamed_module(); } } -void ArchivedClassLoaderData::init_archived_entries(ClassLoaderData* loader_data) { - assert(CDSConfig::is_dumping_full_module_graph(), "must be"); - assert_valid(loader_data); - if (loader_data != nullptr) { - loader_data->packages()->init_archived_entries(_packages); - loader_data->modules() ->init_archived_entries(_modules); - _unnamed_module->init_as_archived_entry(); +void ArchivedClassLoaderData::remove_unshareable_info() { + if (_packages != nullptr) { + _packages = ArchiveBuilder::current()->get_buffered_addr(_packages); + for (int i = 0; i < _packages->length(); i++) { + _packages->at(i)->remove_unshareable_info(); + } + } + if (_modules != nullptr) { + _modules = ArchiveBuilder::current()->get_buffered_addr(_modules); + for (int i = 0; i < _modules->length(); i++) { + _modules->at(i)->remove_unshareable_info(); + } + } + if (_unnamed_module != nullptr) { + _unnamed_module = ArchiveBuilder::current()->get_buffered_addr(_unnamed_module); + _unnamed_module->remove_unshareable_info(); } } @@ -153,7 +160,6 @@ void ArchivedClassLoaderData::clear_archived_oops() { // ------------------------------ void ClassLoaderDataShared::load_archived_platform_and_system_class_loaders() { -#if INCLUDE_CDS_JAVA_HEAP // The streaming object loader prefers loading the class loader related objects before // the CLD constructor which has a NoSafepointVerifier. if (!HeapShared::is_loading_streaming_mode()) { @@ -178,7 +184,6 @@ void ClassLoaderDataShared::load_archived_platform_and_system_class_loaders() { if (system_loader_module_entry != nullptr) { system_loader_module_entry->preload_archived_oops(); } -#endif } static ClassLoaderData* null_class_loader_data() { @@ -210,28 +215,27 @@ void ClassLoaderDataShared::ensure_module_entry_table_exists(oop class_loader) { assert(met != nullptr, "sanity"); } -void ClassLoaderDataShared::iterate_symbols(MetaspaceClosure* closure) { +void ClassLoaderDataShared::build_tables(TRAPS) { assert(CDSConfig::is_dumping_full_module_graph(), "must be"); - _archived_boot_loader_data.iterate_symbols (null_class_loader_data(), closure); - _archived_platform_loader_data.iterate_symbols(java_platform_loader_data_or_null(), closure); - _archived_system_loader_data.iterate_symbols (java_system_loader_data_or_null(), closure); + _archived_boot_loader_data.build_tables(null_class_loader_data(), CHECK); + _archived_platform_loader_data.build_tables(java_platform_loader_data_or_null(), CHECK); + _archived_system_loader_data.build_tables(java_system_loader_data_or_null(), CHECK); } -void ClassLoaderDataShared::allocate_archived_tables() { +void ClassLoaderDataShared::iterate_roots(MetaspaceClosure* it) { assert(CDSConfig::is_dumping_full_module_graph(), "must be"); - _archived_boot_loader_data.allocate (null_class_loader_data()); - _archived_platform_loader_data.allocate(java_platform_loader_data_or_null()); - _archived_system_loader_data.allocate (java_system_loader_data_or_null()); + _archived_boot_loader_data.iterate_roots(it); + _archived_platform_loader_data.iterate_roots(it); + _archived_system_loader_data.iterate_roots(it); } -void ClassLoaderDataShared::init_archived_tables() { +void ClassLoaderDataShared::remove_unshareable_info() { assert(CDSConfig::is_dumping_full_module_graph(), "must be"); + _archived_boot_loader_data.remove_unshareable_info(); + _archived_platform_loader_data.remove_unshareable_info(); + _archived_system_loader_data.remove_unshareable_info(); - _archived_boot_loader_data.init_archived_entries (null_class_loader_data()); - _archived_platform_loader_data.init_archived_entries(java_platform_loader_data_or_null()); - _archived_system_loader_data.init_archived_entries (java_system_loader_data_or_null()); - - _archived_javabase_moduleEntry = ModuleEntry::get_archived_entry(ModuleEntryTable::javabase_moduleEntry()); + _archived_javabase_moduleEntry = ArchiveBuilder::current()->get_buffered_addr(ModuleEntryTable::javabase_moduleEntry()); _platform_loader_root_index = HeapShared::append_root(SystemDictionary::java_platform_loader()); _system_loader_root_index = HeapShared::append_root(SystemDictionary::java_system_loader()); @@ -271,7 +275,6 @@ ModuleEntry* ClassLoaderDataShared::archived_unnamed_module(ClassLoaderData* loa return archived_module; } - void ClassLoaderDataShared::clear_archived_oops() { assert(!CDSConfig::is_using_full_module_graph(), "must be"); _archived_boot_loader_data.clear_archived_oops(); diff --git a/src/hotspot/share/classfile/classLoaderDataShared.hpp b/src/hotspot/share/classfile/classLoaderDataShared.hpp index 39d0a89418f..2cf37310e50 100644 --- a/src/hotspot/share/classfile/classLoaderDataShared.hpp +++ b/src/hotspot/share/classfile/classLoaderDataShared.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -40,11 +40,11 @@ class ClassLoaderDataShared : AllStatic { public: static void load_archived_platform_and_system_class_loaders() NOT_CDS_JAVA_HEAP_RETURN; static void restore_archived_modules_for_preloading_classes(JavaThread* current) NOT_CDS_JAVA_HEAP_RETURN; + static void build_tables(TRAPS) NOT_CDS_JAVA_HEAP_RETURN; + static void iterate_roots(MetaspaceClosure* closure) NOT_CDS_JAVA_HEAP_RETURN; + static void remove_unshareable_info() NOT_CDS_JAVA_HEAP_RETURN; #if INCLUDE_CDS_JAVA_HEAP static void ensure_module_entry_tables_exist(); - static void allocate_archived_tables(); - static void iterate_symbols(MetaspaceClosure* closure); - static void init_archived_tables(); static void serialize(SerializeClosure* f); static void clear_archived_oops(); static void restore_archived_entries_for_null_class_loader_data(); diff --git a/src/hotspot/share/classfile/moduleEntry.cpp b/src/hotspot/share/classfile/moduleEntry.cpp index 5fb3d6f2d13..b5b8aa4ef55 100644 --- a/src/hotspot/share/classfile/moduleEntry.cpp +++ b/src/hotspot/share/classfile/moduleEntry.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -23,6 +23,7 @@ */ #include "cds/aotClassLocation.hpp" +#include "cds/aotGrowableArray.inline.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" #include "cds/cdsConfig.hpp" @@ -37,6 +38,7 @@ #include "jni.h" #include "logging/log.hpp" #include "logging/logStream.hpp" +#include "memory/metadataFactory.hpp" #include "memory/resourceArea.hpp" #include "memory/universe.hpp" #include "oops/oopHandle.inline.hpp" @@ -44,7 +46,6 @@ #include "runtime/handles.inline.hpp" #include "runtime/safepoint.hpp" #include "utilities/events.hpp" -#include "utilities/growableArray.hpp" #include "utilities/hashTable.hpp" #include "utilities/ostream.hpp" #include "utilities/quickSort.hpp" @@ -167,7 +168,7 @@ void ModuleEntry::add_read(ModuleEntry* m) { } else { if (reads() == nullptr) { // Lazily create a module's reads list - GrowableArray* new_reads = new (mtModule) GrowableArray(MODULE_READS_SIZE, mtModule); + AOTGrowableArray* new_reads = new (mtModule) AOTGrowableArray(MODULE_READS_SIZE, mtModule); set_reads(new_reads); } @@ -274,8 +275,7 @@ ModuleEntry::ModuleEntry(Handle module_handle, _has_default_read_edges(false), _must_walk_reads(false), _is_open(is_open), - _is_patched(false) - DEBUG_ONLY(COMMA _reads_is_archived(false)) { + _is_patched(false) { // Initialize fields specific to a ModuleEntry if (_name == nullptr) { @@ -394,7 +394,6 @@ ModuleEntryTable::~ModuleEntryTable() { ModuleEntryTableDeleter deleter; _table.unlink(&deleter); assert(_table.number_of_entries() == 0, "should have removed all entries"); - } void ModuleEntry::set_loader_data(ClassLoaderData* cld) { @@ -402,147 +401,51 @@ void ModuleEntry::set_loader_data(ClassLoaderData* cld) { _loader_data = cld; } +void ModuleEntry::metaspace_pointers_do(MetaspaceClosure* it) { + it->push(&_name); + it->push(&_reads); + it->push(&_version); + it->push(&_location); +} + #if INCLUDE_CDS_JAVA_HEAP -typedef HashTable< - const ModuleEntry*, - ModuleEntry*, - 557, // prime number - AnyObj::C_HEAP> ArchivedModuleEntries; -static ArchivedModuleEntries* _archive_modules_entries = nullptr; - -#ifndef PRODUCT -static int _num_archived_module_entries = 0; -static int _num_inited_module_entries = 0; -#endif - bool ModuleEntry::should_be_archived() const { return SystemDictionaryShared::is_builtin_loader(loader_data()); } -ModuleEntry* ModuleEntry::allocate_archived_entry() const { - precond(should_be_archived()); - precond(CDSConfig::is_dumping_full_module_graph()); - ModuleEntry* archived_entry = (ModuleEntry*)ArchiveBuilder::rw_region_alloc(sizeof(ModuleEntry)); - memcpy((void*)archived_entry, (void*)this, sizeof(ModuleEntry)); +void ModuleEntry::remove_unshareable_info() { + _archived_module_index = HeapShared::append_root(module_oop()); - archived_entry->_archived_module_index = HeapShared::append_root(module_oop()); - if (_archive_modules_entries == nullptr) { - _archive_modules_entries = new (mtClass)ArchivedModuleEntries(); - } - assert(_archive_modules_entries->get(this) == nullptr, "Each ModuleEntry must not be shared across ModuleEntryTables"); - _archive_modules_entries->put(this, archived_entry); - DEBUG_ONLY(_num_archived_module_entries++); - - if (CDSConfig::is_dumping_final_static_archive()) { - OopHandle null_handle; - archived_entry->_shared_pd = null_handle; - } else { - assert(archived_entry->shared_protection_domain() == nullptr, "never set during -Xshare:dump"); + if (_reads != nullptr) { + _reads->set_in_aot_cache(); } // Clear handles and restore at run time. Handles cannot be archived. + if (CDSConfig::is_dumping_final_static_archive()) { + OopHandle null_handle; + _shared_pd = null_handle; + } else { + assert(shared_protection_domain() == nullptr, "never set during -Xshare:dump"); + } + OopHandle null_handle; - archived_entry->_module_handle = null_handle; - - // For verify_archived_module_entries() - DEBUG_ONLY(_num_inited_module_entries++); - - if (log_is_enabled(Info, aot, module)) { - ResourceMark rm; - LogStream ls(Log(aot, module)::info()); - ls.print("Stored in archive: "); - archived_entry->print(&ls); - } - return archived_entry; -} - -bool ModuleEntry::has_been_archived() { - assert(!ArchiveBuilder::current()->is_in_buffer_space(this), "must be called on original ModuleEntry"); - return _archive_modules_entries->contains(this); -} - -ModuleEntry* ModuleEntry::get_archived_entry(ModuleEntry* orig_entry) { - ModuleEntry** ptr = _archive_modules_entries->get(orig_entry); - assert(ptr != nullptr && *ptr != nullptr, "must have been allocated"); - return *ptr; -} - -// This function is used to archive ModuleEntry::_reads and PackageEntry::_qualified_exports. -// GrowableArray cannot be directly archived, as it needs to be expandable at runtime. -// Write it out as an Array, and convert it back to GrowableArray at runtime. -Array* ModuleEntry::write_growable_array(GrowableArray* array) { - Array* archived_array = nullptr; - int length = (array == nullptr) ? 0 : array->length(); - if (length > 0) { - archived_array = ArchiveBuilder::new_ro_array(length); - for (int i = 0; i < length; i++) { - ModuleEntry* archived_entry = get_archived_entry(array->at(i)); - archived_array->at_put(i, archived_entry); - ArchivePtrMarker::mark_pointer((address*)archived_array->adr_at(i)); - } - } - - return archived_array; -} - -GrowableArray* ModuleEntry::restore_growable_array(Array* archived_array) { - GrowableArray* array = nullptr; - int length = (archived_array == nullptr) ? 0 : archived_array->length(); - if (length > 0) { - array = new (mtModule) GrowableArray(length, mtModule); - for (int i = 0; i < length; i++) { - ModuleEntry* archived_entry = archived_array->at(i); - array->append(archived_entry); - } - } - - return array; -} - -void ModuleEntry::iterate_symbols(MetaspaceClosure* closure) { - closure->push(&_name); - closure->push(&_version); - closure->push(&_location); -} - -void ModuleEntry::init_as_archived_entry() { - set_archived_reads(write_growable_array(reads())); + _module_handle = null_handle; _loader_data = nullptr; // re-init at runtime if (name() != nullptr) { - _shared_path_index = AOTClassLocationConfig::dumptime()->get_module_shared_path_index(_location); - _name = ArchiveBuilder::get_buffered_symbol(_name); - ArchivePtrMarker::mark_pointer((address*)&_name); + Symbol* src_location = ArchiveBuilder::current()->get_source_addr(_location); + _shared_path_index = AOTClassLocationConfig::dumptime()->get_module_shared_path_index(src_location); } else { // _shared_path_index is used only by SystemDictionary::is_shared_class_visible_impl() // for checking classes in named modules. _shared_path_index = -1; } - if (_version != nullptr) { - _version = ArchiveBuilder::get_buffered_symbol(_version); - } - if (_location != nullptr) { - _location = ArchiveBuilder::get_buffered_symbol(_location); - } JFR_ONLY(set_trace_id(0);) // re-init at runtime - - ArchivePtrMarker::mark_pointer((address*)&_reads); - ArchivePtrMarker::mark_pointer((address*)&_version); - ArchivePtrMarker::mark_pointer((address*)&_location); } -#ifndef PRODUCT -void ModuleEntry::verify_archived_module_entries() { - assert(_num_archived_module_entries == _num_inited_module_entries, - "%d ModuleEntries have been archived but %d of them have been properly initialized with archived java.lang.Module objects", - _num_archived_module_entries, _num_inited_module_entries); -} -#endif // PRODUCT - void ModuleEntry::load_from_archive(ClassLoaderData* loader_data) { assert(CDSConfig::is_using_archive(), "runtime only"); set_loader_data(loader_data); - set_reads(restore_growable_array(archived_reads())); JFR_ONLY(INIT_ID(this);) } @@ -581,38 +484,28 @@ static int compare_module_by_name(ModuleEntry* a, ModuleEntry* b) { return a->name()->fast_compare(b->name()); } -void ModuleEntryTable::iterate_symbols(MetaspaceClosure* closure) { - auto syms = [&] (const SymbolHandle& key, ModuleEntry*& m) { - m->iterate_symbols(closure); - }; - _table.iterate_all(syms); -} - -Array* ModuleEntryTable::allocate_archived_entries() { - Array* archived_modules = ArchiveBuilder::new_rw_array(_table.number_of_entries()); +Array* ModuleEntryTable::build_aot_table(ClassLoaderData* loader_data, TRAPS) { + Array* aot_table = + MetadataFactory::new_array(loader_data, _table.number_of_entries(), nullptr, CHECK_NULL); int n = 0; auto grab = [&] (const SymbolHandle& key, ModuleEntry*& m) { - archived_modules->at_put(n++, m); + m->pack_reads(); + aot_table->at_put(n++, m); + if (log_is_enabled(Info, aot, module)) { + ResourceMark rm; + LogStream ls(Log(aot, module)::info()); + ls.print("Stored in archive: "); + m->print(&ls); + } }; _table.iterate_all(grab); if (n > 1) { // Always allocate in the same order to produce deterministic archive. - QuickSort::sort(archived_modules->data(), n, compare_module_by_name); + QuickSort::sort(aot_table->data(), n, compare_module_by_name); } - for (int i = 0; i < n; i++) { - archived_modules->at_put(i, archived_modules->at(i)->allocate_archived_entry()); - ArchivePtrMarker::mark_pointer((address*)archived_modules->adr_at(i)); - } - return archived_modules; -} -void ModuleEntryTable::init_archived_entries(Array* archived_modules) { - assert(CDSConfig::is_dumping_full_module_graph(), "sanity"); - for (int i = 0; i < archived_modules->length(); i++) { - ModuleEntry* archived_entry = archived_modules->at(i); - archived_entry->init_as_archived_entry(); - } + return aot_table; } void ModuleEntryTable::load_archived_entries(ClassLoaderData* loader_data, diff --git a/src/hotspot/share/classfile/moduleEntry.hpp b/src/hotspot/share/classfile/moduleEntry.hpp index 2e1852c5369..1a0251a2c2a 100644 --- a/src/hotspot/share/classfile/moduleEntry.hpp +++ b/src/hotspot/share/classfile/moduleEntry.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -25,7 +25,9 @@ #ifndef SHARE_CLASSFILE_MODULEENTRY_HPP #define SHARE_CLASSFILE_MODULEENTRY_HPP +#include "cds/aotGrowableArray.hpp" #include "jni.h" +#include "memory/metaspaceClosureType.hpp" #include "oops/oopHandle.hpp" #include "oops/symbol.hpp" #include "oops/symbolHandle.hpp" @@ -68,11 +70,8 @@ private: // for shared classes from this module Symbol* _name; // name of this module ClassLoaderData* _loader_data; + AOTGrowableArray* _reads; // list of modules that are readable by this module - union { - GrowableArray* _reads; // list of modules that are readable by this module - Array* _archived_reads; // List of readable modules stored in the CDS archive - }; Symbol* _version; // module version number Symbol* _location; // module location CDS_ONLY(int _shared_path_index;) // >=0 if classes in this module are in CDS archive @@ -81,7 +80,6 @@ private: bool _must_walk_reads; // walk module's reads list at GC safepoints to purge out dead modules bool _is_open; // whether the packages in the module are all unqualifiedly exported bool _is_patched; // whether the module is patched via --patch-module - DEBUG_ONLY(bool _reads_is_archived); CDS_JAVA_HEAP_ONLY(int _archived_module_index;) JFR_ONLY(DEFINE_TRACE_ID_FIELD;) @@ -120,22 +118,18 @@ public: bool can_read(ModuleEntry* m) const; bool has_reads_list() const; - GrowableArray* reads() const { - assert(!_reads_is_archived, "sanity"); + AOTGrowableArray* reads() const { return _reads; } - void set_reads(GrowableArray* r) { + void set_reads(AOTGrowableArray* r) { _reads = r; - DEBUG_ONLY(_reads_is_archived = false); } - Array* archived_reads() const { - assert(_reads_is_archived, "sanity"); - return _archived_reads; - } - void set_archived_reads(Array* r) { - _archived_reads = r; - DEBUG_ONLY(_reads_is_archived = true); + void pack_reads() { + if (_reads != nullptr) { + _reads->shrink_to_fit(); + } } + void add_read(ModuleEntry* m); void set_read_walk_required(ClassLoaderData* m_loader_data); @@ -189,6 +183,13 @@ public: const char* name_as_C_string() const { return is_named() ? name()->as_C_string() : UNNAMED_MODULE; } + + // methods required by MetaspaceClosure + void metaspace_pointers_do(MetaspaceClosure* it); + int size_in_heapwords() const { return (int)heap_word_size(sizeof(ModuleEntry)); } + MetaspaceClosureType type() const { return MetaspaceClosureType::ModuleEntryType; } + static bool is_read_only_by_default() { return false; } + void print(outputStream* st = tty) const; void verify(); @@ -198,18 +199,11 @@ public: #if INCLUDE_CDS_JAVA_HEAP bool should_be_archived() const; - void iterate_symbols(MetaspaceClosure* closure); - ModuleEntry* allocate_archived_entry() const; - void init_as_archived_entry(); - static ModuleEntry* get_archived_entry(ModuleEntry* orig_entry); - bool has_been_archived(); - static Array* write_growable_array(GrowableArray* array); - static GrowableArray* restore_growable_array(Array* archived_array); + void remove_unshareable_info(); void load_from_archive(ClassLoaderData* loader_data); void preload_archived_oops(); void restore_archived_oops(ClassLoaderData* loader_data); void clear_archived_oops(); - static void verify_archived_module_entries() PRODUCT_RETURN; #endif }; @@ -275,9 +269,7 @@ public: void verify(); #if INCLUDE_CDS_JAVA_HEAP - void iterate_symbols(MetaspaceClosure* closure); - Array* allocate_archived_entries(); - void init_archived_entries(Array* archived_modules); + Array* build_aot_table(ClassLoaderData* loader_data, TRAPS); void load_archived_entries(ClassLoaderData* loader_data, Array* archived_modules); void restore_archived_oops(ClassLoaderData* loader_data, diff --git a/src/hotspot/share/classfile/modules.cpp b/src/hotspot/share/classfile/modules.cpp index baf2acfb78c..51d09d9c47f 100644 --- a/src/hotspot/share/classfile/modules.cpp +++ b/src/hotspot/share/classfile/modules.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2016, 2026, 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 @@ -505,13 +505,10 @@ void Modules::check_archived_module_oop(oop orig_module_obj) { ClassLoaderData* loader_data = orig_module_ent->loader_data(); assert(loader_data->is_builtin_class_loader_data(), "must be"); - if (orig_module_ent->name() != nullptr) { - // For each named module, we archive both the java.lang.Module oop and the ModuleEntry. - assert(orig_module_ent->has_been_archived(), "sanity"); - } else { + precond(ArchiveBuilder::current()->has_been_archived(orig_module_ent)); + if (orig_module_ent->name() == nullptr) { // We always archive unnamed module oop for boot, platform, and system loaders. precond(orig_module_ent->should_be_archived()); - precond(orig_module_ent->has_been_archived()); if (loader_data->is_boot_class_loader_data()) { assert(!_seen_boot_unnamed_module, "only once"); @@ -529,10 +526,6 @@ void Modules::check_archived_module_oop(oop orig_module_obj) { } } -void Modules::verify_archived_modules() { - ModuleEntry::verify_archived_module_entries(); -} - class Modules::ArchivedProperty { const char* _prop; const bool _numbered; diff --git a/src/hotspot/share/classfile/modules.hpp b/src/hotspot/share/classfile/modules.hpp index 27a22c1017a..75857c8960c 100644 --- a/src/hotspot/share/classfile/modules.hpp +++ b/src/hotspot/share/classfile/modules.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2016, 2026, 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 @@ -59,7 +59,6 @@ public: TRAPS) NOT_CDS_JAVA_HEAP_RETURN; static void init_archived_modules(JavaThread* current, Handle h_platform_loader, Handle h_system_loader) NOT_CDS_JAVA_HEAP_RETURN; - static void verify_archived_modules() NOT_CDS_JAVA_HEAP_RETURN; static void dump_archived_module_info() NOT_CDS_JAVA_HEAP_RETURN; static void serialize_archived_module_info(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN; diff --git a/src/hotspot/share/classfile/packageEntry.cpp b/src/hotspot/share/classfile/packageEntry.cpp index ea2e6cd1def..3e61f2e3a3e 100644 --- a/src/hotspot/share/classfile/packageEntry.cpp +++ b/src/hotspot/share/classfile/packageEntry.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -22,6 +22,8 @@ * */ +#include "cds/aotGrowableArray.inline.hpp" +#include "cds/aotMetaspace.hpp" #include "cds/archiveBuilder.hpp" #include "cds/archiveUtils.hpp" #include "cds/cdsConfig.hpp" @@ -31,13 +33,13 @@ #include "classfile/vmSymbols.hpp" #include "logging/log.hpp" #include "logging/logStream.hpp" +#include "memory/metadataFactory.hpp" #include "memory/resourceArea.hpp" #include "oops/array.hpp" #include "oops/symbol.hpp" #include "runtime/handles.inline.hpp" #include "runtime/java.hpp" #include "utilities/events.hpp" -#include "utilities/growableArray.hpp" #include "utilities/hashTable.hpp" #include "utilities/ostream.hpp" #include "utilities/quickSort.hpp" @@ -51,7 +53,7 @@ PackageEntry::PackageEntry(Symbol* name, ModuleEntry* module) : _qualified_exports(nullptr), _defined_by_cds_in_class_path(0) { - // name can't be null + // name can't be null -- a class in the default package gets a PackageEntry of nullptr. _name->increment_refcount(); JFR_ONLY(INIT_ID(this);) @@ -81,7 +83,7 @@ void PackageEntry::add_qexport(ModuleEntry* m) { if (!has_qual_exports_list()) { // Lazily create a package's qualified exports list. // Initial size is small, do not anticipate export lists to be large. - _qualified_exports = new (mtModule) GrowableArray(QUAL_EXP_SIZE, mtModule); + _qualified_exports = new (mtModule) AOTGrowableArray(QUAL_EXP_SIZE, mtModule); } // Determine, based on this newly established export to module m, @@ -183,12 +185,24 @@ void PackageEntry::purge_qualified_exports() { } void PackageEntry::delete_qualified_exports() { - if (_qualified_exports != nullptr) { + if (_qualified_exports != nullptr && !AOTMetaspace::in_aot_cache(_qualified_exports)) { delete _qualified_exports; } _qualified_exports = nullptr; } +void PackageEntry::pack_qualified_exports() { + if (_qualified_exports != nullptr) { + _qualified_exports->shrink_to_fit(); + } +} + +void PackageEntry::metaspace_pointers_do(MetaspaceClosure* it) { + it->push(&_name); + it->push(&_module); + it->push(&_qualified_exports); +} + PackageEntryTable::PackageEntryTable() { } PackageEntryTable::~PackageEntryTable() { @@ -212,66 +226,19 @@ PackageEntryTable::~PackageEntryTable() { } #if INCLUDE_CDS_JAVA_HEAP -typedef HashTable< - const PackageEntry*, - PackageEntry*, - 557, // prime number - AnyObj::C_HEAP> ArchivedPackageEntries; -static ArchivedPackageEntries* _archived_packages_entries = nullptr; - bool PackageEntry::should_be_archived() const { return module()->should_be_archived(); } -PackageEntry* PackageEntry::allocate_archived_entry() const { - precond(should_be_archived()); - PackageEntry* archived_entry = (PackageEntry*)ArchiveBuilder::rw_region_alloc(sizeof(PackageEntry)); - memcpy((void*)archived_entry, (void*)this, sizeof(PackageEntry)); - - if (_archived_packages_entries == nullptr) { - _archived_packages_entries = new (mtClass)ArchivedPackageEntries(); +void PackageEntry::remove_unshareable_info() { + if (_qualified_exports != nullptr) { + _qualified_exports->set_in_aot_cache(); } - assert(_archived_packages_entries->get(this) == nullptr, "Each PackageEntry must not be shared across PackageEntryTables"); - _archived_packages_entries->put(this, archived_entry); - - return archived_entry; -} - -PackageEntry* PackageEntry::get_archived_entry(PackageEntry* orig_entry) { - PackageEntry** ptr = _archived_packages_entries->get(orig_entry); - if (ptr != nullptr) { - return *ptr; - } else { - return nullptr; - } -} - -void PackageEntry::iterate_symbols(MetaspaceClosure* closure) { - closure->push(&_name); -} - -void PackageEntry::init_as_archived_entry() { - Array* archived_qualified_exports = ModuleEntry::write_growable_array(_qualified_exports); - - _name = ArchiveBuilder::get_buffered_symbol(_name); - _module = ModuleEntry::get_archived_entry(_module); - _qualified_exports = (GrowableArray*)archived_qualified_exports; _defined_by_cds_in_class_path = 0; JFR_ONLY(set_trace_id(0);) // re-init at runtime - - ArchivePtrMarker::mark_pointer((address*)&_name); - ArchivePtrMarker::mark_pointer((address*)&_module); - ArchivePtrMarker::mark_pointer((address*)&_qualified_exports); - - LogStreamHandle(Info, aot, package) st; - if (st.is_enabled()) { - st.print("archived "); - print(&st); - } } void PackageEntry::load_from_archive() { - _qualified_exports = ModuleEntry::restore_growable_array((Array*)_qualified_exports); JFR_ONLY(INIT_ID(this);) } @@ -280,14 +247,7 @@ static int compare_package_by_name(PackageEntry* a, PackageEntry* b) { return a->name()->fast_compare(b->name()); } -void PackageEntryTable::iterate_symbols(MetaspaceClosure* closure) { - auto syms = [&] (const SymbolHandle& key, PackageEntry*& p) { - p->iterate_symbols(closure); - }; - _table.iterate_all(syms); -} - -Array* PackageEntryTable::allocate_archived_entries() { +Array* PackageEntryTable::build_aot_table(ClassLoaderData* loader_data, TRAPS) { // First count the packages in named modules int n = 0; auto count = [&] (const SymbolHandle& key, PackageEntry*& p) { @@ -297,12 +257,19 @@ Array* PackageEntryTable::allocate_archived_entries() { }; _table.iterate_all(count); - Array* archived_packages = ArchiveBuilder::new_rw_array(n); + Array* archived_packages = MetadataFactory::new_array(loader_data, n, nullptr, CHECK_NULL); // reset n n = 0; auto grab = [&] (const SymbolHandle& key, PackageEntry*& p) { if (p->should_be_archived()) { + p->pack_qualified_exports(); archived_packages->at_put(n++, p); + + LogStreamHandle(Info, aot, package) st; + if (st.is_enabled()) { + st.print("archived "); + p->print(&st); + } } }; _table.iterate_all(grab); @@ -311,18 +278,8 @@ Array* PackageEntryTable::allocate_archived_entries() { // Always allocate in the same order to produce deterministic archive. QuickSort::sort(archived_packages->data(), n, compare_package_by_name); } - for (int i = 0; i < n; i++) { - archived_packages->at_put(i, archived_packages->at(i)->allocate_archived_entry()); - ArchivePtrMarker::mark_pointer((address*)archived_packages->adr_at(i)); - } - return archived_packages; -} -void PackageEntryTable::init_archived_entries(Array* archived_packages) { - for (int i = 0; i < archived_packages->length(); i++) { - PackageEntry* archived_entry = archived_packages->at(i); - archived_entry->init_as_archived_entry(); - } + return archived_packages; } void PackageEntryTable::load_archived_entries(Array* archived_packages) { diff --git a/src/hotspot/share/classfile/packageEntry.hpp b/src/hotspot/share/classfile/packageEntry.hpp index 6abf89dc60f..7b174a92287 100644 --- a/src/hotspot/share/classfile/packageEntry.hpp +++ b/src/hotspot/share/classfile/packageEntry.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -25,7 +25,9 @@ #ifndef SHARE_CLASSFILE_PACKAGEENTRY_HPP #define SHARE_CLASSFILE_PACKAGEENTRY_HPP +#include "cds/aotGrowableArray.hpp" #include "classfile/moduleEntry.hpp" +#include "memory/metaspaceClosureType.hpp" #include "oops/symbol.hpp" #include "oops/symbolHandle.hpp" #include "runtime/atomicAccess.hpp" @@ -114,7 +116,7 @@ private: bool _must_walk_exports; // Contains list of modules this package is qualifiedly exported to. Access // to this list is protected by the Module_lock. - GrowableArray* _qualified_exports; + AOTGrowableArray* _qualified_exports; JFR_ONLY(DEFINE_TRACE_ID_FIELD;) // Initial size of a package entry's list of qualified exports. @@ -205,14 +207,24 @@ public: void purge_qualified_exports(); void delete_qualified_exports(); + void pack_qualified_exports(); // used by AOT + + // methods required by MetaspaceClosure + void metaspace_pointers_do(MetaspaceClosure* it); + int size_in_heapwords() const { return (int)heap_word_size(sizeof(PackageEntry)); } + MetaspaceClosureType type() const { return MetaspaceClosureType::PackageEntryType; } + static bool is_read_only_by_default() { return false; } + void print(outputStream* st = tty); + char* name_as_C_string() const { + assert(_name != nullptr, "name can't be null"); + return name()->as_C_string(); + } + #if INCLUDE_CDS_JAVA_HEAP bool should_be_archived() const; - void iterate_symbols(MetaspaceClosure* closure); - PackageEntry* allocate_archived_entry() const; - void init_as_archived_entry(); - static PackageEntry* get_archived_entry(PackageEntry* orig_entry); + void remove_unshareable_info(); void load_from_archive(); #endif @@ -271,9 +283,7 @@ public: void print(outputStream* st = tty); #if INCLUDE_CDS_JAVA_HEAP - void iterate_symbols(MetaspaceClosure* closure); - Array* allocate_archived_entries(); - void init_archived_entries(Array* archived_packages); + Array* build_aot_table(ClassLoaderData* loader_data, TRAPS); void load_archived_entries(Array* archived_packages); #endif }; diff --git a/src/hotspot/share/classfile/vmSymbols.hpp b/src/hotspot/share/classfile/vmSymbols.hpp index 8388b98faae..79646f24d0e 100644 --- a/src/hotspot/share/classfile/vmSymbols.hpp +++ b/src/hotspot/share/classfile/vmSymbols.hpp @@ -245,10 +245,6 @@ class SerializeClosure; \ /* Concurrency support */ \ template(java_util_concurrent_locks_AbstractOwnableSynchronizer, "java/util/concurrent/locks/AbstractOwnableSynchronizer") \ - template(java_util_concurrent_atomic_AtomicIntegerFieldUpdater_Impl, "java/util/concurrent/atomic/AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl") \ - template(java_util_concurrent_atomic_AtomicLongFieldUpdater_CASUpdater, "java/util/concurrent/atomic/AtomicLongFieldUpdater$CASUpdater") \ - template(java_util_concurrent_atomic_AtomicLongFieldUpdater_LockedUpdater, "java/util/concurrent/atomic/AtomicLongFieldUpdater$LockedUpdater") \ - template(java_util_concurrent_atomic_AtomicReferenceFieldUpdater_Impl, "java/util/concurrent/atomic/AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl") \ template(jdk_internal_vm_annotation_Contended_signature, "Ljdk/internal/vm/annotation/Contended;") \ template(jdk_internal_vm_annotation_ReservedStackAccess_signature, "Ljdk/internal/vm/annotation/ReservedStackAccess;") \ template(jdk_internal_ValueBased_signature, "Ljdk/internal/ValueBased;") \ @@ -302,6 +298,7 @@ class SerializeClosure; template(jdk_internal_misc_Scoped_signature, "Ljdk/internal/misc/ScopedMemoryAccess$Scoped;") \ template(jdk_internal_vm_annotation_IntrinsicCandidate_signature, "Ljdk/internal/vm/annotation/IntrinsicCandidate;") \ template(jdk_internal_vm_annotation_Stable_signature, "Ljdk/internal/vm/annotation/Stable;") \ + template(jdk_internal_vm_annotation_TrustFinalFields_signature, "Ljdk/internal/vm/annotation/TrustFinalFields;") \ \ template(jdk_internal_vm_annotation_ChangesCurrentThread_signature, "Ljdk/internal/vm/annotation/ChangesCurrentThread;") \ template(jdk_internal_vm_annotation_JvmtiHideEvents_signature, "Ljdk/internal/vm/annotation/JvmtiHideEvents;") \ diff --git a/src/hotspot/share/gc/g1/g1CardSet.cpp b/src/hotspot/share/gc/g1/g1CardSet.cpp index 3441e6bc608..60ad63e812c 100644 --- a/src/hotspot/share/gc/g1/g1CardSet.cpp +++ b/src/hotspot/share/gc/g1/g1CardSet.cpp @@ -29,7 +29,6 @@ #include "gc/shared/gcLogPrecious.hpp" #include "gc/shared/gcTraceTime.inline.hpp" #include "memory/allocation.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/globals_extension.hpp" #include "runtime/java.hpp" #include "utilities/bitMap.inline.hpp" @@ -192,32 +191,32 @@ const char* G1CardSetConfiguration::mem_object_type_name_str(uint index) { void G1CardSetCoarsenStats::reset() { STATIC_ASSERT(ARRAY_SIZE(_coarsen_from) == ARRAY_SIZE(_coarsen_collision)); for (uint i = 0; i < ARRAY_SIZE(_coarsen_from); i++) { - _coarsen_from[i] = 0; - _coarsen_collision[i] = 0; + _coarsen_from[i].store_relaxed(0); + _coarsen_collision[i].store_relaxed(0); } } void G1CardSetCoarsenStats::set(G1CardSetCoarsenStats& other) { STATIC_ASSERT(ARRAY_SIZE(_coarsen_from) == ARRAY_SIZE(_coarsen_collision)); for (uint i = 0; i < ARRAY_SIZE(_coarsen_from); i++) { - _coarsen_from[i] = other._coarsen_from[i]; - _coarsen_collision[i] = other._coarsen_collision[i]; + _coarsen_from[i].store_relaxed(other._coarsen_from[i].load_relaxed()); + _coarsen_collision[i].store_relaxed(other._coarsen_collision[i].load_relaxed()); } } void G1CardSetCoarsenStats::subtract_from(G1CardSetCoarsenStats& other) { STATIC_ASSERT(ARRAY_SIZE(_coarsen_from) == ARRAY_SIZE(_coarsen_collision)); for (uint i = 0; i < ARRAY_SIZE(_coarsen_from); i++) { - _coarsen_from[i] = other._coarsen_from[i] - _coarsen_from[i]; - _coarsen_collision[i] = other._coarsen_collision[i] - _coarsen_collision[i]; + _coarsen_from[i].store_relaxed(other._coarsen_from[i].load_relaxed() - _coarsen_from[i].load_relaxed()); + _coarsen_collision[i].store_relaxed(other._coarsen_collision[i].load_relaxed() - _coarsen_collision[i].load_relaxed()); } } void G1CardSetCoarsenStats::record_coarsening(uint tag, bool collision) { assert(tag < ARRAY_SIZE(_coarsen_from), "tag %u out of bounds", tag); - AtomicAccess::inc(&_coarsen_from[tag], memory_order_relaxed); + _coarsen_from[tag].add_then_fetch(1u, memory_order_relaxed); if (collision) { - AtomicAccess::inc(&_coarsen_collision[tag], memory_order_relaxed); + _coarsen_collision[tag].add_then_fetch(1u, memory_order_relaxed); } } @@ -228,13 +227,13 @@ void G1CardSetCoarsenStats::print_on(outputStream* out) { "Inline->AoC %zu (%zu) " "AoC->BitMap %zu (%zu) " "BitMap->Full %zu (%zu) ", - _coarsen_from[0], _coarsen_collision[0], - _coarsen_from[1], _coarsen_collision[1], + _coarsen_from[0].load_relaxed(), _coarsen_collision[0].load_relaxed(), + _coarsen_from[1].load_relaxed(), _coarsen_collision[1].load_relaxed(), // There is no BitMap at the first level so we can't . - _coarsen_from[3], _coarsen_collision[3], - _coarsen_from[4], _coarsen_collision[4], - _coarsen_from[5], _coarsen_collision[5], - _coarsen_from[6], _coarsen_collision[6] + _coarsen_from[3].load_relaxed(), _coarsen_collision[3].load_relaxed(), + _coarsen_from[4].load_relaxed(), _coarsen_collision[4].load_relaxed(), + _coarsen_from[5].load_relaxed(), _coarsen_collision[5].load_relaxed(), + _coarsen_from[6].load_relaxed(), _coarsen_collision[6].load_relaxed() ); } @@ -248,7 +247,7 @@ class G1CardSetHashTable : public CHeapObj { // the per region cardsets. const static uint GroupBucketClaimSize = 4; // Did we insert at least one card in the table? - bool volatile _inserted_card; + Atomic _inserted_card; G1CardSetMemoryManager* _mm; CardSetHash _table; @@ -311,10 +310,10 @@ public: G1CardSetHashTableValue value(region_idx, G1CardSetInlinePtr()); bool inserted = _table.insert_get(Thread::current(), lookup, value, found, should_grow); - if (!_inserted_card && inserted) { + if (!_inserted_card.load_relaxed() && inserted) { // It does not matter to us who is setting the flag so a regular atomic store // is sufficient. - AtomicAccess::store(&_inserted_card, true); + _inserted_card.store_relaxed(true); } return found.value(); @@ -343,9 +342,9 @@ public: } void reset() { - if (AtomicAccess::load(&_inserted_card)) { + if (_inserted_card.load_relaxed()) { _table.unsafe_reset(InitialLogTableSize); - AtomicAccess::store(&_inserted_card, false); + _inserted_card.store_relaxed(false); } } @@ -455,14 +454,14 @@ void G1CardSet::free_mem_object(ContainerPtr container) { _mm->free(container_type_to_mem_object_type(type), value); } -G1CardSet::ContainerPtr G1CardSet::acquire_container(ContainerPtr volatile* container_addr) { +G1CardSet::ContainerPtr G1CardSet::acquire_container(Atomic* container_addr) { // Update reference counts under RCU critical section to avoid a // use-after-cleapup bug where we increment a reference count for // an object whose memory has already been cleaned up and reused. GlobalCounter::CriticalSection cs(Thread::current()); while (true) { // Get ContainerPtr and increment refcount atomically wrt to memory reuse. - ContainerPtr container = AtomicAccess::load_acquire(container_addr); + ContainerPtr container = container_addr->load_acquire(); uint cs_type = container_type(container); if (container == FullCardSet || cs_type == ContainerInlinePtr) { return container; @@ -503,15 +502,15 @@ class G1ReleaseCardsets : public StackObj { G1CardSet* _card_set; using ContainerPtr = G1CardSet::ContainerPtr; - void coarsen_to_full(ContainerPtr* container_addr) { + void coarsen_to_full(Atomic* container_addr) { while (true) { - ContainerPtr cur_container = AtomicAccess::load_acquire(container_addr); + ContainerPtr cur_container = container_addr->load_acquire(); uint cs_type = G1CardSet::container_type(cur_container); if (cur_container == G1CardSet::FullCardSet) { return; } - ContainerPtr old_value = AtomicAccess::cmpxchg(container_addr, cur_container, G1CardSet::FullCardSet); + ContainerPtr old_value = container_addr->compare_exchange(cur_container, G1CardSet::FullCardSet); if (old_value == cur_container) { _card_set->release_and_maybe_free_container(cur_container); @@ -523,7 +522,7 @@ class G1ReleaseCardsets : public StackObj { public: explicit G1ReleaseCardsets(G1CardSet* card_set) : _card_set(card_set) { } - void operator ()(ContainerPtr* container_addr) { + void operator ()(Atomic* container_addr) { coarsen_to_full(container_addr); } }; @@ -544,10 +543,10 @@ G1AddCardResult G1CardSet::add_to_howl(ContainerPtr parent_container, ContainerPtr container; uint bucket = _config->howl_bucket_index(card_in_region); - ContainerPtr volatile* bucket_entry = howl->container_addr(bucket); + Atomic* bucket_entry = howl->container_addr(bucket); while (true) { - if (AtomicAccess::load(&howl->_num_entries) >= _config->cards_in_howl_threshold()) { + if (howl->_num_entries.load_relaxed() >= _config->cards_in_howl_threshold()) { return Overflow; } @@ -571,7 +570,7 @@ G1AddCardResult G1CardSet::add_to_howl(ContainerPtr parent_container, } if (increment_total && add_result == Added) { - AtomicAccess::inc(&howl->_num_entries, memory_order_relaxed); + howl->_num_entries.add_then_fetch(1u, memory_order_relaxed); } if (to_transfer != nullptr) { @@ -588,7 +587,7 @@ G1AddCardResult G1CardSet::add_to_bitmap(ContainerPtr container, uint card_in_re return bitmap->add(card_offset, _config->cards_in_howl_bitmap_threshold(), _config->max_cards_in_howl_bitmap()); } -G1AddCardResult G1CardSet::add_to_inline_ptr(ContainerPtr volatile* container_addr, ContainerPtr container, uint card_in_region) { +G1AddCardResult G1CardSet::add_to_inline_ptr(Atomic* container_addr, ContainerPtr container, uint card_in_region) { G1CardSetInlinePtr value(container_addr, container); return value.add(card_in_region, _config->inline_ptr_bits_per_card(), _config->max_cards_in_inline_ptr()); } @@ -610,7 +609,7 @@ G1CardSet::ContainerPtr G1CardSet::create_coarsened_array_of_cards(uint card_in_ return new_container; } -bool G1CardSet::coarsen_container(ContainerPtr volatile* container_addr, +bool G1CardSet::coarsen_container(Atomic* container_addr, ContainerPtr cur_container, uint card_in_region, bool within_howl) { @@ -640,7 +639,7 @@ bool G1CardSet::coarsen_container(ContainerPtr volatile* container_addr, ShouldNotReachHere(); } - ContainerPtr old_value = AtomicAccess::cmpxchg(container_addr, cur_container, new_container); // Memory order? + ContainerPtr old_value = container_addr->compare_exchange(cur_container, new_container); // Memory order? if (old_value == cur_container) { // Success. Indicate that the cards from the current card set must be transferred // by this caller. @@ -687,7 +686,7 @@ void G1CardSet::transfer_cards(G1CardSetHashTableValue* table_entry, ContainerPt assert(container_type(source_container) == ContainerHowl, "must be"); // Need to correct for that the Full remembered set occupies more cards than the // AoCS before. - AtomicAccess::add(&_num_occupied, _config->max_cards_in_region() - table_entry->_num_occupied, memory_order_relaxed); + _num_occupied.add_then_fetch(_config->max_cards_in_region() - table_entry->_num_occupied.load_relaxed(), memory_order_relaxed); } } @@ -713,18 +712,18 @@ void G1CardSet::transfer_cards_in_howl(ContainerPtr parent_container, diff -= 1; G1CardSetHowl* howling_array = container_ptr(parent_container); - AtomicAccess::add(&howling_array->_num_entries, diff, memory_order_relaxed); + howling_array->_num_entries.add_then_fetch(diff, memory_order_relaxed); G1CardSetHashTableValue* table_entry = get_container(card_region); assert(table_entry != nullptr, "Table entry not found for transferred cards"); - AtomicAccess::add(&table_entry->_num_occupied, diff, memory_order_relaxed); + table_entry->_num_occupied.add_then_fetch(diff, memory_order_relaxed); - AtomicAccess::add(&_num_occupied, diff, memory_order_relaxed); + _num_occupied.add_then_fetch(diff, memory_order_relaxed); } } -G1AddCardResult G1CardSet::add_to_container(ContainerPtr volatile* container_addr, +G1AddCardResult G1CardSet::add_to_container(Atomic* container_addr, ContainerPtr container, uint card_region, uint card_in_region, @@ -827,8 +826,8 @@ G1AddCardResult G1CardSet::add_card(uint card_region, uint card_in_region, bool } if (increment_total && add_result == Added) { - AtomicAccess::inc(&table_entry->_num_occupied, memory_order_relaxed); - AtomicAccess::inc(&_num_occupied, memory_order_relaxed); + table_entry->_num_occupied.add_then_fetch(1u, memory_order_relaxed); + _num_occupied.add_then_fetch(1u, memory_order_relaxed); } if (should_grow_table) { _table->grow(); @@ -853,7 +852,7 @@ bool G1CardSet::contains_card(uint card_region, uint card_in_region) { return false; } - ContainerPtr container = table_entry->_container; + ContainerPtr container = table_entry->_container.load_relaxed(); if (container == FullCardSet) { // contains_card() is not a performance critical method so we do not hide that // case in the switch below. @@ -889,7 +888,7 @@ void G1CardSet::print_info(outputStream* st, uintptr_t card) { return; } - ContainerPtr container = table_entry->_container; + ContainerPtr container = table_entry->_container.load_relaxed(); if (container == FullCardSet) { st->print("FULL card set)"); return; @@ -940,7 +939,7 @@ void G1CardSet::iterate_cards_during_transfer(ContainerPtr const container, Card void G1CardSet::iterate_containers(ContainerPtrClosure* cl, bool at_safepoint) { auto do_value = [&] (G1CardSetHashTableValue* value) { - cl->do_containerptr(value->_region_idx, value->_num_occupied, value->_container); + cl->do_containerptr(value->_region_idx, value->_num_occupied.load_relaxed(), value->_container.load_relaxed()); return true; }; @@ -1001,11 +1000,11 @@ bool G1CardSet::occupancy_less_or_equal_to(size_t limit) const { } bool G1CardSet::is_empty() const { - return _num_occupied == 0; + return _num_occupied.load_relaxed() == 0; } size_t G1CardSet::occupied() const { - return _num_occupied; + return _num_occupied.load_relaxed(); } size_t G1CardSet::num_containers() { @@ -1051,7 +1050,7 @@ size_t G1CardSet::static_mem_size() { void G1CardSet::clear() { _table->reset(); - _num_occupied = 0; + _num_occupied.store_relaxed(0); _mm->flush(); } diff --git a/src/hotspot/share/gc/g1/g1CardSet.hpp b/src/hotspot/share/gc/g1/g1CardSet.hpp index 9cefc4b1c22..64ddf0ca6a4 100644 --- a/src/hotspot/share/gc/g1/g1CardSet.hpp +++ b/src/hotspot/share/gc/g1/g1CardSet.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -27,6 +27,7 @@ #include "memory/allocation.hpp" #include "memory/memRegion.hpp" +#include "runtime/atomic.hpp" #include "utilities/concurrentHashTable.hpp" class G1CardSetAllocOptions; @@ -154,8 +155,8 @@ public: private: // Indices are "from" indices. - size_t _coarsen_from[NumCoarsenCategories]; - size_t _coarsen_collision[NumCoarsenCategories]; + Atomic _coarsen_from[NumCoarsenCategories]; + Atomic _coarsen_collision[NumCoarsenCategories]; public: G1CardSetCoarsenStats() { reset(); } @@ -271,11 +272,11 @@ private: // Total number of cards in this card set. This is a best-effort value, i.e. there may // be (slightly) more cards in the card set than this value in reality. - size_t _num_occupied; + Atomic _num_occupied; ContainerPtr make_container_ptr(void* value, uintptr_t type); - ContainerPtr acquire_container(ContainerPtr volatile* container_addr); + ContainerPtr acquire_container(Atomic* container_addr); // Returns true if the card set container should be released bool release_container(ContainerPtr container); // Release card set and free if needed. @@ -288,7 +289,7 @@ private: // coarsen_container does not transfer cards from cur_container // to the new container. Transfer is achieved by transfer_cards. // Returns true if this was the thread that coarsened the container (and added the card). - bool coarsen_container(ContainerPtr volatile* container_addr, + bool coarsen_container(Atomic* container_addr, ContainerPtr cur_container, uint card_in_region, bool within_howl = false); @@ -300,9 +301,9 @@ private: void transfer_cards(G1CardSetHashTableValue* table_entry, ContainerPtr source_container, uint card_region); void transfer_cards_in_howl(ContainerPtr parent_container, ContainerPtr source_container, uint card_region); - G1AddCardResult add_to_container(ContainerPtr volatile* container_addr, ContainerPtr container, uint card_region, uint card, bool increment_total = true); + G1AddCardResult add_to_container(Atomic* container_addr, ContainerPtr container, uint card_region, uint card, bool increment_total = true); - G1AddCardResult add_to_inline_ptr(ContainerPtr volatile* container_addr, ContainerPtr container, uint card_in_region); + G1AddCardResult add_to_inline_ptr(Atomic* container_addr, ContainerPtr container, uint card_in_region); G1AddCardResult add_to_array(ContainerPtr container, uint card_in_region); G1AddCardResult add_to_bitmap(ContainerPtr container, uint card_in_region); G1AddCardResult add_to_howl(ContainerPtr parent_container, uint card_region, uint card_in_region, bool increment_total = true); @@ -366,7 +367,6 @@ public: size_t num_containers(); - static G1CardSetCoarsenStats coarsen_stats(); static void print_coarsen_stats(outputStream* out); // Returns size of the actual remembered set containers in bytes. @@ -412,8 +412,15 @@ public: using ContainerPtr = G1CardSet::ContainerPtr; const uint _region_idx; - uint volatile _num_occupied; - ContainerPtr volatile _container; + Atomic _num_occupied; + Atomic _container; + + // Copy constructor needed for use in ConcurrentHashTable. + G1CardSetHashTableValue(const G1CardSetHashTableValue& other) : + _region_idx(other._region_idx), + _num_occupied(other._num_occupied.load_relaxed()), + _container(other._container.load_relaxed()) + { } G1CardSetHashTableValue(uint region_idx, ContainerPtr container) : _region_idx(region_idx), _num_occupied(0), _container(container) { } }; diff --git a/src/hotspot/share/gc/g1/g1CardSetContainers.hpp b/src/hotspot/share/gc/g1/g1CardSetContainers.hpp index 72c7795be2e..78551479e06 100644 --- a/src/hotspot/share/gc/g1/g1CardSetContainers.hpp +++ b/src/hotspot/share/gc/g1/g1CardSetContainers.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, 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 @@ -27,7 +27,7 @@ #include "gc/g1/g1CardSet.hpp" #include "memory/allocation.hpp" -#include "runtime/atomicAccess.hpp" +#include "runtime/atomic.hpp" #include "utilities/bitMap.hpp" #include "utilities/globalDefinitions.hpp" @@ -67,7 +67,7 @@ class G1CardSetInlinePtr : public StackObj { using ContainerPtr = G1CardSet::ContainerPtr; - ContainerPtr volatile * _value_addr; + Atomic* _value_addr; ContainerPtr _value; static const uint SizeFieldLen = 3; @@ -103,7 +103,7 @@ public: explicit G1CardSetInlinePtr(ContainerPtr value) : G1CardSetInlinePtr(nullptr, value) {} - G1CardSetInlinePtr(ContainerPtr volatile* value_addr, ContainerPtr value) : _value_addr(value_addr), _value(value) { + G1CardSetInlinePtr(Atomic* value_addr, ContainerPtr value) : _value_addr(value_addr), _value(value) { assert(G1CardSet::container_type(_value) == G1CardSet::ContainerInlinePtr, "Value " PTR_FORMAT " is not a valid G1CardSetInlinePtr.", p2i(_value)); } @@ -145,13 +145,13 @@ public: // All but inline pointers are of this kind. For those, card entries are stored // directly in the ContainerPtr of the ConcurrentHashTable node. class G1CardSetContainer { - uintptr_t _ref_count; + Atomic _ref_count; protected: ~G1CardSetContainer() = default; public: G1CardSetContainer() : _ref_count(3) { } - uintptr_t refcount() const { return AtomicAccess::load_acquire(&_ref_count); } + uintptr_t refcount() const { return _ref_count.load_acquire(); } bool try_increment_refcount(); @@ -172,7 +172,7 @@ public: using ContainerPtr = G1CardSet::ContainerPtr; private: EntryCountType _size; - EntryCountType volatile _num_entries; + Atomic _num_entries; // VLA implementation. EntryDataType _data[1]; @@ -180,10 +180,10 @@ private: static const EntryCountType EntryMask = LockBitMask - 1; class G1CardSetArrayLocker : public StackObj { - EntryCountType volatile* _num_entries_addr; + Atomic* _num_entries_addr; EntryCountType _local_num_entries; public: - G1CardSetArrayLocker(EntryCountType volatile* value); + G1CardSetArrayLocker(Atomic* value); EntryCountType num_entries() const { return _local_num_entries; } void inc_num_entries() { @@ -192,7 +192,7 @@ private: } ~G1CardSetArrayLocker() { - AtomicAccess::release_store(_num_entries_addr, _local_num_entries); + _num_entries_addr->release_store(_local_num_entries); } }; @@ -213,7 +213,7 @@ public: template void iterate(CardVisitor& found); - size_t num_entries() const { return _num_entries & EntryMask; } + size_t num_entries() const { return _num_entries.load_relaxed() & EntryMask; } static size_t header_size_in_bytes(); @@ -223,7 +223,7 @@ public: }; class G1CardSetBitMap : public G1CardSetContainer { - size_t _num_bits_set; + Atomic _num_bits_set; BitMap::bm_word_t _bits[1]; public: @@ -236,7 +236,7 @@ public: return bm.at(card_idx); } - uint num_bits_set() const { return (uint)_num_bits_set; } + uint num_bits_set() const { return (uint)_num_bits_set.load_relaxed(); } template void iterate(CardVisitor& found, size_t const size_in_bits, uint offset); @@ -255,10 +255,10 @@ class G1CardSetHowl : public G1CardSetContainer { public: typedef uint EntryCountType; using ContainerPtr = G1CardSet::ContainerPtr; - EntryCountType volatile _num_entries; + Atomic _num_entries; private: // VLA implementation. - ContainerPtr _buckets[1]; + Atomic _buckets[1]; // Do not add class member variables beyond this point. // Iterates over the given ContainerPtr with at index in this Howl card set, @@ -268,14 +268,14 @@ private: ContainerPtr at(EntryCountType index) const; - ContainerPtr const* buckets() const; + Atomic const* buckets() const; public: G1CardSetHowl(EntryCountType card_in_region, G1CardSetConfiguration* config); - ContainerPtr const* container_addr(EntryCountType index) const; + Atomic const* container_addr(EntryCountType index) const; - ContainerPtr* container_addr(EntryCountType index); + Atomic* container_addr(EntryCountType index); bool contains(uint card_idx, G1CardSetConfiguration* config); // Iterates over all ContainerPtrs in this Howl card set, applying a CardOrRangeVisitor diff --git a/src/hotspot/share/gc/g1/g1CardSetContainers.inline.hpp b/src/hotspot/share/gc/g1/g1CardSetContainers.inline.hpp index 1958309f517..3c6fb9d1a02 100644 --- a/src/hotspot/share/gc/g1/g1CardSetContainers.inline.hpp +++ b/src/hotspot/share/gc/g1/g1CardSetContainers.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -67,7 +67,7 @@ inline G1AddCardResult G1CardSetInlinePtr::add(uint card_idx, uint bits_per_card return Overflow; } ContainerPtr new_value = merge(_value, card_idx, num_cards, bits_per_card); - ContainerPtr old_value = AtomicAccess::cmpxchg(_value_addr, _value, new_value, memory_order_relaxed); + ContainerPtr old_value = _value_addr->compare_exchange(_value, new_value, memory_order_relaxed); if (_value == old_value) { return Added; } @@ -126,7 +126,7 @@ inline bool G1CardSetContainer::try_increment_refcount() { } uintptr_t new_value = old_value + 2; - uintptr_t ref_count = AtomicAccess::cmpxchg(&_ref_count, old_value, new_value); + uintptr_t ref_count = _ref_count.compare_exchange(old_value, new_value); if (ref_count == old_value) { return true; } @@ -137,7 +137,7 @@ inline bool G1CardSetContainer::try_increment_refcount() { inline uintptr_t G1CardSetContainer::decrement_refcount() { uintptr_t old_value = refcount(); assert((old_value & 0x1) != 0 && old_value >= 3, "precondition"); - return AtomicAccess::sub(&_ref_count, 2u); + return _ref_count.sub_then_fetch(2u); } inline G1CardSetArray::G1CardSetArray(uint card_in_region, EntryCountType num_cards) : @@ -149,14 +149,13 @@ inline G1CardSetArray::G1CardSetArray(uint card_in_region, EntryCountType num_ca *entry_addr(0) = checked_cast(card_in_region); } -inline G1CardSetArray::G1CardSetArrayLocker::G1CardSetArrayLocker(EntryCountType volatile* num_entries_addr) : +inline G1CardSetArray::G1CardSetArrayLocker::G1CardSetArrayLocker(Atomic* num_entries_addr) : _num_entries_addr(num_entries_addr) { SpinYield s; - EntryCountType num_entries = AtomicAccess::load(_num_entries_addr) & EntryMask; + EntryCountType num_entries = _num_entries_addr->load_relaxed() & EntryMask; while (true) { - EntryCountType old_value = AtomicAccess::cmpxchg(_num_entries_addr, - num_entries, - (EntryCountType)(num_entries | LockBitMask)); + EntryCountType old_value = _num_entries_addr->compare_exchange(num_entries, + (EntryCountType)(num_entries | LockBitMask)); if (old_value == num_entries) { // Succeeded locking the array. _local_num_entries = num_entries; @@ -174,7 +173,7 @@ inline G1CardSetArray::EntryDataType const* G1CardSetArray::base_addr() const { } inline G1CardSetArray::EntryDataType const* G1CardSetArray::entry_addr(EntryCountType index) const { - assert(index < _num_entries, "precondition"); + assert(index < _num_entries.load_relaxed(), "precondition"); return base_addr() + index; } @@ -189,7 +188,7 @@ inline G1CardSetArray::EntryDataType G1CardSetArray::at(EntryCountType index) co inline G1AddCardResult G1CardSetArray::add(uint card_idx) { assert(card_idx < (1u << (sizeof(EntryDataType) * BitsPerByte)), "Card index %u does not fit allowed card value range.", card_idx); - EntryCountType num_entries = AtomicAccess::load_acquire(&_num_entries) & EntryMask; + EntryCountType num_entries = _num_entries.load_acquire() & EntryMask; EntryCountType idx = 0; for (; idx < num_entries; idx++) { if (at(idx) == card_idx) { @@ -223,7 +222,7 @@ inline G1AddCardResult G1CardSetArray::add(uint card_idx) { } inline bool G1CardSetArray::contains(uint card_idx) { - EntryCountType num_entries = AtomicAccess::load_acquire(&_num_entries) & EntryMask; + EntryCountType num_entries = _num_entries.load_acquire() & EntryMask; for (EntryCountType idx = 0; idx < num_entries; idx++) { if (at(idx) == card_idx) { @@ -235,7 +234,7 @@ inline bool G1CardSetArray::contains(uint card_idx) { template void G1CardSetArray::iterate(CardVisitor& found) { - EntryCountType num_entries = AtomicAccess::load_acquire(&_num_entries) & EntryMask; + EntryCountType num_entries = _num_entries.load_acquire() & EntryMask; for (EntryCountType idx = 0; idx < num_entries; idx++) { found(at(idx)); } @@ -256,11 +255,11 @@ inline G1CardSetBitMap::G1CardSetBitMap(uint card_in_region, uint size_in_bits) inline G1AddCardResult G1CardSetBitMap::add(uint card_idx, size_t threshold, size_t size_in_bits) { BitMapView bm(_bits, size_in_bits); - if (_num_bits_set >= threshold) { + if (_num_bits_set.load_relaxed() >= threshold) { return bm.at(card_idx) ? Found : Overflow; } if (bm.par_set_bit(card_idx)) { - AtomicAccess::inc(&_num_bits_set, memory_order_relaxed); + _num_bits_set.add_then_fetch(1u, memory_order_relaxed); return Added; } return Found; @@ -276,22 +275,22 @@ inline size_t G1CardSetBitMap::header_size_in_bytes() { return offset_of(G1CardSetBitMap, _bits); } -inline G1CardSetHowl::ContainerPtr const* G1CardSetHowl::container_addr(EntryCountType index) const { - assert(index < _num_entries, "precondition"); +inline Atomic const* G1CardSetHowl::container_addr(EntryCountType index) const { + assert(index < _num_entries.load_relaxed(), "precondition"); return buckets() + index; } -inline G1CardSetHowl::ContainerPtr* G1CardSetHowl::container_addr(EntryCountType index) { - return const_cast(const_cast(this)->container_addr(index)); +inline Atomic* G1CardSetHowl::container_addr(EntryCountType index) { + return const_cast*>(const_cast(this)->container_addr(index)); } inline G1CardSetHowl::ContainerPtr G1CardSetHowl::at(EntryCountType index) const { - return *container_addr(index); + return (*container_addr(index)).load_relaxed(); } -inline G1CardSetHowl::ContainerPtr const* G1CardSetHowl::buckets() const { +inline Atomic const* G1CardSetHowl::buckets() const { const void* ptr = reinterpret_cast(this) + header_size_in_bytes(); - return reinterpret_cast(ptr); + return reinterpret_cast const*>(ptr); } inline G1CardSetHowl::G1CardSetHowl(EntryCountType card_in_region, G1CardSetConfiguration* config) : @@ -300,7 +299,7 @@ inline G1CardSetHowl::G1CardSetHowl(EntryCountType card_in_region, G1CardSetConf EntryCountType num_buckets = config->num_buckets_in_howl(); EntryCountType bucket = config->howl_bucket_index(card_in_region); for (uint i = 0; i < num_buckets; ++i) { - *container_addr(i) = G1CardSetInlinePtr(); + container_addr(i)->store_relaxed(G1CardSetInlinePtr()); if (i == bucket) { G1CardSetInlinePtr value(container_addr(i), at(i)); value.add(card_in_region, config->inline_ptr_bits_per_card(), config->max_cards_in_inline_ptr()); @@ -310,8 +309,8 @@ inline G1CardSetHowl::G1CardSetHowl(EntryCountType card_in_region, G1CardSetConf inline bool G1CardSetHowl::contains(uint card_idx, G1CardSetConfiguration* config) { EntryCountType bucket = config->howl_bucket_index(card_idx); - ContainerPtr* array_entry = container_addr(bucket); - ContainerPtr container = AtomicAccess::load_acquire(array_entry); + Atomic* array_entry = container_addr(bucket); + ContainerPtr container = array_entry->load_acquire(); switch (G1CardSet::container_type(container)) { case G1CardSet::ContainerArrayOfCards: { diff --git a/src/hotspot/share/gc/g1/g1CardSetMemory.cpp b/src/hotspot/share/gc/g1/g1CardSetMemory.cpp index d13a6fe2dca..60602ef942b 100644 --- a/src/hotspot/share/gc/g1/g1CardSetMemory.cpp +++ b/src/hotspot/share/gc/g1/g1CardSetMemory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -26,7 +26,6 @@ #include "gc/g1/g1CardSetContainers.inline.hpp" #include "gc/g1/g1CardSetMemory.inline.hpp" #include "gc/g1/g1MonotonicArena.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/ostream.hpp" G1CardSetAllocator::G1CardSetAllocator(const char* name, diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp index 958b171444e..8782b65b6f9 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp @@ -31,6 +31,7 @@ #include "gc/g1/g1CollectorState.hpp" #include "gc/g1/g1ConcurrentMark.inline.hpp" #include "gc/g1/g1EvacFailureRegions.hpp" +#include "gc/g1/g1EvacStats.inline.hpp" #include "gc/g1/g1HeapRegion.inline.hpp" #include "gc/g1/g1HeapRegionManager.inline.hpp" #include "gc/g1/g1HeapRegionRemSet.hpp" diff --git a/src/hotspot/share/gc/g1/g1CollectionSetChooser.cpp b/src/hotspot/share/gc/g1/g1CollectionSetChooser.cpp index d9496410c12..e7bab32129e 100644 --- a/src/hotspot/share/gc/g1/g1CollectionSetChooser.cpp +++ b/src/hotspot/share/gc/g1/g1CollectionSetChooser.cpp @@ -203,13 +203,13 @@ class G1BuildCandidateRegionsTask : public WorkerTask { G1CollectedHeap* _g1h; G1HeapRegionClaimer _hrclaimer; - uint volatile _num_regions_added; + Atomic _num_regions_added; G1BuildCandidateArray _result; void update_totals(uint num_regions) { if (num_regions > 0) { - AtomicAccess::add(&_num_regions_added, num_regions); + _num_regions_added.add_then_fetch(num_regions); } } @@ -221,7 +221,7 @@ class G1BuildCandidateRegionsTask : public WorkerTask { void prune(G1HeapRegion** data) { G1Policy* p = G1CollectedHeap::heap()->policy(); - uint num_candidates = AtomicAccess::load(&_num_regions_added); + uint num_candidates = _num_regions_added.load_relaxed(); uint min_old_cset_length = p->calc_min_old_cset_length(num_candidates); uint num_pruned = 0; @@ -254,7 +254,7 @@ class G1BuildCandidateRegionsTask : public WorkerTask { wasted_bytes, allowed_waste); - AtomicAccess::sub(&_num_regions_added, num_pruned, memory_order_relaxed); + _num_regions_added.sub_then_fetch(num_pruned, memory_order_relaxed); } public: @@ -275,7 +275,7 @@ public: _result.sort_by_gc_efficiency(); prune(_result.array()); candidates->set_candidates_from_marking(_result.array(), - _num_regions_added); + _num_regions_added.load_relaxed()); } }; diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp index 52591f7ce5f..2bbfb5032b3 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp @@ -291,9 +291,9 @@ void G1CMMarkStack::expand() { _chunk_allocator.try_expand(); } -void G1CMMarkStack::add_chunk_to_list(TaskQueueEntryChunk* volatile* list, TaskQueueEntryChunk* elem) { - elem->next = *list; - *list = elem; +void G1CMMarkStack::add_chunk_to_list(Atomic* list, TaskQueueEntryChunk* elem) { + elem->next = list->load_relaxed(); + list->store_relaxed(elem); } void G1CMMarkStack::add_chunk_to_chunk_list(TaskQueueEntryChunk* elem) { @@ -307,10 +307,10 @@ void G1CMMarkStack::add_chunk_to_free_list(TaskQueueEntryChunk* elem) { add_chunk_to_list(&_free_list, elem); } -G1CMMarkStack::TaskQueueEntryChunk* G1CMMarkStack::remove_chunk_from_list(TaskQueueEntryChunk* volatile* list) { - TaskQueueEntryChunk* result = *list; +G1CMMarkStack::TaskQueueEntryChunk* G1CMMarkStack::remove_chunk_from_list(Atomic* list) { + TaskQueueEntryChunk* result = list->load_relaxed(); if (result != nullptr) { - *list = (*list)->next; + list->store_relaxed(list->load_relaxed()->next); } return result; } @@ -364,8 +364,8 @@ bool G1CMMarkStack::par_pop_chunk(G1TaskQueueEntry* ptr_arr) { void G1CMMarkStack::set_empty() { _chunks_in_chunk_list = 0; - _chunk_list = nullptr; - _free_list = nullptr; + _chunk_list.store_relaxed(nullptr); + _free_list.store_relaxed(nullptr); _chunk_allocator.reset(); } diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp index 52a1b133439..836d7793f81 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp @@ -210,17 +210,17 @@ private: ChunkAllocator _chunk_allocator; char _pad0[DEFAULT_PADDING_SIZE]; - TaskQueueEntryChunk* volatile _free_list; // Linked list of free chunks that can be allocated by users. + Atomic _free_list; // Linked list of free chunks that can be allocated by users. char _pad1[DEFAULT_PADDING_SIZE - sizeof(TaskQueueEntryChunk*)]; - TaskQueueEntryChunk* volatile _chunk_list; // List of chunks currently containing data. + Atomic _chunk_list; // List of chunks currently containing data. volatile size_t _chunks_in_chunk_list; char _pad2[DEFAULT_PADDING_SIZE - sizeof(TaskQueueEntryChunk*) - sizeof(size_t)]; // Atomically add the given chunk to the list. - void add_chunk_to_list(TaskQueueEntryChunk* volatile* list, TaskQueueEntryChunk* elem); + void add_chunk_to_list(Atomic* list, TaskQueueEntryChunk* elem); // Atomically remove and return a chunk from the given list. Returns null if the // list is empty. - TaskQueueEntryChunk* remove_chunk_from_list(TaskQueueEntryChunk* volatile* list); + TaskQueueEntryChunk* remove_chunk_from_list(Atomic* list); void add_chunk_to_chunk_list(TaskQueueEntryChunk* elem); void add_chunk_to_free_list(TaskQueueEntryChunk* elem); @@ -252,7 +252,7 @@ private: // Return whether the chunk list is empty. Racy due to unsynchronized access to // _chunk_list. - bool is_empty() const { return _chunk_list == nullptr; } + bool is_empty() const { return _chunk_list.load_relaxed() == nullptr; } size_t capacity() const { return _chunk_allocator.capacity(); } diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp index fe72c68d4eb..2f4824e4cae 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp @@ -90,7 +90,7 @@ inline void G1CMMarkStack::iterate(Fn fn) const { size_t num_chunks = 0; - TaskQueueEntryChunk* cur = _chunk_list; + TaskQueueEntryChunk* cur = _chunk_list.load_relaxed(); while (cur != nullptr) { guarantee(num_chunks <= _chunks_in_chunk_list, "Found %zu oop chunks which is more than there should be", num_chunks); diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.cpp b/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.cpp index fdef4214622..4eb11f6d8f6 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -30,7 +30,6 @@ #include "gc/g1/g1HeapRegionPrinter.hpp" #include "gc/g1/g1RemSetTrackingPolicy.hpp" #include "logging/log.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/mutexLocker.hpp" struct G1UpdateRegionLivenessAndSelectForRebuildTask::G1OnRegionClosure : public G1HeapRegionClosure { @@ -154,7 +153,7 @@ void G1UpdateRegionLivenessAndSelectForRebuildTask::work(uint worker_id) { G1OnRegionClosure on_region_cl(_g1h, _cm, &local_cleanup_list); _g1h->heap_region_par_iterate_from_worker_offset(&on_region_cl, &_hrclaimer, worker_id); - AtomicAccess::add(&_total_selected_for_rebuild, on_region_cl._num_selected_for_rebuild); + _total_selected_for_rebuild.add_then_fetch(on_region_cl._num_selected_for_rebuild); // Update the old/humongous region sets _g1h->remove_from_old_gen_sets(on_region_cl._num_old_regions_removed, diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.hpp index 161f0b4b9f5..a256693ff1d 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkRemarkTasks.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -29,6 +29,7 @@ #include "gc/g1/g1HeapRegionManager.hpp" #include "gc/g1/g1HeapRegionSet.hpp" #include "gc/shared/workerThread.hpp" +#include "runtime/atomic.hpp" class G1CollectedHeap; class G1ConcurrentMark; @@ -41,7 +42,7 @@ class G1UpdateRegionLivenessAndSelectForRebuildTask : public WorkerTask { G1ConcurrentMark* _cm; G1HeapRegionClaimer _hrclaimer; - uint volatile _total_selected_for_rebuild; + Atomic _total_selected_for_rebuild; // Reclaimed empty regions G1FreeRegionList _cleanup_list; @@ -57,7 +58,9 @@ public: void work(uint worker_id) override; - uint total_selected_for_rebuild() const { return _total_selected_for_rebuild; } + uint total_selected_for_rebuild() const { + return _total_selected_for_rebuild.load_relaxed(); + } static uint desired_num_workers(uint num_regions); }; diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp index ed6a9ad4292..8546e6e2d64 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp @@ -28,6 +28,7 @@ #include "gc/g1/g1CollectedHeap.inline.hpp" #include "gc/g1/g1CollectionSet.hpp" #include "gc/g1/g1ConcurrentRefine.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1ConcurrentRefineSweepTask.hpp" #include "gc/g1/g1ConcurrentRefineThread.hpp" #include "gc/g1/g1HeapRegion.inline.hpp" diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp index 83a09c55a3f..5160d5ed036 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -22,7 +22,7 @@ * */ -#include "gc/g1/g1ConcurrentRefineStats.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "runtime/atomicAccess.hpp" #include "runtime/timer.hpp" @@ -39,19 +39,27 @@ G1ConcurrentRefineStats::G1ConcurrentRefineStats() : {} void G1ConcurrentRefineStats::add_atomic(G1ConcurrentRefineStats* other) { - AtomicAccess::add(&_sweep_duration, other->_sweep_duration, memory_order_relaxed); - AtomicAccess::add(&_yield_during_sweep_duration, other->_yield_during_sweep_duration, memory_order_relaxed); + _sweep_duration.add_then_fetch(other->_sweep_duration.load_relaxed(), memory_order_relaxed); + _yield_during_sweep_duration.add_then_fetch(other->yield_during_sweep_duration(), memory_order_relaxed); - AtomicAccess::add(&_cards_scanned, other->_cards_scanned, memory_order_relaxed); - AtomicAccess::add(&_cards_clean, other->_cards_clean, memory_order_relaxed); - AtomicAccess::add(&_cards_not_parsable, other->_cards_not_parsable, memory_order_relaxed); - AtomicAccess::add(&_cards_already_refer_to_cset, other->_cards_already_refer_to_cset, memory_order_relaxed); - AtomicAccess::add(&_cards_refer_to_cset, other->_cards_refer_to_cset, memory_order_relaxed); - AtomicAccess::add(&_cards_no_cross_region, other->_cards_no_cross_region, memory_order_relaxed); + _cards_scanned.add_then_fetch(other->cards_scanned(), memory_order_relaxed); + _cards_clean.add_then_fetch(other->cards_clean(), memory_order_relaxed); + _cards_not_parsable.add_then_fetch(other->cards_not_parsable(), memory_order_relaxed); + _cards_already_refer_to_cset.add_then_fetch(other->cards_already_refer_to_cset(), memory_order_relaxed); + _cards_refer_to_cset.add_then_fetch(other->cards_refer_to_cset(), memory_order_relaxed); + _cards_no_cross_region.add_then_fetch(other->cards_no_cross_region(), memory_order_relaxed); - AtomicAccess::add(&_refine_duration, other->_refine_duration, memory_order_relaxed); + _refine_duration.add_then_fetch(other->refine_duration(), memory_order_relaxed); } void G1ConcurrentRefineStats::reset() { - *this = G1ConcurrentRefineStats(); + _sweep_duration.store_relaxed(0); + _yield_during_sweep_duration.store_relaxed(0); + _cards_scanned.store_relaxed(0); + _cards_clean.store_relaxed(0); + _cards_not_parsable.store_relaxed(0); + _cards_already_refer_to_cset.store_relaxed(0); + _cards_refer_to_cset.store_relaxed(0); + _cards_no_cross_region.store_relaxed(0); + _refine_duration.store_relaxed(0); } diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp index ce22f4317df..5f57c56ba6c 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -26,61 +26,61 @@ #define SHARE_GC_G1_G1CONCURRENTREFINESTATS_HPP #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" -#include "utilities/ticks.hpp" // Collection of statistics for concurrent refinement processing. // Used for collecting per-thread statistics and for summaries over a // collection of threads. class G1ConcurrentRefineStats : public CHeapObj { - jlong _sweep_duration; // Time spent sweeping the table finding non-clean cards - // and refining them. - jlong _yield_during_sweep_duration; // Time spent yielding during the sweep (not doing the sweep). + Atomic _sweep_duration; // Time spent sweeping the table finding non-clean cards + // and refining them. + Atomic _yield_during_sweep_duration; // Time spent yielding during the sweep (not doing the sweep). - size_t _cards_scanned; // Total number of cards scanned. - size_t _cards_clean; // Number of cards found clean. - size_t _cards_not_parsable; // Number of cards we could not parse and left unrefined. - size_t _cards_already_refer_to_cset;// Number of cards marked found to be already young. - size_t _cards_refer_to_cset; // Number of dirty cards that were recently found to contain a to-cset reference. - size_t _cards_no_cross_region; // Number of dirty cards that were dirtied, but then cleaned again by the mutator. + Atomic _cards_scanned; // Total number of cards scanned. + Atomic _cards_clean; // Number of cards found clean. + Atomic _cards_not_parsable; // Number of cards we could not parse and left unrefined. + Atomic _cards_already_refer_to_cset;// Number of cards marked found to be already young. + Atomic _cards_refer_to_cset; // Number of dirty cards that were recently found to contain a to-cset reference. + Atomic _cards_no_cross_region; // Number of dirty cards that were dirtied, but then cleaned again by the mutator. - jlong _refine_duration; // Time spent during actual refinement. + Atomic _refine_duration; // Time spent during actual refinement. public: G1ConcurrentRefineStats(); // Time spent performing sweeping the refinement table (includes actual refinement, // but not yield time). - jlong sweep_duration() const { return _sweep_duration - _yield_during_sweep_duration; } - jlong yield_during_sweep_duration() const { return _yield_during_sweep_duration; } - jlong refine_duration() const { return _refine_duration; } + inline jlong sweep_duration() const; + inline jlong yield_during_sweep_duration() const; + inline jlong refine_duration() const; // Number of refined cards. - size_t refined_cards() const { return cards_not_clean(); } + inline size_t refined_cards() const; - size_t cards_scanned() const { return _cards_scanned; } - size_t cards_clean() const { return _cards_clean; } - size_t cards_not_clean() const { return _cards_scanned - _cards_clean; } - size_t cards_not_parsable() const { return _cards_not_parsable; } - size_t cards_already_refer_to_cset() const { return _cards_already_refer_to_cset; } - size_t cards_refer_to_cset() const { return _cards_refer_to_cset; } - size_t cards_no_cross_region() const { return _cards_no_cross_region; } + inline size_t cards_scanned() const; + inline size_t cards_clean() const; + inline size_t cards_not_clean() const; + inline size_t cards_not_parsable() const; + inline size_t cards_already_refer_to_cset() const; + inline size_t cards_refer_to_cset() const; + inline size_t cards_no_cross_region() const; // Number of cards that were marked dirty and in need of refinement. This includes cards recently // found to refer to the collection set as they originally were dirty. - size_t cards_pending() const { return cards_not_clean() - _cards_already_refer_to_cset; } + inline size_t cards_pending() const; - size_t cards_to_cset() const { return _cards_already_refer_to_cset + _cards_refer_to_cset; } + inline size_t cards_to_cset() const; - void inc_sweep_time(jlong t) { _sweep_duration += t; } - void inc_yield_during_sweep_duration(jlong t) { _yield_during_sweep_duration += t; } - void inc_refine_duration(jlong t) { _refine_duration += t; } + inline void inc_sweep_time(jlong t); + inline void inc_yield_during_sweep_duration(jlong t); + inline void inc_refine_duration(jlong t); - void inc_cards_scanned(size_t increment) { _cards_scanned += increment; } - void inc_cards_clean(size_t increment) { _cards_clean += increment; } - void inc_cards_not_parsable() { _cards_not_parsable++; } - void inc_cards_already_refer_to_cset() { _cards_already_refer_to_cset++; } - void inc_cards_refer_to_cset() { _cards_refer_to_cset++; } - void inc_cards_no_cross_region() { _cards_no_cross_region++; } + inline void inc_cards_scanned(size_t increment); + inline void inc_cards_clean(size_t increment); + inline void inc_cards_not_parsable(); + inline void inc_cards_already_refer_to_cset(); + inline void inc_cards_refer_to_cset(); + inline void inc_cards_no_cross_region(); void add_atomic(G1ConcurrentRefineStats* other); diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp new file mode 100644 index 00000000000..e1a296c6494 --- /dev/null +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineStats.inline.hpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2026, 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_GC_G1_G1CONCURRENTREFINESTATS_INLINE_HPP +#define SHARE_GC_G1_G1CONCURRENTREFINESTATS_INLINE_HPP + +#include "gc/g1/g1ConcurrentRefineStats.hpp" + +inline jlong G1ConcurrentRefineStats::sweep_duration() const { + return _sweep_duration.load_relaxed() - yield_during_sweep_duration(); +} + +inline jlong G1ConcurrentRefineStats::yield_during_sweep_duration() const { + return _yield_during_sweep_duration.load_relaxed(); +} + +inline jlong G1ConcurrentRefineStats::refine_duration() const { + return _refine_duration.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::refined_cards() const { + return cards_not_clean(); +} + +inline size_t G1ConcurrentRefineStats::cards_scanned() const { + return _cards_scanned.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_clean() const { + return _cards_clean.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_not_clean() const { + return cards_scanned() - cards_clean(); +} + +inline size_t G1ConcurrentRefineStats::cards_not_parsable() const { + return _cards_not_parsable.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_already_refer_to_cset() const { + return _cards_already_refer_to_cset.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_refer_to_cset() const { + return _cards_refer_to_cset.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_no_cross_region() const { + return _cards_no_cross_region.load_relaxed(); +} + +inline size_t G1ConcurrentRefineStats::cards_pending() const { + return cards_not_clean() - cards_already_refer_to_cset(); +} + +inline size_t G1ConcurrentRefineStats::cards_to_cset() const { + return cards_already_refer_to_cset() + cards_refer_to_cset(); +} + +inline void G1ConcurrentRefineStats::inc_sweep_time(jlong t) { + _sweep_duration.store_relaxed(_sweep_duration.load_relaxed() + t); +} + +inline void G1ConcurrentRefineStats::inc_yield_during_sweep_duration(jlong t) { + _yield_during_sweep_duration.store_relaxed(yield_during_sweep_duration() + t); +} + +inline void G1ConcurrentRefineStats::inc_refine_duration(jlong t) { + _refine_duration.store_relaxed(refine_duration() + t); +} + +inline void G1ConcurrentRefineStats::inc_cards_scanned(size_t increment) { + _cards_scanned.store_relaxed(cards_scanned() + increment); +} + +inline void G1ConcurrentRefineStats::inc_cards_clean(size_t increment) { + _cards_clean.store_relaxed(cards_clean() + increment); +} + +inline void G1ConcurrentRefineStats::inc_cards_not_parsable() { + _cards_not_parsable.store_relaxed(cards_not_parsable() + 1); +} + +inline void G1ConcurrentRefineStats::inc_cards_already_refer_to_cset() { + _cards_already_refer_to_cset.store_relaxed(cards_already_refer_to_cset() + 1); +} + +inline void G1ConcurrentRefineStats::inc_cards_refer_to_cset() { + _cards_refer_to_cset.store_relaxed(cards_refer_to_cset() + 1); +} + +inline void G1ConcurrentRefineStats::inc_cards_no_cross_region() { + _cards_no_cross_region.store_relaxed(cards_no_cross_region() + 1); +} + +#endif // SHARE_GC_G1_G1CONCURRENTREFINESTATS_INLINE_HPP diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp index ca5bc9ebe5f..ce944f2254d 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.cpp @@ -24,6 +24,7 @@ #include "gc/g1/g1CardTableClaimTable.inline.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1ConcurrentRefineSweepTask.hpp" class G1RefineRegionClosure : public G1HeapRegionClosure { diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp index bf24c5ae850..827b9a3c402 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineSweepTask.hpp @@ -25,10 +25,10 @@ #ifndef SHARE_GC_G1_G1CONCURRENTREFINESWEEPTASK_HPP #define SHARE_GC_G1_G1CONCURRENTREFINESWEEPTASK_HPP -#include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/shared/workerThread.hpp" class G1CardTableClaimTable; +class G1ConcurrentRefineStats; class G1ConcurrentRefineSweepTask : public WorkerTask { G1CardTableClaimTable* _scan_state; diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp index eccfe466d48..6b51e5eef62 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.cpp @@ -26,7 +26,7 @@ #include "gc/g1/g1CardTableClaimTable.inline.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp" #include "gc/g1/g1ConcurrentRefine.hpp" -#include "gc/g1/g1ConcurrentRefineStats.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1ConcurrentRefineSweepTask.hpp" #include "gc/g1/g1ConcurrentRefineThread.hpp" #include "gc/shared/gcTraceTime.inline.hpp" diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp index 7cdc001d348..2ecbdc668eb 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefineThread.hpp @@ -25,7 +25,6 @@ #ifndef SHARE_GC_G1_G1CONCURRENTREFINETHREAD_HPP #define SHARE_GC_G1_G1CONCURRENTREFINETHREAD_HPP -#include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/shared/concurrentGCThread.hpp" #include "runtime/mutex.hpp" #include "utilities/globalDefinitions.hpp" diff --git a/src/hotspot/share/gc/g1/g1EvacStats.cpp b/src/hotspot/share/gc/g1/g1EvacStats.cpp index 049175a4ecc..1d54b184e64 100644 --- a/src/hotspot/share/gc/g1/g1EvacStats.cpp +++ b/src/hotspot/share/gc/g1/g1EvacStats.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -22,13 +22,24 @@ * */ -#include "gc/g1/g1EvacStats.hpp" +#include "gc/g1/g1EvacStats.inline.hpp" #include "gc/shared/gc_globals.hpp" #include "gc/shared/gcId.hpp" #include "logging/log.hpp" #include "memory/allocation.inline.hpp" #include "runtime/globals.hpp" +void G1EvacStats::reset() { + PLABStats::reset(); + _region_end_waste.store_relaxed(0); + _regions_filled.store_relaxed(0); + _num_plab_filled.store_relaxed(0); + _direct_allocated.store_relaxed(0); + _num_direct_allocated.store_relaxed(0); + _failure_used.store_relaxed(0); + _failure_waste.store_relaxed(0); +} + void G1EvacStats::log_plab_allocation() { log_debug(gc, plab)("%s PLAB allocation: " "allocated: %zuB, " @@ -51,13 +62,13 @@ void G1EvacStats::log_plab_allocation() { "failure used: %zuB, " "failure wasted: %zuB", _description, - _region_end_waste * HeapWordSize, - _regions_filled, - _num_plab_filled, - _direct_allocated * HeapWordSize, - _num_direct_allocated, - _failure_used * HeapWordSize, - _failure_waste * HeapWordSize); + region_end_waste() * HeapWordSize, + regions_filled(), + num_plab_filled(), + direct_allocated() * HeapWordSize, + num_direct_allocated(), + failure_used() * HeapWordSize, + failure_waste() * HeapWordSize); } void G1EvacStats::log_sizing(size_t calculated_words, size_t net_desired_words) { @@ -109,7 +120,7 @@ size_t G1EvacStats::compute_desired_plab_size() const { // threads do not allocate anything but a few rather large objects. In this // degenerate case the PLAB size would simply quickly tend to minimum PLAB size, // which is an okay reaction. - size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0; + size_t const used_for_waste_calculation = used() > region_end_waste() ? used() - region_end_waste() : 0; size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct; return (size_t)((double)total_waste_allowed / (100 - G1LastPLABAverageOccupancy)); diff --git a/src/hotspot/share/gc/g1/g1EvacStats.hpp b/src/hotspot/share/gc/g1/g1EvacStats.hpp index e6eb80442d6..b250d4580b5 100644 --- a/src/hotspot/share/gc/g1/g1EvacStats.hpp +++ b/src/hotspot/share/gc/g1/g1EvacStats.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -27,6 +27,7 @@ #include "gc/shared/gcUtil.hpp" #include "gc/shared/plab.hpp" +#include "runtime/atomic.hpp" // Records various memory allocation statistics gathered during evacuation. All sizes // are in HeapWords. @@ -36,30 +37,21 @@ class G1EvacStats : public PLABStats { AdaptiveWeightedAverage _net_plab_size_filter; // Integrator with decay - size_t _region_end_waste; // Number of words wasted due to skipping to the next region. - uint _regions_filled; // Number of regions filled completely. - size_t _num_plab_filled; // Number of PLABs filled and retired. - size_t _direct_allocated; // Number of words allocated directly into the regions. - size_t _num_direct_allocated; // Number of direct allocation attempts. + Atomic _region_end_waste; // Number of words wasted due to skipping to the next region. + Atomic _regions_filled; // Number of regions filled completely. + Atomic _num_plab_filled; // Number of PLABs filled and retired. + Atomic _direct_allocated; // Number of words allocated directly into the regions. + Atomic _num_direct_allocated; // Number of direct allocation attempts. // Number of words in live objects remaining in regions that ultimately suffered an // evacuation failure. This is used in the regions when the regions are made old regions. - size_t _failure_used; + Atomic _failure_used; // Number of words wasted in regions which failed evacuation. This is the sum of space // for objects successfully copied out of the regions (now dead space) plus waste at the // end of regions. - size_t _failure_waste; + Atomic _failure_waste; - virtual void reset() { - PLABStats::reset(); - _region_end_waste = 0; - _regions_filled = 0; - _num_plab_filled = 0; - _direct_allocated = 0; - _num_direct_allocated = 0; - _failure_used = 0; - _failure_waste = 0; - } + virtual void reset(); void log_plab_allocation(); void log_sizing(size_t calculated_words, size_t net_desired_words); @@ -77,16 +69,16 @@ public: // Should be called at the end of a GC pause. void adjust_desired_plab_size(); - uint regions_filled() const { return _regions_filled; } - size_t num_plab_filled() const { return _num_plab_filled; } - size_t region_end_waste() const { return _region_end_waste; } - size_t direct_allocated() const { return _direct_allocated; } - size_t num_direct_allocated() const { return _num_direct_allocated; } + uint regions_filled() const; + size_t num_plab_filled() const; + size_t region_end_waste() const; + size_t direct_allocated() const; + size_t num_direct_allocated() const; // Amount of space in heapwords used in the failing regions when an evacuation failure happens. - size_t failure_used() const { return _failure_used; } + size_t failure_used() const; // Amount of space in heapwords wasted (unused) in the failing regions when an evacuation failure happens. - size_t failure_waste() const { return _failure_waste; } + size_t failure_waste() const; inline void add_num_plab_filled(size_t value); inline void add_direct_allocated(size_t value); diff --git a/src/hotspot/share/gc/g1/g1EvacStats.inline.hpp b/src/hotspot/share/gc/g1/g1EvacStats.inline.hpp index c90598a30cb..2bd3b37719a 100644 --- a/src/hotspot/share/gc/g1/g1EvacStats.inline.hpp +++ b/src/hotspot/share/gc/g1/g1EvacStats.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -27,28 +27,54 @@ #include "gc/g1/g1EvacStats.hpp" -#include "runtime/atomicAccess.hpp" +inline uint G1EvacStats::regions_filled() const { + return _regions_filled.load_relaxed(); +} + +inline size_t G1EvacStats::num_plab_filled() const { + return _num_plab_filled.load_relaxed(); +} + +inline size_t G1EvacStats::region_end_waste() const { + return _region_end_waste.load_relaxed(); +} + +inline size_t G1EvacStats::direct_allocated() const { + return _direct_allocated.load_relaxed(); +} + +inline size_t G1EvacStats::num_direct_allocated() const { + return _num_direct_allocated.load_relaxed(); +} + +inline size_t G1EvacStats::failure_used() const { + return _failure_used.load_relaxed(); +} + +inline size_t G1EvacStats::failure_waste() const { + return _failure_waste.load_relaxed(); +} inline void G1EvacStats::add_direct_allocated(size_t value) { - AtomicAccess::add(&_direct_allocated, value, memory_order_relaxed); + _direct_allocated.add_then_fetch(value, memory_order_relaxed); } inline void G1EvacStats::add_num_plab_filled(size_t value) { - AtomicAccess::add(&_num_plab_filled, value, memory_order_relaxed); + _num_plab_filled.add_then_fetch(value, memory_order_relaxed); } inline void G1EvacStats::add_num_direct_allocated(size_t value) { - AtomicAccess::add(&_num_direct_allocated, value, memory_order_relaxed); + _num_direct_allocated.add_then_fetch(value, memory_order_relaxed); } inline void G1EvacStats::add_region_end_waste(size_t value) { - AtomicAccess::add(&_region_end_waste, value, memory_order_relaxed); - AtomicAccess::inc(&_regions_filled, memory_order_relaxed); + _region_end_waste.add_then_fetch(value, memory_order_relaxed); + _regions_filled.add_then_fetch(1u, memory_order_relaxed); } inline void G1EvacStats::add_failure_used_and_waste(size_t used, size_t waste) { - AtomicAccess::add(&_failure_used, used, memory_order_relaxed); - AtomicAccess::add(&_failure_waste, waste, memory_order_relaxed); + _failure_used.add_then_fetch(used, memory_order_relaxed); + _failure_waste.add_then_fetch(waste, memory_order_relaxed); } #endif // SHARE_GC_G1_G1EVACSTATS_INLINE_HPP diff --git a/src/hotspot/share/gc/g1/g1FullCollector.cpp b/src/hotspot/share/gc/g1/g1FullCollector.cpp index 7395df01760..6c8cc7028cc 100644 --- a/src/hotspot/share/gc/g1/g1FullCollector.cpp +++ b/src/hotspot/share/gc/g1/g1FullCollector.cpp @@ -134,10 +134,10 @@ G1FullCollector::G1FullCollector(G1CollectedHeap* heap, _compaction_points = NEW_C_HEAP_ARRAY(G1FullGCCompactionPoint*, _num_workers, mtGC); _live_stats = NEW_C_HEAP_ARRAY(G1RegionMarkStats, _heap->max_num_regions(), mtGC); - _compaction_tops = NEW_C_HEAP_ARRAY(HeapWord*, _heap->max_num_regions(), mtGC); + _compaction_tops = NEW_C_HEAP_ARRAY(Atomic, _heap->max_num_regions(), mtGC); for (uint j = 0; j < heap->max_num_regions(); j++) { _live_stats[j].clear(); - _compaction_tops[j] = nullptr; + ::new (&_compaction_tops[j]) Atomic{}; } _partial_array_state_manager = new PartialArrayStateManager(_num_workers); @@ -167,7 +167,7 @@ G1FullCollector::~G1FullCollector() { FREE_C_HEAP_ARRAY(G1FullGCMarker*, _markers); FREE_C_HEAP_ARRAY(G1FullGCCompactionPoint*, _compaction_points); - FREE_C_HEAP_ARRAY(HeapWord*, _compaction_tops); + FREE_C_HEAP_ARRAY(Atomic, _compaction_tops); FREE_C_HEAP_ARRAY(G1RegionMarkStats, _live_stats); } diff --git a/src/hotspot/share/gc/g1/g1FullCollector.hpp b/src/hotspot/share/gc/g1/g1FullCollector.hpp index 28ecffad944..7e455b07013 100644 --- a/src/hotspot/share/gc/g1/g1FullCollector.hpp +++ b/src/hotspot/share/gc/g1/g1FullCollector.hpp @@ -96,7 +96,7 @@ class G1FullCollector : StackObj { G1FullGCHeapRegionAttr _region_attr_table; - HeapWord* volatile* _compaction_tops; + Atomic* _compaction_tops; public: G1FullCollector(G1CollectedHeap* heap, diff --git a/src/hotspot/share/gc/g1/g1FullCollector.inline.hpp b/src/hotspot/share/gc/g1/g1FullCollector.inline.hpp index b52f3d79604..0c201f0e43f 100644 --- a/src/hotspot/share/gc/g1/g1FullCollector.inline.hpp +++ b/src/hotspot/share/gc/g1/g1FullCollector.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -63,11 +63,11 @@ void G1FullCollector::update_from_skip_compacting_to_compacting(uint region_idx) } void G1FullCollector::set_compaction_top(G1HeapRegion* r, HeapWord* value) { - AtomicAccess::store(&_compaction_tops[r->hrm_index()], value); + _compaction_tops[r->hrm_index()].store_relaxed(value); } HeapWord* G1FullCollector::compaction_top(G1HeapRegion* r) const { - return AtomicAccess::load(&_compaction_tops[r->hrm_index()]); + return _compaction_tops[r->hrm_index()].load_relaxed(); } void G1FullCollector::set_has_compaction_targets() { diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index 8818b477aae..1d0b29c303e 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -32,7 +32,7 @@ #include "gc/g1/g1ConcurrentMark.hpp" #include "gc/g1/g1ConcurrentMarkThread.inline.hpp" #include "gc/g1/g1ConcurrentRefine.hpp" -#include "gc/g1/g1ConcurrentRefineStats.hpp" +#include "gc/g1/g1ConcurrentRefineStats.inline.hpp" #include "gc/g1/g1GCPhaseTimes.hpp" #include "gc/g1/g1HeapRegion.inline.hpp" #include "gc/g1/g1HeapRegionRemSet.inline.hpp" diff --git a/src/hotspot/share/gc/g1/g1RemSet.cpp b/src/hotspot/share/gc/g1/g1RemSet.cpp index c7724de280f..0c9a0fad8f2 100644 --- a/src/hotspot/share/gc/g1/g1RemSet.cpp +++ b/src/hotspot/share/gc/g1/g1RemSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2026, 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 @@ -50,7 +50,7 @@ #include "memory/resourceArea.hpp" #include "oops/access.inline.hpp" #include "oops/oop.inline.hpp" -#include "runtime/atomicAccess.hpp" +#include "runtime/atomic.hpp" #include "runtime/os.hpp" #include "utilities/align.hpp" #include "utilities/globalDefinitions.hpp" @@ -107,46 +107,48 @@ class G1RemSetScanState : public CHeapObj { // Set of (unique) regions that can be added to concurrently. class G1DirtyRegions : public CHeapObj { uint* _buffer; - uint _cur_idx; + Atomic _cur_idx; size_t _max_reserved_regions; - bool* _contains; + Atomic* _contains; public: G1DirtyRegions(size_t max_reserved_regions) : _buffer(NEW_C_HEAP_ARRAY(uint, max_reserved_regions, mtGC)), _cur_idx(0), _max_reserved_regions(max_reserved_regions), - _contains(NEW_C_HEAP_ARRAY(bool, max_reserved_regions, mtGC)) { + _contains(NEW_C_HEAP_ARRAY(Atomic, max_reserved_regions, mtGC)) { reset(); } ~G1DirtyRegions() { FREE_C_HEAP_ARRAY(uint, _buffer); - FREE_C_HEAP_ARRAY(bool, _contains); + FREE_C_HEAP_ARRAY(Atomic, _contains); } void reset() { - _cur_idx = 0; - ::memset(_contains, false, _max_reserved_regions * sizeof(bool)); + _cur_idx.store_relaxed(0); + for (uint i = 0; i < _max_reserved_regions; i++) { + _contains[i].store_relaxed(false); + } } - uint size() const { return _cur_idx; } + uint size() const { return _cur_idx.load_relaxed(); } uint at(uint idx) const { - assert(idx < _cur_idx, "Index %u beyond valid regions", idx); + assert(idx < size(), "Index %u beyond valid regions", idx); return _buffer[idx]; } void add_dirty_region(uint region) { - if (_contains[region]) { + if (_contains[region].load_relaxed()) { return; } - bool marked_as_dirty = AtomicAccess::cmpxchg(&_contains[region], false, true) == false; + bool marked_as_dirty = _contains[region].compare_set(false, true); if (marked_as_dirty) { - uint allocated = AtomicAccess::fetch_then_add(&_cur_idx, 1u); + uint allocated = _cur_idx.fetch_then_add(1u); _buffer[allocated] = region; } } @@ -155,9 +157,11 @@ class G1RemSetScanState : public CHeapObj { void merge(const G1DirtyRegions* other) { for (uint i = 0; i < other->size(); i++) { uint region = other->at(i); - if (!_contains[region]) { - _buffer[_cur_idx++] = region; - _contains[region] = true; + if (!_contains[region].load_relaxed()) { + uint cur = _cur_idx.load_relaxed(); + _buffer[cur] = region; + _cur_idx.store_relaxed(cur + 1); + _contains[region].store_relaxed(true); } } } @@ -173,7 +177,7 @@ class G1RemSetScanState : public CHeapObj { class G1ClearCardTableTask : public G1AbstractSubTask { G1CollectedHeap* _g1h; G1DirtyRegions* _regions; - uint volatile _cur_dirty_regions; + Atomic _cur_dirty_regions; G1RemSetScanState* _scan_state; @@ -210,8 +214,9 @@ class G1ClearCardTableTask : public G1AbstractSubTask { void do_work(uint worker_id) override { const uint num_regions_per_worker = num_cards_per_worker / (uint)G1HeapRegion::CardsPerRegion; - while (_cur_dirty_regions < _regions->size()) { - uint next = AtomicAccess::fetch_then_add(&_cur_dirty_regions, num_regions_per_worker); + uint cur = _cur_dirty_regions.load_relaxed(); + while (cur < _regions->size()) { + uint next = _cur_dirty_regions.fetch_then_add(num_regions_per_worker); uint max = MIN2(next + num_regions_per_worker, _regions->size()); for (uint i = next; i < max; i++) { @@ -226,6 +231,7 @@ class G1ClearCardTableTask : public G1AbstractSubTask { // old regions use it for old->collection set candidates, so they should not be cleared // either. } + cur = max; } } }; @@ -1115,7 +1121,7 @@ class G1MergeHeapRootsTask : public WorkerTask { bool _initial_evacuation; - volatile bool _fast_reclaim_handled; + Atomic _fast_reclaim_handled; public: G1MergeHeapRootsTask(G1RemSetScanState* scan_state, uint num_workers, bool initial_evacuation) : @@ -1143,8 +1149,8 @@ public: // 1. eager-reclaim candidates if (_initial_evacuation && g1h->has_humongous_reclaim_candidates() && - !_fast_reclaim_handled && - !AtomicAccess::cmpxchg(&_fast_reclaim_handled, false, true)) { + !_fast_reclaim_handled.load_relaxed() && + _fast_reclaim_handled.compare_set(false, true)) { G1GCParPhaseTimesTracker subphase_x(p, G1GCPhaseTimes::MergeER, worker_id); diff --git a/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp b/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp index b11213ddeb3..c0870b7a726 100644 --- a/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp +++ b/src/hotspot/share/gc/g1/g1YoungGCPreEvacuateTasks.cpp @@ -23,7 +23,6 @@ */ #include "gc/g1/g1CollectedHeap.inline.hpp" -#include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/g1/g1RegionPinCache.inline.hpp" #include "gc/g1/g1ThreadLocalData.hpp" #include "gc/g1/g1YoungGCPreEvacuateTasks.hpp" diff --git a/src/hotspot/share/gc/shared/oopStorageSetParState.inline.hpp b/src/hotspot/share/gc/shared/oopStorageSetParState.inline.hpp index 8e220e745e5..8341a3b20c4 100644 --- a/src/hotspot/share/gc/shared/oopStorageSetParState.inline.hpp +++ b/src/hotspot/share/gc/shared/oopStorageSetParState.inline.hpp @@ -31,7 +31,6 @@ #include "gc/shared/oopStorageSet.hpp" #include "memory/iterator.hpp" #include "oops/access.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/debug.hpp" template diff --git a/src/hotspot/share/gc/shared/partialArrayState.cpp b/src/hotspot/share/gc/shared/partialArrayState.cpp index 6f714d48a35..aadbc46b7c1 100644 --- a/src/hotspot/share/gc/shared/partialArrayState.cpp +++ b/src/hotspot/share/gc/shared/partialArrayState.cpp @@ -28,7 +28,6 @@ #include "memory/arena.hpp" #include "nmt/memTag.hpp" #include "oops/oopsHierarchy.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/orderAccess.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" diff --git a/src/hotspot/share/gc/shared/partialArrayTaskStepper.inline.hpp b/src/hotspot/share/gc/shared/partialArrayTaskStepper.inline.hpp index aaa86e2de16..6946f7c69ff 100644 --- a/src/hotspot/share/gc/shared/partialArrayTaskStepper.inline.hpp +++ b/src/hotspot/share/gc/shared/partialArrayTaskStepper.inline.hpp @@ -28,7 +28,6 @@ #include "gc/shared/partialArrayTaskStepper.hpp" #include "gc/shared/partialArrayState.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/checkedCast.hpp" #include "utilities/debug.hpp" diff --git a/src/hotspot/share/gc/shared/taskqueue.cpp b/src/hotspot/share/gc/shared/taskqueue.cpp index f75dc4c2923..58af1793a48 100644 --- a/src/hotspot/share/gc/shared/taskqueue.cpp +++ b/src/hotspot/share/gc/shared/taskqueue.cpp @@ -25,7 +25,6 @@ #include "gc/shared/taskqueue.hpp" #include "logging/log.hpp" #include "oops/oop.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/javaThread.hpp" #include "runtime/os.hpp" #include "utilities/debug.hpp" diff --git a/src/hotspot/share/gc/shared/taskqueue.inline.hpp b/src/hotspot/share/gc/shared/taskqueue.inline.hpp index 55851495a5f..e77645f4fcf 100644 --- a/src/hotspot/share/gc/shared/taskqueue.inline.hpp +++ b/src/hotspot/share/gc/shared/taskqueue.inline.hpp @@ -32,7 +32,6 @@ #include "memory/allocation.inline.hpp" #include "memory/resourceArea.hpp" #include "oops/oop.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/orderAccess.hpp" #include "utilities/debug.hpp" #include "utilities/ostream.hpp" diff --git a/src/hotspot/share/gc/shared/workerThread.cpp b/src/hotspot/share/gc/shared/workerThread.cpp index e4831d25d26..2f6f003608f 100644 --- a/src/hotspot/share/gc/shared/workerThread.cpp +++ b/src/hotspot/share/gc/shared/workerThread.cpp @@ -26,7 +26,6 @@ #include "gc/shared/workerThread.hpp" #include "logging/log.hpp" #include "memory/iterator.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/init.hpp" #include "runtime/java.hpp" #include "runtime/os.hpp" diff --git a/src/hotspot/share/gc/z/vmStructs_z.hpp b/src/hotspot/share/gc/z/vmStructs_z.hpp index a88dae188d3..de32b964a51 100644 --- a/src/hotspot/share/gc/z/vmStructs_z.hpp +++ b/src/hotspot/share/gc/z/vmStructs_z.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -111,7 +111,6 @@ typedef ZValue ZPerNUMAZPartition; \ nonstatic_field(ZForwarding, _virtual, const ZVirtualMemory) \ nonstatic_field(ZForwarding, _object_alignment_shift, const size_t) \ - volatile_nonstatic_field(ZForwarding, _ref_count, int) \ nonstatic_field(ZForwarding, _entries, const ZAttachedArrayForForwarding) \ nonstatic_field(ZForwardingEntry, _entry, uint64_t) \ nonstatic_field(ZAttachedArrayForForwarding, _length, const size_t) diff --git a/src/hotspot/share/gc/z/zAbort.cpp b/src/hotspot/share/gc/z/zAbort.cpp index 3310793f730..82523ddebe8 100644 --- a/src/hotspot/share/gc/z/zAbort.cpp +++ b/src/hotspot/share/gc/z/zAbort.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -22,10 +22,9 @@ */ #include "gc/z/zAbort.hpp" -#include "runtime/atomicAccess.hpp" -volatile bool ZAbort::_should_abort = false; +Atomic ZAbort::_should_abort{}; void ZAbort::abort() { - AtomicAccess::store(&_should_abort, true); + _should_abort.store_relaxed(true); } diff --git a/src/hotspot/share/gc/z/zAbort.hpp b/src/hotspot/share/gc/z/zAbort.hpp index 925b0a79ac3..64633752d5d 100644 --- a/src/hotspot/share/gc/z/zAbort.hpp +++ b/src/hotspot/share/gc/z/zAbort.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -25,10 +25,11 @@ #define SHARE_GC_Z_ZABORT_HPP #include "memory/allStatic.hpp" +#include "runtime/atomic.hpp" class ZAbort : public AllStatic { private: - static volatile bool _should_abort; + static Atomic _should_abort; public: static bool should_abort(); diff --git a/src/hotspot/share/gc/z/zAbort.inline.hpp b/src/hotspot/share/gc/z/zAbort.inline.hpp index 37503e25f70..856179e9d2a 100644 --- a/src/hotspot/share/gc/z/zAbort.inline.hpp +++ b/src/hotspot/share/gc/z/zAbort.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -26,10 +26,8 @@ #include "gc/z/zAbort.hpp" -#include "runtime/atomicAccess.hpp" - inline bool ZAbort::should_abort() { - return AtomicAccess::load(&_should_abort); + return _should_abort.load_relaxed(); } #endif // SHARE_GC_Z_ZABORT_INLINE_HPP diff --git a/src/hotspot/share/gc/z/zArray.hpp b/src/hotspot/share/gc/z/zArray.hpp index 2c2f8a5dbfb..d39def4096e 100644 --- a/src/hotspot/share/gc/z/zArray.hpp +++ b/src/hotspot/share/gc/z/zArray.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -26,7 +26,7 @@ #include "cppstdlib/type_traits.hpp" #include "memory/allocation.hpp" -#include "runtime/atomicAccess.hpp" +#include "runtime/atomic.hpp" #include "runtime/os.hpp" #include "runtime/thread.hpp" #include "utilities/growableArray.hpp" @@ -78,7 +78,9 @@ public: template class ZArrayIteratorImpl : public StackObj { private: - size_t _next; + using NextType = std::conditional_t, size_t>; + + NextType _next; const size_t _end; const T* const _array; diff --git a/src/hotspot/share/gc/z/zArray.inline.hpp b/src/hotspot/share/gc/z/zArray.inline.hpp index 9e2bc19118e..15caa54ebab 100644 --- a/src/hotspot/share/gc/z/zArray.inline.hpp +++ b/src/hotspot/share/gc/z/zArray.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -27,7 +27,6 @@ #include "gc/z/zArray.hpp" #include "gc/z/zLock.inline.hpp" -#include "runtime/atomicAccess.hpp" template ZArraySlice::ZArraySlice(T* data, int len) @@ -130,7 +129,7 @@ inline bool ZArrayIteratorImpl::next_serial(size_t* index) { template inline bool ZArrayIteratorImpl::next_parallel(size_t* index) { - const size_t claimed_index = AtomicAccess::fetch_then_add(&_next, 1u, memory_order_relaxed); + const size_t claimed_index = _next.fetch_then_add(1u, memory_order_relaxed); if (claimed_index < _end) { *index = claimed_index; @@ -177,7 +176,7 @@ inline bool ZArrayIteratorImpl::next_if(T* elem, Function predicate template inline bool ZArrayIteratorImpl::next_index(size_t* index) { - if (Parallel) { + if constexpr (Parallel) { return next_parallel(index); } else { return next_serial(index); diff --git a/src/hotspot/share/gc/z/zForwarding.cpp b/src/hotspot/share/gc/z/zForwarding.cpp index 820bb9dbc35..92fc1bc89df 100644 --- a/src/hotspot/share/gc/z/zForwarding.cpp +++ b/src/hotspot/share/gc/z/zForwarding.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -29,7 +29,6 @@ #include "gc/z/zStat.hpp" #include "gc/z/zUtils.inline.hpp" #include "logging/log.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/align.hpp" // @@ -50,7 +49,7 @@ // bool ZForwarding::claim() { - return AtomicAccess::cmpxchg(&_claimed, false, true) == false; + return _claimed.compare_set(false, true); } void ZForwarding::in_place_relocation_start(zoffset relocated_watermark) { @@ -60,7 +59,7 @@ void ZForwarding::in_place_relocation_start(zoffset relocated_watermark) { // Support for ZHeap::is_in checks of from-space objects // in a page that is in-place relocating - AtomicAccess::store(&_in_place_thread, Thread::current()); + _in_place_thread.store_relaxed(Thread::current()); _in_place_top_at_start = _page->top(); } @@ -76,17 +75,17 @@ void ZForwarding::in_place_relocation_finish() { } // Disable relaxed ZHeap::is_in checks - AtomicAccess::store(&_in_place_thread, (Thread*)nullptr); + _in_place_thread.store_relaxed(nullptr); } bool ZForwarding::in_place_relocation_is_below_top_at_start(zoffset offset) const { // Only the relocating thread is allowed to know about the old relocation top. - return AtomicAccess::load(&_in_place_thread) == Thread::current() && offset < _in_place_top_at_start; + return _in_place_thread.load_relaxed() == Thread::current() && offset < _in_place_top_at_start; } bool ZForwarding::retain_page(ZRelocateQueue* queue) { for (;;) { - const int32_t ref_count = AtomicAccess::load_acquire(&_ref_count); + const int32_t ref_count = _ref_count.load_acquire(); if (ref_count == 0) { // Released @@ -101,7 +100,7 @@ bool ZForwarding::retain_page(ZRelocateQueue* queue) { return false; } - if (AtomicAccess::cmpxchg(&_ref_count, ref_count, ref_count + 1) == ref_count) { + if (_ref_count.compare_set(ref_count, ref_count + 1)) { // Retained return true; } @@ -110,11 +109,11 @@ bool ZForwarding::retain_page(ZRelocateQueue* queue) { void ZForwarding::in_place_relocation_claim_page() { for (;;) { - const int32_t ref_count = AtomicAccess::load(&_ref_count); + const int32_t ref_count = _ref_count.load_relaxed(); assert(ref_count > 0, "Invalid state"); // Invert reference count - if (AtomicAccess::cmpxchg(&_ref_count, ref_count, -ref_count) != ref_count) { + if (!_ref_count.compare_set(ref_count, -ref_count)) { continue; } @@ -122,7 +121,7 @@ void ZForwarding::in_place_relocation_claim_page() { // and we have now claimed the page. Otherwise we wait until it is claimed. if (ref_count != 1) { ZLocker locker(&_ref_lock); - while (AtomicAccess::load_acquire(&_ref_count) != -1) { + while (_ref_count.load_acquire() != -1) { _ref_lock.wait(); } } @@ -134,12 +133,12 @@ void ZForwarding::in_place_relocation_claim_page() { void ZForwarding::release_page() { for (;;) { - const int32_t ref_count = AtomicAccess::load(&_ref_count); + const int32_t ref_count = _ref_count.load_relaxed(); assert(ref_count != 0, "Invalid state"); if (ref_count > 0) { // Decrement reference count - if (AtomicAccess::cmpxchg(&_ref_count, ref_count, ref_count - 1) != ref_count) { + if (!_ref_count.compare_set(ref_count, ref_count - 1)) { continue; } @@ -152,7 +151,7 @@ void ZForwarding::release_page() { } } else { // Increment reference count - if (AtomicAccess::cmpxchg(&_ref_count, ref_count, ref_count + 1) != ref_count) { + if (!_ref_count.compare_set(ref_count, ref_count + 1)) { continue; } @@ -171,9 +170,9 @@ void ZForwarding::release_page() { ZPage* ZForwarding::detach_page() { // Wait until released - if (AtomicAccess::load_acquire(&_ref_count) != 0) { + if (_ref_count.load_acquire() != 0) { ZLocker locker(&_ref_lock); - while (AtomicAccess::load_acquire(&_ref_count) != 0) { + while (_ref_count.load_acquire() != 0) { _ref_lock.wait(); } } @@ -182,16 +181,16 @@ ZPage* ZForwarding::detach_page() { } ZPage* ZForwarding::page() { - assert(AtomicAccess::load(&_ref_count) != 0, "The page has been released/detached"); + assert(_ref_count.load_relaxed() != 0, "The page has been released/detached"); return _page; } void ZForwarding::mark_done() { - AtomicAccess::store(&_done, true); + _done.store_relaxed(true); } bool ZForwarding::is_done() const { - return AtomicAccess::load(&_done); + return _done.load_relaxed(); } // @@ -288,7 +287,7 @@ void ZForwarding::relocated_remembered_fields_publish() { // used to have remembered set entries. Now publish the fields to // the YC. - const ZPublishState res = AtomicAccess::cmpxchg(&_relocated_remembered_fields_state, ZPublishState::none, ZPublishState::published); + const ZPublishState res = _relocated_remembered_fields_state.compare_exchange(ZPublishState::none, ZPublishState::published); // none: OK to publish // published: Not possible - this operation makes this transition @@ -319,7 +318,7 @@ void ZForwarding::relocated_remembered_fields_notify_concurrent_scan_of() { // Invariant: The page is being retained assert(ZGeneration::young()->is_phase_mark(), "Only called when"); - const ZPublishState res = AtomicAccess::cmpxchg(&_relocated_remembered_fields_state, ZPublishState::none, ZPublishState::reject); + const ZPublishState res = _relocated_remembered_fields_state.compare_exchange(ZPublishState::none, ZPublishState::reject); // none: OC has not completed relocation // published: OC has completed and published all relocated remembered fields @@ -340,7 +339,7 @@ void ZForwarding::relocated_remembered_fields_notify_concurrent_scan_of() { // OC relocation already collected and published fields // Still notify concurrent scanning and reject the collected data from the OC - const ZPublishState res2 = AtomicAccess::cmpxchg(&_relocated_remembered_fields_state, ZPublishState::published, ZPublishState::reject); + const ZPublishState res2 = _relocated_remembered_fields_state.compare_exchange(ZPublishState::published, ZPublishState::reject); assert(res2 == ZPublishState::published, "Should not fail"); log_debug(gc, remset)("Forwarding remset eager and reject: " PTR_FORMAT " " PTR_FORMAT, untype(start()), untype(end())); @@ -368,7 +367,7 @@ bool ZForwarding::relocated_remembered_fields_published_contains(volatile zpoint } void ZForwarding::verify() const { - guarantee(_ref_count != 0, "Invalid reference count"); + guarantee(_ref_count.load_relaxed() != 0, "Invalid reference count"); guarantee(_page != nullptr, "Invalid page"); uint32_t live_objects = 0; diff --git a/src/hotspot/share/gc/z/zForwarding.hpp b/src/hotspot/share/gc/z/zForwarding.hpp index 29b5cf4aabe..72319bd2ebb 100644 --- a/src/hotspot/share/gc/z/zForwarding.hpp +++ b/src/hotspot/share/gc/z/zForwarding.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -32,6 +32,7 @@ #include "gc/z/zPageAge.hpp" #include "gc/z/zPageType.hpp" #include "gc/z/zVirtualMemory.hpp" +#include "runtime/atomic.hpp" class ObjectClosure; class ZForwardingAllocator; @@ -62,13 +63,13 @@ private: const uint32_t _partition_id; const ZPageAge _from_age; const ZPageAge _to_age; - volatile bool _claimed; + Atomic _claimed; mutable ZConditionLock _ref_lock; - volatile int32_t _ref_count; - volatile bool _done; + Atomic _ref_count; + Atomic _done; // Relocated remembered set fields support - volatile ZPublishState _relocated_remembered_fields_state; + Atomic _relocated_remembered_fields_state; PointerArray _relocated_remembered_fields_array; uint32_t _relocated_remembered_fields_publish_young_seqnum; @@ -77,7 +78,7 @@ private: zoffset_end _in_place_top_at_start; // Debugging - volatile Thread* _in_place_thread; + Atomic _in_place_thread; ZForwardingEntry* entries() const; ZForwardingEntry at(ZForwardingCursor* cursor) const; diff --git a/src/hotspot/share/gc/z/zForwarding.inline.hpp b/src/hotspot/share/gc/z/zForwarding.inline.hpp index 45b5d495e79..02f61eb5b05 100644 --- a/src/hotspot/share/gc/z/zForwarding.inline.hpp +++ b/src/hotspot/share/gc/z/zForwarding.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -196,7 +196,7 @@ void ZForwarding::oops_do_in_forwarded_via_table(Function function) { } inline bool ZForwarding::in_place_relocation() const { - assert(AtomicAccess::load(&_ref_count) != 0, "The page has been released/detached"); + assert(_ref_count.load_relaxed() != 0, "The page has been released/detached"); return _in_place; } @@ -307,7 +307,7 @@ inline void ZForwarding::relocated_remembered_fields_register(volatile zpointer* // Invariant: Page is being retained assert(ZGeneration::young()->is_phase_mark(), "Only called when"); - const ZPublishState res = AtomicAccess::load(&_relocated_remembered_fields_state); + const ZPublishState res = _relocated_remembered_fields_state.load_relaxed(); // none: Gather remembered fields // published: Have already published fields - not possible since they haven't been @@ -327,7 +327,7 @@ inline void ZForwarding::relocated_remembered_fields_register(volatile zpointer* // Returns true iff the page is being (or about to be) relocated by the OC // while the YC gathered the remembered fields of the "from" page. inline bool ZForwarding::relocated_remembered_fields_is_concurrently_scanned() const { - return AtomicAccess::load(&_relocated_remembered_fields_state) == ZPublishState::reject; + return _relocated_remembered_fields_state.load_relaxed() == ZPublishState::reject; } template @@ -335,7 +335,7 @@ inline void ZForwarding::relocated_remembered_fields_apply_to_published(Function // Invariant: Page is not being retained assert(ZGeneration::young()->is_phase_mark(), "Only called when"); - const ZPublishState res = AtomicAccess::load_acquire(&_relocated_remembered_fields_state); + const ZPublishState res = _relocated_remembered_fields_state.load_acquire(); // none: Nothing published - page had already been relocated before YC started // published: OC relocated and published relocated remembered fields @@ -363,14 +363,14 @@ inline void ZForwarding::relocated_remembered_fields_apply_to_published(Function // collection. Mark that it is unsafe (and unnecessary) to call scan_page // on the page in the page table. assert(res != ZPublishState::accept, "Unexpected"); - AtomicAccess::store(&_relocated_remembered_fields_state, ZPublishState::reject); + _relocated_remembered_fields_state.store_relaxed(ZPublishState::reject); } else { log_debug(gc, remset)("scan_forwarding failed retain safe " PTR_FORMAT, untype(start())); // Guaranteed that the page was fully relocated and removed from page table. // Because of this we can signal to scan_page that any page found in page table // of the same slot as the current forwarding is a page that is safe to scan, // and in fact must be scanned. - AtomicAccess::store(&_relocated_remembered_fields_state, ZPublishState::accept); + _relocated_remembered_fields_state.store_relaxed(ZPublishState::accept); } } diff --git a/src/hotspot/share/gc/z/zForwardingAllocator.cpp b/src/hotspot/share/gc/z/zForwardingAllocator.cpp index 0b4e6c7b08c..451a1d62754 100644 --- a/src/hotspot/share/gc/z/zForwardingAllocator.cpp +++ b/src/hotspot/share/gc/z/zForwardingAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -34,6 +34,7 @@ ZForwardingAllocator::~ZForwardingAllocator() { } void ZForwardingAllocator::reset(size_t size) { - _start = _top = REALLOC_C_HEAP_ARRAY(char, _start, size, mtGC); + _start = REALLOC_C_HEAP_ARRAY(char, _start, size, mtGC); + _top.store_relaxed(_start); _end = _start + size; } diff --git a/src/hotspot/share/gc/z/zForwardingAllocator.hpp b/src/hotspot/share/gc/z/zForwardingAllocator.hpp index 8424fe6cd70..62d84885692 100644 --- a/src/hotspot/share/gc/z/zForwardingAllocator.hpp +++ b/src/hotspot/share/gc/z/zForwardingAllocator.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -24,13 +24,14 @@ #ifndef SHARE_GC_Z_ZFORWARDINGALLOCATOR_HPP #define SHARE_GC_Z_ZFORWARDINGALLOCATOR_HPP +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" class ZForwardingAllocator { private: - char* _start; - char* _end; - char* _top; + char* _start; + char* _end; + Atomic _top; public: ZForwardingAllocator(); diff --git a/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp b/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp index dc71507175c..c8811c84ede 100644 --- a/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp +++ b/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -26,7 +26,6 @@ #include "gc/z/zForwardingAllocator.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/debug.hpp" inline size_t ZForwardingAllocator::size() const { @@ -34,11 +33,11 @@ inline size_t ZForwardingAllocator::size() const { } inline bool ZForwardingAllocator::is_full() const { - return _top == _end; + return _top.load_relaxed() == _end; } inline void* ZForwardingAllocator::alloc(size_t size) { - char* const addr = AtomicAccess::fetch_then_add(&_top, size); + char* const addr = _top.fetch_then_add(size); assert(addr + size <= _end, "Allocation should never fail"); return addr; } diff --git a/src/hotspot/share/gc/z/zGeneration.cpp b/src/hotspot/share/gc/z/zGeneration.cpp index a8c646bf895..27f352a624f 100644 --- a/src/hotspot/share/gc/z/zGeneration.cpp +++ b/src/hotspot/share/gc/z/zGeneration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -56,7 +56,6 @@ #include "logging/log.hpp" #include "memory/universe.hpp" #include "prims/jvmtiTagMap.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/continuation.hpp" #include "runtime/handshake.hpp" #include "runtime/safepoint.hpp" @@ -298,33 +297,33 @@ bool ZGeneration::is_relocate_queue_active() const { void ZGeneration::reset_statistics() { assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint"); - _freed = 0; - _promoted = 0; - _compacted = 0; + _freed.store_relaxed(0u); + _promoted.store_relaxed(0u); + _compacted.store_relaxed(0u); } size_t ZGeneration::freed() const { - return _freed; + return _freed.load_relaxed(); } void ZGeneration::increase_freed(size_t size) { - AtomicAccess::add(&_freed, size, memory_order_relaxed); + _freed.add_then_fetch(size, memory_order_relaxed); } size_t ZGeneration::promoted() const { - return _promoted; + return _promoted.load_relaxed();; } void ZGeneration::increase_promoted(size_t size) { - AtomicAccess::add(&_promoted, size, memory_order_relaxed); + _promoted.add_then_fetch(size, memory_order_relaxed); } size_t ZGeneration::compacted() const { - return _compacted; + return _compacted.load_relaxed();; } void ZGeneration::increase_compacted(size_t size) { - AtomicAccess::add(&_compacted, size, memory_order_relaxed); + _compacted.add_then_fetch(size, memory_order_relaxed); } ConcurrentGCTimer* ZGeneration::gc_timer() const { diff --git a/src/hotspot/share/gc/z/zGeneration.hpp b/src/hotspot/share/gc/z/zGeneration.hpp index 3b700361460..1371865958b 100644 --- a/src/hotspot/share/gc/z/zGeneration.hpp +++ b/src/hotspot/share/gc/z/zGeneration.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -37,6 +37,7 @@ #include "gc/z/zWeakRootsProcessor.hpp" #include "gc/z/zWorkers.hpp" #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" class ThreadClosure; class ZForwardingTable; @@ -70,9 +71,9 @@ protected: ZRelocate _relocate; ZRelocationSet _relocation_set; - volatile size_t _freed; - volatile size_t _promoted; - volatile size_t _compacted; + Atomic _freed; + Atomic _promoted; + Atomic _compacted; Phase _phase; uint32_t _seqnum; diff --git a/src/hotspot/share/gc/z/zJNICritical.cpp b/src/hotspot/share/gc/z/zJNICritical.cpp index 28cc70cb3b5..f50cc113936 100644 --- a/src/hotspot/share/gc/z/zJNICritical.cpp +++ b/src/hotspot/share/gc/z/zJNICritical.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -24,7 +24,6 @@ #include "gc/z/zJNICritical.hpp" #include "gc/z/zLock.inline.hpp" #include "gc/z/zStat.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/interfaceSupport.inline.hpp" #include "runtime/thread.inline.hpp" #include "utilities/debug.hpp" @@ -46,22 +45,22 @@ static const ZStatCriticalPhase ZCriticalPhaseJNICriticalStall("JNI Critical Stall", false /* verbose */); -volatile int64_t ZJNICritical::_count; -ZConditionLock* ZJNICritical::_lock; +Atomic ZJNICritical::_count; +ZConditionLock* ZJNICritical::_lock; void ZJNICritical::initialize() { - _count = 0; + precond(_count.load_relaxed() == 0); _lock = new ZConditionLock(); } void ZJNICritical::block() { for (;;) { - const int64_t count = AtomicAccess::load_acquire(&_count); + const int64_t count = _count.load_acquire(); if (count < 0) { // Already blocked, wait until unblocked ZLocker locker(_lock); - while (AtomicAccess::load_acquire(&_count) < 0) { + while (_count.load_acquire() < 0) { _lock->wait(); } @@ -70,7 +69,7 @@ void ZJNICritical::block() { } // Increment and invert count - if (AtomicAccess::cmpxchg(&_count, count, -(count + 1)) != count) { + if (!_count.compare_set(count, -(count + 1))) { continue; } @@ -80,7 +79,7 @@ void ZJNICritical::block() { if (count != 0) { // Wait until blocked ZLocker locker(_lock); - while (AtomicAccess::load_acquire(&_count) != -1) { + while (_count.load_acquire() != -1) { _lock->wait(); } } @@ -91,18 +90,18 @@ void ZJNICritical::block() { } void ZJNICritical::unblock() { - const int64_t count = AtomicAccess::load_acquire(&_count); + const int64_t count = _count.load_acquire(); assert(count == -1, "Invalid count"); // Notify unblocked ZLocker locker(_lock); - AtomicAccess::release_store(&_count, (int64_t)0); + _count.release_store(0); _lock->notify_all(); } void ZJNICritical::enter_inner(JavaThread* thread) { for (;;) { - const int64_t count = AtomicAccess::load_acquire(&_count); + const int64_t count = _count.load_acquire(); if (count < 0) { // Wait until unblocked @@ -112,7 +111,7 @@ void ZJNICritical::enter_inner(JavaThread* thread) { ThreadBlockInVM tbivm(thread); ZLocker locker(_lock); - while (AtomicAccess::load_acquire(&_count) < 0) { + while (_count.load_acquire() < 0) { _lock->wait(); } @@ -121,7 +120,7 @@ void ZJNICritical::enter_inner(JavaThread* thread) { } // Increment count - if (AtomicAccess::cmpxchg(&_count, count, count + 1) != count) { + if (!_count.compare_set(count, count + 1)) { continue; } @@ -142,17 +141,17 @@ void ZJNICritical::enter(JavaThread* thread) { void ZJNICritical::exit_inner() { for (;;) { - const int64_t count = AtomicAccess::load_acquire(&_count); + const int64_t count = _count.load_acquire(); assert(count != 0, "Invalid count"); if (count > 0) { // No block in progress, decrement count - if (AtomicAccess::cmpxchg(&_count, count, count - 1) != count) { + if (!_count.compare_set(count, count - 1)) { continue; } } else { // Block in progress, increment count - if (AtomicAccess::cmpxchg(&_count, count, count + 1) != count) { + if (!_count.compare_set(count, count + 1)) { continue; } diff --git a/src/hotspot/share/gc/z/zJNICritical.hpp b/src/hotspot/share/gc/z/zJNICritical.hpp index d2ba80eddba..def6001ae9f 100644 --- a/src/hotspot/share/gc/z/zJNICritical.hpp +++ b/src/hotspot/share/gc/z/zJNICritical.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -25,14 +25,15 @@ #define SHARE_GC_Z_ZJNICRITICAL_HPP #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" class JavaThread; class ZConditionLock; class ZJNICritical : public AllStatic { private: - static volatile int64_t _count; - static ZConditionLock* _lock; + static Atomic _count; + static ZConditionLock* _lock; static void enter_inner(JavaThread* thread); static void exit_inner(); diff --git a/src/hotspot/share/gc/z/zLiveMap.cpp b/src/hotspot/share/gc/z/zLiveMap.cpp index c4ae41b0873..8b03a97e03f 100644 --- a/src/hotspot/share/gc/z/zLiveMap.cpp +++ b/src/hotspot/share/gc/z/zLiveMap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -27,7 +27,6 @@ #include "gc/z/zStat.hpp" #include "gc/z/zUtils.hpp" #include "logging/log.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/debug.hpp" #include "utilities/powerOfTwo.hpp" #include "utilities/spinYield.hpp" @@ -60,18 +59,18 @@ void ZLiveMap::reset(ZGenerationId id) { // Multiple threads can enter here, make sure only one of them // resets the marking information while the others busy wait. - for (uint32_t seqnum = AtomicAccess::load_acquire(&_seqnum); + for (uint32_t seqnum = _seqnum.load_acquire(); seqnum != generation->seqnum(); - seqnum = AtomicAccess::load_acquire(&_seqnum)) { + seqnum = _seqnum.load_acquire()) { if (seqnum != seqnum_initializing) { // No one has claimed initialization of the livemap yet - if (AtomicAccess::cmpxchg(&_seqnum, seqnum, seqnum_initializing) == seqnum) { + if (_seqnum.compare_set(seqnum, seqnum_initializing)) { // This thread claimed the initialization // Reset marking information - _live_bytes = 0; - _live_objects = 0; + _live_bytes.store_relaxed(0u); + _live_objects.store_relaxed(0u); // Clear segment claimed/live bits segment_live_bits().clear(); @@ -81,13 +80,13 @@ void ZLiveMap::reset(ZGenerationId id) { // a bit is about to be set for the first time. initialize_bitmap(); - assert(_seqnum == seqnum_initializing, "Invalid"); + assert(_seqnum.load_relaxed() == seqnum_initializing, "Invalid"); // Make sure the newly reset marking information is ordered // before the update of the page seqnum, such that when the // up-to-date seqnum is load acquired, the bit maps will not // contain stale information. - AtomicAccess::release_store(&_seqnum, generation->seqnum()); + _seqnum.release_store(generation->seqnum()); break; } } diff --git a/src/hotspot/share/gc/z/zLiveMap.hpp b/src/hotspot/share/gc/z/zLiveMap.hpp index 71457d05a41..9373f6aad98 100644 --- a/src/hotspot/share/gc/z/zLiveMap.hpp +++ b/src/hotspot/share/gc/z/zLiveMap.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -28,6 +28,7 @@ #include "gc/z/zBitMap.hpp" #include "gc/z/zGenerationId.hpp" #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" class ObjectClosure; @@ -41,9 +42,9 @@ private: const uint32_t _segment_size; const int _segment_shift; - volatile uint32_t _seqnum; - volatile uint32_t _live_objects; - volatile size_t _live_bytes; + Atomic _seqnum; + Atomic _live_objects; + Atomic _live_bytes; BitMap::bm_word_t _segment_live_bits; BitMap::bm_word_t _segment_claim_bits; ZBitMap _bitmap; diff --git a/src/hotspot/share/gc/z/zLiveMap.inline.hpp b/src/hotspot/share/gc/z/zLiveMap.inline.hpp index e6176b928ff..69687d0b595 100644 --- a/src/hotspot/share/gc/z/zLiveMap.inline.hpp +++ b/src/hotspot/share/gc/z/zLiveMap.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -31,24 +31,23 @@ #include "gc/z/zGeneration.inline.hpp" #include "gc/z/zMark.hpp" #include "gc/z/zUtils.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/bitMap.inline.hpp" #include "utilities/debug.hpp" inline void ZLiveMap::reset() { - _seqnum = 0; + _seqnum.store_relaxed(0u); } inline bool ZLiveMap::is_marked(ZGenerationId id) const { - return AtomicAccess::load_acquire(&_seqnum) == ZGeneration::generation(id)->seqnum(); + return _seqnum.load_acquire() == ZGeneration::generation(id)->seqnum(); } inline uint32_t ZLiveMap::live_objects() const { - return _live_objects; + return _live_objects.load_relaxed(); } inline size_t ZLiveMap::live_bytes() const { - return _live_bytes; + return _live_bytes.load_relaxed(); } inline const BitMapView ZLiveMap::segment_live_bits() const { @@ -116,8 +115,8 @@ inline bool ZLiveMap::set(ZGenerationId id, BitMap::idx_t index, bool finalizabl } inline void ZLiveMap::inc_live(uint32_t objects, size_t bytes) { - AtomicAccess::add(&_live_objects, objects); - AtomicAccess::add(&_live_bytes, bytes); + _live_objects.add_then_fetch(objects); + _live_bytes.add_then_fetch(bytes); } inline BitMap::idx_t ZLiveMap::segment_start(BitMap::idx_t segment) const { diff --git a/src/hotspot/share/gc/z/zLock.hpp b/src/hotspot/share/gc/z/zLock.hpp index 640a9fb02d3..a843f2389d7 100644 --- a/src/hotspot/share/gc/z/zLock.hpp +++ b/src/hotspot/share/gc/z/zLock.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -25,6 +25,7 @@ #define SHARE_GC_Z_ZLOCK_HPP #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "runtime/mutex.hpp" class ZLock : public CHeapObj { @@ -39,9 +40,9 @@ public: class ZReentrantLock { private: - ZLock _lock; - Thread* volatile _owner; - uint64_t _count; + ZLock _lock; + Atomic _owner; + uint64_t _count; public: ZReentrantLock(); diff --git a/src/hotspot/share/gc/z/zLock.inline.hpp b/src/hotspot/share/gc/z/zLock.inline.hpp index edf59be5b4c..ba5d6692521 100644 --- a/src/hotspot/share/gc/z/zLock.inline.hpp +++ b/src/hotspot/share/gc/z/zLock.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -26,7 +26,6 @@ #include "gc/z/zLock.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/javaThread.hpp" #include "runtime/os.inline.hpp" #include "utilities/debug.hpp" @@ -50,11 +49,11 @@ inline ZReentrantLock::ZReentrantLock() inline void ZReentrantLock::lock() { Thread* const thread = Thread::current(); - Thread* const owner = AtomicAccess::load(&_owner); + Thread* const owner = _owner.load_relaxed(); if (owner != thread) { _lock.lock(); - AtomicAccess::store(&_owner, thread); + _owner.store_relaxed(thread); } _count++; @@ -67,14 +66,14 @@ inline void ZReentrantLock::unlock() { _count--; if (_count == 0) { - AtomicAccess::store(&_owner, (Thread*)nullptr); + _owner.store_relaxed(nullptr); _lock.unlock(); } } inline bool ZReentrantLock::is_owned() const { Thread* const thread = Thread::current(); - Thread* const owner = AtomicAccess::load(&_owner); + Thread* const owner = _owner.load_relaxed(); return owner == thread; } diff --git a/src/hotspot/share/gc/z/zMark.cpp b/src/hotspot/share/gc/z/zMark.cpp index 3b247fdd35e..03701ae9998 100644 --- a/src/hotspot/share/gc/z/zMark.cpp +++ b/src/hotspot/share/gc/z/zMark.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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,7 +57,6 @@ #include "memory/iterator.inline.hpp" #include "oops/objArrayOop.inline.hpp" #include "oops/oop.inline.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/continuation.hpp" #include "runtime/handshake.hpp" #include "runtime/javaThread.hpp" @@ -152,13 +151,14 @@ void ZMark::prepare_work() { _terminate.reset(_nworkers); // Reset flush counters - _work_nproactiveflush = _work_nterminateflush = 0; + _work_nproactiveflush.store_relaxed(0u); + _work_nterminateflush.store_relaxed(0u); } void ZMark::finish_work() { // Accumulate proactive/terminate flush counters - _nproactiveflush += _work_nproactiveflush; - _nterminateflush += _work_nterminateflush; + _nproactiveflush += _work_nproactiveflush.load_relaxed(); + _nterminateflush += _work_nterminateflush.load_relaxed(); } void ZMark::follow_work_complete() { @@ -594,7 +594,7 @@ bool ZMark::flush() { } bool ZMark::try_terminate_flush() { - AtomicAccess::inc(&_work_nterminateflush); + _work_nterminateflush.add_then_fetch(1u); _terminate.set_resurrected(false); if (ZVerifyMarking) { @@ -610,12 +610,12 @@ bool ZMark::try_proactive_flush() { return false; } - if (AtomicAccess::load(&_work_nproactiveflush) == ZMarkProactiveFlushMax) { + if (_work_nproactiveflush.load_relaxed() == ZMarkProactiveFlushMax) { // Limit reached or we're trying to terminate return false; } - AtomicAccess::inc(&_work_nproactiveflush); + _work_nproactiveflush.add_then_fetch(1u); SuspendibleThreadSetLeaver sts_leaver; return flush(); diff --git a/src/hotspot/share/gc/z/zMark.hpp b/src/hotspot/share/gc/z/zMark.hpp index cc398addeb8..72a527b957d 100644 --- a/src/hotspot/share/gc/z/zMark.hpp +++ b/src/hotspot/share/gc/z/zMark.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -30,6 +30,7 @@ #include "gc/z/zMarkStackEntry.hpp" #include "gc/z/zMarkTerminate.hpp" #include "oops/oopsHierarchy.hpp" +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" class Thread; @@ -60,8 +61,8 @@ private: ZMarkingSMR _marking_smr; ZMarkStripeSet _stripes; ZMarkTerminate _terminate; - volatile size_t _work_nproactiveflush; - volatile size_t _work_nterminateflush; + Atomic _work_nproactiveflush; + Atomic _work_nterminateflush; size_t _nproactiveflush; size_t _nterminateflush; size_t _ntrycomplete; diff --git a/src/hotspot/share/gc/z/zMarkTerminate.hpp b/src/hotspot/share/gc/z/zMarkTerminate.hpp index cff1f8e73fa..9def3e72120 100644 --- a/src/hotspot/share/gc/z/zMarkTerminate.hpp +++ b/src/hotspot/share/gc/z/zMarkTerminate.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -25,6 +25,7 @@ #define SHARE_GC_Z_ZMARKTERMINATE_HPP #include "gc/z/zLock.hpp" +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" class ZMarkStripeSet; @@ -32,9 +33,9 @@ class ZMarkStripeSet; class ZMarkTerminate { private: uint _nworkers; - volatile uint _nworking; - volatile uint _nawakening; - volatile bool _resurrected; + Atomic _nworking; + Atomic _nawakening; + Atomic _resurrected; ZConditionLock _lock; void maybe_reduce_stripes(ZMarkStripeSet* stripes, size_t used_nstripes); diff --git a/src/hotspot/share/gc/z/zMarkTerminate.inline.hpp b/src/hotspot/share/gc/z/zMarkTerminate.inline.hpp index 575044e3a39..84a545623bc 100644 --- a/src/hotspot/share/gc/z/zMarkTerminate.inline.hpp +++ b/src/hotspot/share/gc/z/zMarkTerminate.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -30,7 +30,6 @@ #include "gc/z/zLock.inline.hpp" #include "gc/z/zMarkStack.hpp" #include "logging/log.hpp" -#include "runtime/atomicAccess.hpp" #include "runtime/osThread.hpp" #include "runtime/thread.inline.hpp" @@ -42,24 +41,23 @@ inline ZMarkTerminate::ZMarkTerminate() _lock() {} inline void ZMarkTerminate::reset(uint nworkers) { - AtomicAccess::store(&_nworkers, nworkers); - AtomicAccess::store(&_nworking, nworkers); - _nawakening = 0; + _nworkers = nworkers; + _nworking.store_relaxed(nworkers); + _nawakening.store_relaxed(0u); } inline void ZMarkTerminate::leave() { SuspendibleThreadSetLeaver sts_leaver; ZLocker locker(&_lock); - AtomicAccess::store(&_nworking, _nworking - 1); - if (_nworking == 0) { + if (_nworking.sub_then_fetch(1u, memory_order_relaxed) == 0) { // Last thread leaving; notify waiters _lock.notify_all(); } } inline void ZMarkTerminate::maybe_reduce_stripes(ZMarkStripeSet* stripes, size_t used_nstripes) { - size_t nstripes = stripes->nstripes(); + const size_t nstripes = stripes->nstripes(); if (used_nstripes == nstripes && nstripes > 1u) { stripes->try_set_nstripes(nstripes, nstripes >> 1); } @@ -69,8 +67,7 @@ inline bool ZMarkTerminate::try_terminate(ZMarkStripeSet* stripes, size_t used_n SuspendibleThreadSetLeaver sts_leaver; ZLocker locker(&_lock); - AtomicAccess::store(&_nworking, _nworking - 1); - if (_nworking == 0) { + if (_nworking.sub_then_fetch(1u, memory_order_relaxed) == 0) { // Last thread entering termination: success _lock.notify_all(); return true; @@ -83,24 +80,24 @@ inline bool ZMarkTerminate::try_terminate(ZMarkStripeSet* stripes, size_t used_n // We either got notification about more work // or got a spurious wakeup; don't terminate - if (_nawakening > 0) { - AtomicAccess::store(&_nawakening, _nawakening - 1); + if (_nawakening.load_relaxed() > 0) { + _nawakening.sub_then_fetch(1u, memory_order_relaxed); } - if (_nworking == 0) { + if (_nworking.load_relaxed() == 0) { // We got notified all work is done; terminate return true; } - AtomicAccess::store(&_nworking, _nworking + 1); + _nworking.add_then_fetch(1u, memory_order_relaxed); return false; } inline void ZMarkTerminate::wake_up() { - uint nworking = AtomicAccess::load(&_nworking); - uint nawakening = AtomicAccess::load(&_nawakening); - if (nworking + nawakening == AtomicAccess::load(&_nworkers)) { + const uint nworking = _nworking.load_relaxed(); + const uint nawakening = _nawakening.load_relaxed(); + if (nworking + nawakening == _nworkers) { // Everyone is working or about to return; } @@ -111,24 +108,24 @@ inline void ZMarkTerminate::wake_up() { } ZLocker locker(&_lock); - if (_nworking + _nawakening != _nworkers) { + if (_nworking.load_relaxed() + _nawakening.load_relaxed() != _nworkers) { // Everyone is not working - AtomicAccess::store(&_nawakening, _nawakening + 1); + _nawakening.add_then_fetch(1u, memory_order_relaxed); _lock.notify(); } } inline bool ZMarkTerminate::saturated() const { - uint nworking = AtomicAccess::load(&_nworking); - uint nawakening = AtomicAccess::load(&_nawakening); + const uint nworking = _nworking.load_relaxed(); + const uint nawakening = _nawakening.load_relaxed(); - return nworking + nawakening == AtomicAccess::load(&_nworkers); + return nworking + nawakening == _nworkers; } inline void ZMarkTerminate::set_resurrected(bool value) { // Update resurrected if it changed if (resurrected() != value) { - AtomicAccess::store(&_resurrected, value); + _resurrected.store_relaxed(value); if (value) { log_debug(gc, marking)("Resurrection broke termination"); } else { @@ -138,7 +135,7 @@ inline void ZMarkTerminate::set_resurrected(bool value) { } inline bool ZMarkTerminate::resurrected() const { - return AtomicAccess::load(&_resurrected); + return _resurrected.load_relaxed(); } #endif // SHARE_GC_Z_ZMARKTERMINATE_INLINE_HPP diff --git a/src/hotspot/share/gc/z/zNMethodTableIteration.cpp b/src/hotspot/share/gc/z/zNMethodTableIteration.cpp index bdd4270ddac..423e98dd28b 100644 --- a/src/hotspot/share/gc/z/zNMethodTableIteration.cpp +++ b/src/hotspot/share/gc/z/zNMethodTableIteration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -24,7 +24,6 @@ #include "gc/z/zNMethodTableEntry.hpp" #include "gc/z/zNMethodTableIteration.hpp" #include "memory/iterator.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" @@ -42,11 +41,11 @@ void ZNMethodTableIteration::nmethods_do_begin(ZNMethodTableEntry* table, size_t _table = table; _size = size; - _claimed = 0; + _claimed.store_relaxed(0u); } void ZNMethodTableIteration::nmethods_do_end() { - assert(_claimed >= _size, "Failed to claim all table entries"); + assert(_claimed.load_relaxed() >= _size, "Failed to claim all table entries"); // Finish iteration _table = nullptr; @@ -57,7 +56,7 @@ void ZNMethodTableIteration::nmethods_do(NMethodClosure* cl) { // Claim table partition. Each partition is currently sized to span // two cache lines. This number is just a guess, but seems to work well. const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry); - const size_t partition_start = MIN2(AtomicAccess::fetch_then_add(&_claimed, partition_size), _size); + const size_t partition_start = MIN2(_claimed.fetch_then_add(partition_size), _size); const size_t partition_end = MIN2(partition_start + partition_size, _size); if (partition_start == partition_end) { // End of table diff --git a/src/hotspot/share/gc/z/zNMethodTableIteration.hpp b/src/hotspot/share/gc/z/zNMethodTableIteration.hpp index 064c3eafca0..12dc096491d 100644 --- a/src/hotspot/share/gc/z/zNMethodTableIteration.hpp +++ b/src/hotspot/share/gc/z/zNMethodTableIteration.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, 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 @@ -25,15 +25,16 @@ #define SHARE_GC_Z_ZNMETHODTABLEITERATION_HPP #include "gc/z/zGlobals.hpp" +#include "runtime/atomic.hpp" class NMethodClosure; class ZNMethodTableEntry; class ZNMethodTableIteration { private: - ZNMethodTableEntry* _table; - size_t _size; - ZCACHE_ALIGNED volatile size_t _claimed; + ZNMethodTableEntry* _table; + size_t _size; + ZCACHE_ALIGNED Atomic _claimed; bool in_progress() const; diff --git a/src/hotspot/share/gc/z/zRelocate.cpp b/src/hotspot/share/gc/z/zRelocate.cpp index da07f67d859..d51cf5abbae 100644 --- a/src/hotspot/share/gc/z/zRelocate.cpp +++ b/src/hotspot/share/gc/z/zRelocate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -64,31 +64,31 @@ ZRelocateQueue::ZRelocateQueue() _needs_attention(0) {} bool ZRelocateQueue::needs_attention() const { - return AtomicAccess::load(&_needs_attention) != 0; + return _needs_attention.load_relaxed() != 0; } void ZRelocateQueue::inc_needs_attention() { - const int needs_attention = AtomicAccess::add(&_needs_attention, 1); + const int needs_attention = _needs_attention.add_then_fetch(1); assert(needs_attention == 1 || needs_attention == 2, "Invalid state"); } void ZRelocateQueue::dec_needs_attention() { - const int needs_attention = AtomicAccess::sub(&_needs_attention, 1); + const int needs_attention = _needs_attention.sub_then_fetch(1); assert(needs_attention == 0 || needs_attention == 1, "Invalid state"); } void ZRelocateQueue::activate(uint nworkers) { - _is_active = true; + _is_active.store_relaxed(true); join(nworkers); } void ZRelocateQueue::deactivate() { - AtomicAccess::store(&_is_active, false); + _is_active.store_relaxed(false); clear(); } bool ZRelocateQueue::is_active() const { - return AtomicAccess::load(&_is_active); + return _is_active.load_relaxed(); } void ZRelocateQueue::join(uint nworkers) { @@ -453,7 +453,7 @@ static void retire_target_page(ZGeneration* generation, ZPage* page) { class ZRelocateSmallAllocator { private: ZGeneration* const _generation; - volatile size_t _in_place_count; + Atomic _in_place_count; public: ZRelocateSmallAllocator(ZGeneration* generation) @@ -463,7 +463,7 @@ public: ZPage* alloc_and_retire_target_page(ZForwarding* forwarding, ZPage* target) { ZPage* const page = alloc_page(forwarding); if (page == nullptr) { - AtomicAccess::inc(&_in_place_count); + _in_place_count.add_then_fetch(1u); } if (target != nullptr) { @@ -493,7 +493,7 @@ public: } size_t in_place_count() const { - return _in_place_count; + return _in_place_count.load_relaxed(); } }; @@ -503,7 +503,7 @@ private: ZConditionLock _lock; ZRelocationTargets* _shared_targets; bool _in_place; - volatile size_t _in_place_count; + Atomic _in_place_count; public: ZRelocateMediumAllocator(ZGeneration* generation, ZRelocationTargets* shared_targets) @@ -539,7 +539,7 @@ public: ZPage* const to_page = alloc_page(forwarding); _shared_targets->set(partition_id, to_age, to_page); if (to_page == nullptr) { - AtomicAccess::inc(&_in_place_count); + _in_place_count.add_then_fetch(1u); _in_place = true; } @@ -579,7 +579,7 @@ public: } size_t in_place_count() const { - return _in_place_count; + return _in_place_count.load_relaxed(); } }; diff --git a/src/hotspot/share/gc/z/zRelocate.hpp b/src/hotspot/share/gc/z/zRelocate.hpp index 038efba83eb..d25536e1bce 100644 --- a/src/hotspot/share/gc/z/zRelocate.hpp +++ b/src/hotspot/share/gc/z/zRelocate.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -28,6 +28,7 @@ #include "gc/z/zPageAge.hpp" #include "gc/z/zRelocationSet.hpp" #include "gc/z/zValue.hpp" +#include "runtime/atomic.hpp" class ZForwarding; class ZGeneration; @@ -42,8 +43,8 @@ private: uint _nworkers; uint _nsynchronized; bool _synchronize; - volatile bool _is_active; - volatile int _needs_attention; + Atomic _is_active; + Atomic _needs_attention; bool needs_attention() const; void inc_needs_attention(); diff --git a/src/hotspot/share/gc/z/zTLABUsage.cpp b/src/hotspot/share/gc/z/zTLABUsage.cpp index c2e3db6bedf..d3613cf8632 100644 --- a/src/hotspot/share/gc/z/zTLABUsage.cpp +++ b/src/hotspot/share/gc/z/zTLABUsage.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -23,24 +23,23 @@ #include "gc/z/zTLABUsage.hpp" #include "logging/log.hpp" -#include "runtime/atomicAccess.hpp" ZTLABUsage::ZTLABUsage() : _used(0), _used_history() {} void ZTLABUsage::increase_used(size_t size) { - AtomicAccess::add(&_used, size, memory_order_relaxed); + _used.add_then_fetch(size, memory_order_relaxed); } void ZTLABUsage::decrease_used(size_t size) { - precond(size <= _used); + precond(size <= _used.load_relaxed()); - AtomicAccess::sub(&_used, size, memory_order_relaxed); + _used.sub_then_fetch(size, memory_order_relaxed); } void ZTLABUsage::reset() { - const size_t used = AtomicAccess::xchg(&_used, (size_t) 0); + const size_t used = _used.exchange(0u); // Avoid updates when nothing has been allocated since the last YC if (used == 0) { diff --git a/src/hotspot/share/gc/z/zTLABUsage.hpp b/src/hotspot/share/gc/z/zTLABUsage.hpp index 3d1b084fe16..68c7620c26e 100644 --- a/src/hotspot/share/gc/z/zTLABUsage.hpp +++ b/src/hotspot/share/gc/z/zTLABUsage.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -24,6 +24,7 @@ #ifndef SHARE_GC_Z_ZTLABUSAGE_HPP #define SHARE_GC_Z_ZTLABUSAGE_HPP +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/numberSeq.hpp" @@ -42,9 +43,9 @@ class ZTLABUsage { private: // Accounting TLAB used until the next GC cycle - volatile size_t _used; + Atomic _used; // Sequence of historic used values - TruncatedSeq _used_history; + TruncatedSeq _used_history; public: ZTLABUsage(); diff --git a/src/hotspot/share/interpreter/bytecodeTracer.cpp b/src/hotspot/share/interpreter/bytecodeTracer.cpp index f9980e389e2..69fc93b6c0f 100644 --- a/src/hotspot/share/interpreter/bytecodeTracer.cpp +++ b/src/hotspot/share/interpreter/bytecodeTracer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -192,18 +192,20 @@ void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, } #endif -void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) { +void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags, bool buffered) { BytecodePrinter method_printer(flags); BytecodeStream s(method); s.set_interval(from, to); - // Keep output to st coherent: collect all lines and print at once. ResourceMark rm; stringStream ss; + outputStream* out = buffered ? &ss : st; while (s.next() >= 0) { - method_printer.trace(method, s.bcp(), &ss); + method_printer.trace(method, s.bcp(), out); + } + if (buffered) { + st->print("%s", ss.as_string()); } - st->print("%s", ss.as_string()); } void BytecodePrinter::print_constant(int cp_index, outputStream* st) { diff --git a/src/hotspot/share/interpreter/bytecodeTracer.hpp b/src/hotspot/share/interpreter/bytecodeTracer.hpp index b32e55abbcf..e199a2b7ea2 100644 --- a/src/hotspot/share/interpreter/bytecodeTracer.hpp +++ b/src/hotspot/share/interpreter/bytecodeTracer.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -39,7 +39,7 @@ class BytecodeClosure; class BytecodeTracer: AllStatic { public: NOT_PRODUCT(static void trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st = tty);) - static void print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags); + static void print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags, bool buffered = true); }; #endif // SHARE_INTERPRETER_BYTECODETRACER_HPP diff --git a/src/hotspot/share/memory/allocation.cpp b/src/hotspot/share/memory/allocation.cpp index 9df91225d6f..2a109688ca6 100644 --- a/src/hotspot/share/memory/allocation.cpp +++ b/src/hotspot/share/memory/allocation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -22,6 +22,7 @@ * */ +#include "cds/aotMetaspace.hpp" #include "memory/allocation.inline.hpp" #include "memory/arena.hpp" #include "memory/metaspace.hpp" @@ -161,12 +162,33 @@ void AnyObj::set_allocation_type(address res, allocation_type type) { } } +void AnyObj::set_in_aot_cache() { + _allocation_t[0] = 0; + _allocation_t[1] = 0; +} + +bool AnyObj::in_aot_cache() const { + if (AOTMetaspace::in_aot_cache(this)) { + precond(_allocation_t[0] == 0); + precond(_allocation_t[1] == 0); + return true; + } else { + return false; + } +} + AnyObj::allocation_type AnyObj::get_allocation_type() const { + if (in_aot_cache()) { + return STACK_OR_EMBEDDED; + } assert(~(_allocation_t[0] | allocation_mask) == (uintptr_t)this, "lost resource object"); return (allocation_type)((~_allocation_t[0]) & allocation_mask); } bool AnyObj::is_type_set() const { + if (in_aot_cache()) { + return true; + } allocation_type type = (allocation_type)(_allocation_t[1] & allocation_mask); return get_allocation_type() == type && (_allocation_t[1] - type) == (uintptr_t)(&_allocation_t[1]); diff --git a/src/hotspot/share/memory/allocation.hpp b/src/hotspot/share/memory/allocation.hpp index 963ca04aadf..15b7750a363 100644 --- a/src/hotspot/share/memory/allocation.hpp +++ b/src/hotspot/share/memory/allocation.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -420,6 +420,7 @@ class AnyObj { public: enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 }; static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN; + void set_in_aot_cache() NOT_DEBUG_RETURN; #ifdef ASSERT private: // When this object is allocated on stack the new() operator is not @@ -429,6 +430,7 @@ class AnyObj { uintptr_t _allocation_t[2]; bool is_type_set() const; void initialize_allocation_info(); + bool in_aot_cache() const; public: allocation_type get_allocation_type() const; bool allocated_on_stack_or_embedded() const { return get_allocation_type() == STACK_OR_EMBEDDED; } diff --git a/src/hotspot/share/memory/metaspaceClosure.cpp b/src/hotspot/share/memory/metaspaceClosure.cpp index f3c6e350034..0239eadf692 100644 --- a/src/hotspot/share/memory/metaspaceClosure.cpp +++ b/src/hotspot/share/memory/metaspaceClosure.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -22,7 +22,21 @@ * */ +#include "cds/aotGrowableArray.hpp" +#include "classfile/packageEntry.hpp" #include "memory/metaspaceClosure.hpp" +#include "oops/array.hpp" +#include "oops/instanceKlass.hpp" + +// Sanity checks +static_assert(!HAS_METASPACE_POINTERS_DO(int)); + +static_assert(HAS_METASPACE_POINTERS_DO(Array)); +static_assert(HAS_METASPACE_POINTERS_DO(Array)); +static_assert(HAS_METASPACE_POINTERS_DO(InstanceKlass)); +static_assert(HAS_METASPACE_POINTERS_DO(PackageEntry)); +static_assert(HAS_METASPACE_POINTERS_DO(AOTGrowableArray)); +static_assert(HAS_METASPACE_POINTERS_DO(AOTGrowableArray)); void MetaspaceClosure::push_impl(MetaspaceClosure::Ref* ref) { if (_enclosing_ref != nullptr) { diff --git a/src/hotspot/share/memory/metaspaceClosure.hpp b/src/hotspot/share/memory/metaspaceClosure.hpp index 329502d7a47..b6ba69d6f63 100644 --- a/src/hotspot/share/memory/metaspaceClosure.hpp +++ b/src/hotspot/share/memory/metaspaceClosure.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -25,9 +25,11 @@ #ifndef SHARE_MEMORY_METASPACECLOSURE_HPP #define SHARE_MEMORY_METASPACECLOSURE_HPP +#include "cds/aotGrowableArray.hpp" #include "cppstdlib/type_traits.hpp" #include "logging/log.hpp" #include "memory/allocation.hpp" +#include "memory/metaspaceClosureType.hpp" #include "metaprogramming/enableIf.hpp" #include "oops/array.hpp" #include "utilities/debug.hpp" @@ -36,41 +38,27 @@ #include "utilities/macros.hpp" #include "utilities/resizableHashTable.hpp" -// The metadata hierarchy is separate from the oop hierarchy - class MetaspaceObj; // no C++ vtable -//class Array; // no C++ vtable - class Annotations; // no C++ vtable - class ConstantPoolCache; // no C++ vtable - class ConstMethod; // no C++ vtable - class MethodCounters; // no C++ vtable - class Symbol; // no C++ vtable - class Metadata; // has C++ vtable (so do all subclasses) - class ConstantPool; - class MethodData; - class Method; - class Klass; - class InstanceKlass; - class InstanceMirrorKlass; - class InstanceClassLoaderKlass; - class InstanceRefKlass; - class ArrayKlass; - class ObjArrayKlass; - class TypeArrayKlass; +// This macro just check for the existence of a member with the name "metaspace_pointers_do". If the +// parameter list is not (MetaspaceClosure* it), you will get a compilation error. +#define HAS_METASPACE_POINTERS_DO(T) HasMetaspacePointersDo::value + +template +class HasMetaspacePointersDo { + template static void* test(decltype(&U::metaspace_pointers_do)); + template static int test(...); + using test_type = decltype(test(nullptr)); +public: + static constexpr bool value = std::is_pointer_v; +}; // class MetaspaceClosure -- // -// This class is used for iterating the objects in the HotSpot Metaspaces. It +// This class is used for iterating the class metadata objects. It // provides an API to walk all the reachable objects starting from a set of // root references (such as all Klass'es in the SystemDictionary). // -// Currently it is used for compacting the CDS archive by eliminate temporary -// objects allocated during archive creation time. See ArchiveBuilder for an example. -// -// To support MetaspaceClosure, each subclass of MetaspaceObj must provide -// a method of the type void metaspace_pointers_do(MetaspaceClosure*). This method -// should call MetaspaceClosure::push() on every pointer fields of this -// class that points to a MetaspaceObj. See Annotations::metaspace_pointers_do() -// for an example. +// Currently it is used to copy class metadata into the AOT cache. +// See ArchiveBuilder for an example. class MetaspaceClosure { public: enum Writability { @@ -79,16 +67,32 @@ public: _default }; +#define METASPACE_CLOSURE_TYPE_NAME_CASE(name) case MetaspaceClosureType::name ## Type: return #name; + + static const char* type_name(MetaspaceClosureType type) { + switch(type) { + METASPACE_CLOSURE_TYPES_DO(METASPACE_CLOSURE_TYPE_NAME_CASE) + default: + ShouldNotReachHere(); + return nullptr; + } + } + // class MetaspaceClosure::Ref -- // - // MetaspaceClosure can be viewed as a very simple type of copying garbage - // collector. For it to function properly, it requires each subclass of - // MetaspaceObj to provide two methods: + // For type X to be iterable by MetaspaceClosure, X (or one of X's supertypes) must have + // the following public functions: + // void metaspace_pointers_do(MetaspaceClosure* it); + // static bool is_read_only_by_default() { return true; } // - // size_t size(); -- to determine how much data to copy - // void metaspace_pointers_do(MetaspaceClosure*); -- to locate all the embedded pointers + // In addition, if X is not a subtype of MetaspaceObj, it must have the following function: + // MetaspaceClosureType type() const; + // int size_in_heapwords() const; // - // Calling these methods would be trivial if these two were virtual methods. + // Currently, the iterable types include all subtypes of MetsapceObj, as well + // as GrowableArray, ModuleEntry and PackageEntry. + // + // Calling these functions would be trivial if these were virtual functions. // However, to save space, MetaspaceObj has NO vtable. The vtable is introduced // only in the Metadata class. // @@ -97,7 +101,7 @@ public: // so that we can statically discover the type of a object. The use of Ref // depends on the fact that: // - // [1] We don't use polymorphic pointers for MetaspaceObj's that are not subclasses + // [1] We don't use polymorphic pointers to MetaspaceObj's that are not subclasses // of Metadata. I.e., we don't do this: // class Klass { // MetaspaceObj *_obj; @@ -130,8 +134,7 @@ public: virtual bool not_null() const = 0; virtual int size() const = 0; virtual void metaspace_pointers_do(MetaspaceClosure *it) const = 0; - virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const = 0; - virtual MetaspaceObj::Type msotype() const = 0; + virtual MetaspaceClosureType type() const = 0; virtual bool is_read_only_by_default() const = 0; virtual ~Ref() {} @@ -180,7 +183,26 @@ public: } private: - // MSORef -- iterate an instance of MetaspaceObj + template ::value)> + static int get_size(T* obj) { + return obj->size(); + } + + template ::value)> + static int get_size(T* obj) { + return obj->size_in_heapwords(); + } + + static MetaspaceClosureType as_type(MetaspaceClosureType t) { + return t; + } + + static MetaspaceClosureType as_type(MetaspaceObj::Type msotype) { + precond(msotype < MetaspaceObj::_number_of_types); + return (MetaspaceClosureType)msotype; + } + + // MSORef -- iterate an instance of T, where T::metaspace_pointers_do() exists. template class MSORef : public Ref { T** _mpp; T* dereference() const { @@ -196,18 +218,20 @@ private: virtual bool is_read_only_by_default() const { return T::is_read_only_by_default(); } virtual bool not_null() const { return dereference() != nullptr; } - virtual int size() const { return dereference()->size(); } - virtual MetaspaceObj::Type msotype() const { return dereference()->type(); } + virtual int size() const { return get_size(dereference()); } + virtual MetaspaceClosureType type() const { return as_type(dereference()->type()); } virtual void metaspace_pointers_do(MetaspaceClosure *it) const { dereference()->metaspace_pointers_do(it); } - virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const { - ((T*)new_loc)->metaspace_pointers_do(it); - } }; - // abstract base class for MSOArrayRef, MSOPointerArrayRef and OtherArrayRef + //--------------------- + // Support for Array + //--------------------- + + // Abstract base class for MSOArrayRef, MSOPointerArrayRef and OtherArrayRef. + // These are used for iterating Array. template class ArrayRef : public Ref { Array** _mpp; protected: @@ -224,10 +248,10 @@ private: virtual bool is_read_only_by_default() const { return true; } virtual bool not_null() const { return dereference() != nullptr; } virtual int size() const { return dereference()->size(); } - virtual MetaspaceObj::Type msotype() const { return MetaspaceObj::array_type(sizeof(T)); } + virtual MetaspaceClosureType type() const { return as_type(MetaspaceObj::array_type(sizeof(T))); } }; - // OtherArrayRef -- iterate an instance of Array, where T is NOT a subtype of MetaspaceObj. + // OtherArrayRef -- iterate an instance of Array, where T does NOT have metaspace_pointer_do(). // T can be a primitive type, such as int, or a structure. However, we do not scan // the fields inside T, so you should not embed any pointers inside T. template class OtherArrayRef : public ArrayRef { @@ -238,13 +262,9 @@ private: Array* array = ArrayRef::dereference(); log_trace(aot)("Iter(OtherArray): %p [%d]", array, array->length()); } - virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const { - Array* array = (Array*)new_loc; - log_trace(aot)("Iter(OtherArray): %p [%d]", array, array->length()); - } }; - // MSOArrayRef -- iterate an instance of Array, where T is a subtype of MetaspaceObj. + // MSOArrayRef -- iterate an instance of Array, where T has metaspace_pointer_do(). // We recursively call T::metaspace_pointers_do() for each element in this array. template class MSOArrayRef : public ArrayRef { public: @@ -253,9 +273,6 @@ private: virtual void metaspace_pointers_do(MetaspaceClosure *it) const { metaspace_pointers_do_at_impl(it, ArrayRef::dereference()); } - virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const { - metaspace_pointers_do_at_impl(it, (Array*)new_loc); - } private: void metaspace_pointers_do_at_impl(MetaspaceClosure *it, Array* array) const { log_trace(aot)("Iter(MSOArray): %p [%d]", array, array->length()); @@ -266,7 +283,7 @@ private: } }; - // MSOPointerArrayRef -- iterate an instance of Array, where T is a subtype of MetaspaceObj. + // MSOPointerArrayRef -- iterate an instance of Array, where T has metaspace_pointer_do(). // We recursively call MetaspaceClosure::push() for each pointer in this array. template class MSOPointerArrayRef : public ArrayRef { public: @@ -275,9 +292,6 @@ private: virtual void metaspace_pointers_do(MetaspaceClosure *it) const { metaspace_pointers_do_at_impl(it, ArrayRef::dereference()); } - virtual void metaspace_pointers_do_at(MetaspaceClosure *it, address new_loc) const { - metaspace_pointers_do_at_impl(it, (Array*)new_loc); - } private: void metaspace_pointers_do_at_impl(MetaspaceClosure *it, Array* array) const { log_trace(aot)("Iter(MSOPointerArray): %p [%d]", array, array->length()); @@ -288,6 +302,102 @@ private: } }; + //-------------------------------- + // Support for AOTGrowableArray + //-------------------------------- + + // Abstract base class for MSOCArrayRef, MSOPointerCArrayRef and OtherCArrayRef. + // These are used for iterating the buffer held by AOTGrowableArray. + template class CArrayRef : public Ref { + T** _mpp; + int _num_elems; // Number of elements + + int byte_size() const { + return _num_elems * sizeof(T); + } + + protected: + // C pointer arrays don't support tagged pointers. + T* dereference() const { + return *_mpp; + } + virtual void** mpp() const { + return (void**)_mpp; + } + int num_elems() const { + return _num_elems; + } + public: + CArrayRef(T** mpp, int num_elems, Writability w) + : Ref(w), _mpp(mpp), _num_elems(num_elems) { + assert(is_aligned(byte_size(), BytesPerWord), "must be"); + } + + virtual bool is_read_only_by_default() const { return false; } + virtual bool not_null() const { return dereference() != nullptr; } + virtual int size() const { return (int)heap_word_size(byte_size()); } + virtual MetaspaceClosureType type() const { return MetaspaceClosureType::CArrayType; } + }; + + // OtherCArrayRef -- iterate a C array of type T, where T does NOT have metaspace_pointer_do(). + // T can be a primitive type, such as int, or a structure. However, we do not scan + // the fields inside T, so you should not embed any pointers inside T. + template class OtherCArrayRef : public CArrayRef { + public: + OtherCArrayRef(T** mpp, int num_elems, Writability w) : CArrayRef(mpp, num_elems, w) {} + + virtual void metaspace_pointers_do(MetaspaceClosure *it) const { + T* array = CArrayRef::dereference(); + log_trace(aot)("Iter(OtherCArray): %p [%d]", array, CArrayRef::num_elems()); + } + }; + + // MSOCArrayRef -- iterate a C array of type T, where T has metaspace_pointer_do(). + // We recursively call T::metaspace_pointers_do() for each element in this array. + // This is for supporting AOTGrowableArray. + // + // E.g., PackageEntry* _pkg_entry_pointers[2]; // a buffer that has 2 PackageEntry objects + // ... + // it->push(&_pkg_entry_pointers, 2); + // /* calls _pkg_entry_pointers[0].metaspace_pointers_do(it); */ + // /* calls _pkg_entry_pointers[1].metaspace_pointers_do(it); */ + template class MSOCArrayRef : public CArrayRef { + public: + MSOCArrayRef(T** mpp, int num_elems, Writability w) : CArrayRef(mpp, num_elems, w) {} + + virtual void metaspace_pointers_do(MetaspaceClosure *it) const { + T* array = CArrayRef::dereference(); + log_trace(aot)("Iter(MSOCArray): %p [%d]", array, CArrayRef::num_elems()); + for (int i = 0; i < CArrayRef::num_elems(); i++) { + T* elm = array + i; + elm->metaspace_pointers_do(it); + } + } + }; + + // MSOPointerCArrayRef -- iterate a C array of type T*, where T has metaspace_pointer_do(). + // We recursively call MetaspaceClosure::push() for each pointer in this array. + // This is for supporting AOTGrowableArray. + // + // E.g., PackageEntry** _pkg_entry_pointers[2]; // a buffer that has 2 PackageEntry pointers + // ... + // it->push(&_pkg_entry_pointers, 2); + // /* calls _pkg_entry_pointers[0]->metaspace_pointers_do(it); */ + // /* calls _pkg_entry_pointers[1]->metaspace_pointers_do(it); */ + template class MSOPointerCArrayRef : public CArrayRef { + public: + MSOPointerCArrayRef(T*** mpp, int num_elems, Writability w) : CArrayRef(mpp, num_elems, w) {} + + virtual void metaspace_pointers_do(MetaspaceClosure *it) const { + T** array = CArrayRef::dereference(); + log_trace(aot)("Iter(MSOPointerCArray): %p [%d]", array, CArrayRef::num_elems()); + for (int i = 0; i < CArrayRef::num_elems(); i++) { + T** mpp = array + i; + it->push(mpp); + } + } + }; + // Normally, chains of references like a->b->c->d are iterated recursively. However, // if recursion is too deep, we save the Refs in _pending_refs, and push them later in // MetaspaceClosure::finish(). This avoids overflowing the C stack. @@ -330,37 +440,61 @@ public: // Array*>* a4 = ...; it->push(&a4); => MSOPointerArrayRef // Array* a5 = ...; it->push(&a5); => MSOPointerArrayRef // - // Note that the following will fail to compile (to prevent you from adding new fields - // into the MetaspaceObj subtypes that cannot be properly copied by CDS): + // AOTGrowableArrays have a separate "C array" buffer, so they are scanned in two steps: // - // MemoryPool* p = ...; it->push(&p); => MemoryPool is not a subclass of MetaspaceObj - // Array* a6 = ...; it->push(&a6); => MemoryPool is not a subclass of MetaspaceObj - // Array* a7 = ...; it->push(&a7); => int is not a subclass of MetaspaceObj + // AOTGrowableArray* ga1 = ...; it->push(&ga1); => MSORef => OtherCArrayRef + // AOTGrowableArray* ga2 = ...; it->push(&ga2); => MSORef => MSOCArrayRef + // AOTGrowableArray* ga3 = ...; it->push(&ga3); => MSORef => MSOPointerCArrayRef + // + // Note that the following will fail to compile: + // + // MemoryPool* p = ...; it->push(&p); => MemoryPool doesn't have metaspace_pointers_do + // Array* a6 = ...; it->push(&a6); => MemoryPool doesn't have metaspace_pointers_do + // Array* a7 = ...; it->push(&a7); => int doesn't have metaspace_pointers_do + // --- Regular iterable objects template void push(T** mpp, Writability w = _default) { - static_assert(std::is_base_of::value, "Do not push pointers of arbitrary types"); + static_assert(HAS_METASPACE_POINTERS_DO(T), "Do not push pointers of arbitrary types"); push_with_ref>(mpp, w); } - template ::value)> + // --- Array + template void push(Array** mpp, Writability w = _default) { push_with_ref>(mpp, w); } - template ::value)> + template void push(Array** mpp, Writability w = _default) { push_with_ref>(mpp, w); } template void push(Array** mpp, Writability w = _default) { - static_assert(std::is_base_of::value, "Do not push Arrays of arbitrary pointer types"); + static_assert(HAS_METASPACE_POINTERS_DO(T), "Do not push Arrays of arbitrary pointer types"); push_with_ref>(mpp, w); } + + // --- The buffer of AOTGrowableArray + template + void push_c_array(T** mpp, int num_elems, Writability w = _default) { + push_impl(new OtherCArrayRef(mpp, num_elems, w)); + } + + template + void push_c_array(T** mpp, int num_elems, Writability w = _default) { + push_impl(new MSOCArrayRef(mpp, num_elems, w)); + } + + template + void push_c_array(T*** mpp, int num_elems, Writability w = _default) { + static_assert(HAS_METASPACE_POINTERS_DO(T), "Do not push C arrays of arbitrary pointer types"); + push_impl(new MSOPointerCArrayRef(mpp, num_elems, w)); + } }; -// This is a special MetaspaceClosure that visits each unique MetaspaceObj once. +// This is a special MetaspaceClosure that visits each unique object once. class UniqueMetaspaceClosure : public MetaspaceClosure { static const int INITIAL_TABLE_SIZE = 15889; static const int MAX_TABLE_SIZE = 1000000; diff --git a/src/hotspot/share/memory/metaspaceClosureType.hpp b/src/hotspot/share/memory/metaspaceClosureType.hpp new file mode 100644 index 00000000000..adf6805521b --- /dev/null +++ b/src/hotspot/share/memory/metaspaceClosureType.hpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2026, 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_MEMORY_METASPACECLOSURETYPE_HPP +#define SHARE_MEMORY_METASPACECLOSURETYPE_HPP + +#include "memory/allocation.hpp" + +// MetaspaceClosure is able to iterate on MetaspaceObjs, plus the following classes +#define METASPACE_CLOSURE_TYPES_DO(f) \ + METASPACE_OBJ_TYPES_DO(f) \ + f(CArray) \ + f(GrowableArray) \ + f(ModuleEntry) \ + f(PackageEntry) \ + +#define METASPACE_CLOSURE_TYPE_DECLARE(name) name ## Type, + +enum class MetaspaceClosureType : int { + METASPACE_CLOSURE_TYPES_DO(METASPACE_CLOSURE_TYPE_DECLARE) + _number_of_types +}; + + +#endif // SHARE_MEMORY_METASPACECLOSURETYPE_HPP diff --git a/src/hotspot/share/oops/array.hpp b/src/hotspot/share/oops/array.hpp index 90dcc9dfeaf..82067e007ea 100644 --- a/src/hotspot/share/oops/array.hpp +++ b/src/hotspot/share/oops/array.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2026, 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 @@ -33,6 +33,8 @@ // Array for metadata allocation +class MetaspaceClosure; + template class Array: public MetaspaceObj { friend class ArchiveBuilder; @@ -157,6 +159,9 @@ protected: st->print("Array(" PTR_FORMAT ")", p2i(this)); } + // This function does nothing. The iteration of the elements are done inside metaspaceClosure.hpp + void metaspace_pointers_do(MetaspaceClosure* it) {} + #ifndef PRODUCT void print(outputStream* st) { for (int i = 0; i< _length; i++) { diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index 56a80daed60..1963327fc78 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -2693,6 +2693,10 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) { it->push(&_nest_members); it->push(&_permitted_subclasses); it->push(&_record_components); + + if (CDSConfig::is_dumping_full_module_graph() && !defined_by_other_loaders()) { + it->push(&_package_entry); + } } #if INCLUDE_CDS @@ -2791,24 +2795,9 @@ void InstanceKlass::remove_java_mirror() { void InstanceKlass::init_shared_package_entry() { assert(CDSConfig::is_dumping_archive(), "must be"); -#if !INCLUDE_CDS_JAVA_HEAP - _package_entry = nullptr; -#else - if (CDSConfig::is_dumping_full_module_graph()) { - if (defined_by_other_loaders()) { - _package_entry = nullptr; - } else { - _package_entry = PackageEntry::get_archived_entry(_package_entry); - } - } else if (CDSConfig::is_dumping_dynamic_archive() && - CDSConfig::is_using_full_module_graph() && - AOTMetaspace::in_aot_cache(_package_entry)) { - // _package_entry is an archived package in the base archive. Leave it as is. - } else { + if (!CDSConfig::is_dumping_full_module_graph() || defined_by_other_loaders()) { _package_entry = nullptr; } - ArchivePtrMarker::mark_pointer((address**)&_package_entry); -#endif } void InstanceKlass::compute_has_loops_flag_for_methods() { diff --git a/src/hotspot/share/oops/instanceKlass.hpp b/src/hotspot/share/oops/instanceKlass.hpp index 23a59d26093..e370a3b7a7c 100644 --- a/src/hotspot/share/oops/instanceKlass.hpp +++ b/src/hotspot/share/oops/instanceKlass.hpp @@ -353,6 +353,9 @@ class InstanceKlass: public Klass { int static_oop_field_count() const { return (int)_static_oop_field_count; } void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; } + bool trust_final_fields() { return _misc_flags.trust_final_fields(); } + void set_trust_final_fields(bool value) { _misc_flags.set_trust_final_fields(value); } + // Java itable int itable_length() const { return _itable_len; } void set_itable_length(int len) { _itable_len = len; } diff --git a/src/hotspot/share/oops/instanceKlassFlags.hpp b/src/hotspot/share/oops/instanceKlassFlags.hpp index 5eebaab27d1..d576805b30f 100644 --- a/src/hotspot/share/oops/instanceKlassFlags.hpp +++ b/src/hotspot/share/oops/instanceKlassFlags.hpp @@ -54,6 +54,7 @@ class InstanceKlassFlags { flag(has_localvariable_table , 1 << 11) /* has localvariable information */ \ flag(has_miranda_methods , 1 << 12) /* True if this class has miranda methods in it's vtable */ \ flag(has_final_method , 1 << 13) /* True if klass has final method */ \ + flag(trust_final_fields , 1 << 14) /* All instance final fields in this class should be trusted */ \ /* end of list */ #define IK_FLAGS_ENUM_NAME(name, value) _misc_##name = value, diff --git a/src/hotspot/share/oops/klass.hpp b/src/hotspot/share/oops/klass.hpp index b6974762209..d59db9744cb 100644 --- a/src/hotspot/share/oops/klass.hpp +++ b/src/hotspot/share/oops/klass.hpp @@ -510,18 +510,20 @@ protected: return (BasicType) btvalue; } - // Want a pattern to quickly diff against layout header in register - // find something less clever! + // Return a value containing a single set bit that is in the bitset difference between the + // layout helpers for array-of-boolean and array-of-byte. static int layout_helper_boolean_diffbit() { - jint zlh = array_layout_helper(T_BOOLEAN); - jint blh = array_layout_helper(T_BYTE); - assert(zlh != blh, "array layout helpers must differ"); - int diffbit = 1; - while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) { - diffbit <<= 1; - assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE"); - } - return diffbit; + uint zlh = static_cast(array_layout_helper(T_BOOLEAN)); + uint blh = static_cast(array_layout_helper(T_BYTE)); + // get all the bits that are set in zlh and clear in blh + uint candidates = (zlh & ~blh); + assert(candidates != 0, "must be"); // must be some if there is a solution. + // Use well known bit hack to isolate the low bit of candidates. + uint result = candidates & (-candidates); + assert(is_power_of_2(result), "must be power of 2"); + assert((result & zlh) != 0, "must be set in alh of T_BOOLEAN"); + assert((result & blh) == 0, "must be clear in alh of T_BYTE"); + return static_cast(result); } static int layout_helper_log2_element_size(jint lh) { diff --git a/src/hotspot/share/oops/method.cpp b/src/hotspot/share/oops/method.cpp index 1a2e5f0bee4..949441585d8 100644 --- a/src/hotspot/share/oops/method.cpp +++ b/src/hotspot/share/oops/method.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -1898,15 +1898,15 @@ void Method::print_name(outputStream* st) const { #endif // !PRODUCT || INCLUDE_JVMTI -void Method::print_codes_on(outputStream* st, int flags) const { - print_codes_on(0, code_size(), st, flags); +void Method::print_codes_on(outputStream* st, int flags, bool buffered) const { + print_codes_on(0, code_size(), st, flags, buffered); } -void Method::print_codes_on(int from, int to, outputStream* st, int flags) const { +void Method::print_codes_on(int from, int to, outputStream* st, int flags, bool buffered) const { Thread *thread = Thread::current(); ResourceMark rm(thread); methodHandle mh (thread, (Method*)this); - BytecodeTracer::print_method_codes(mh, from, to, st, flags); + BytecodeTracer::print_method_codes(mh, from, to, st, flags, buffered); } CompressedLineNumberReadStream::CompressedLineNumberReadStream(u_char* buffer) : CompressedReadStream(buffer) { diff --git a/src/hotspot/share/oops/method.hpp b/src/hotspot/share/oops/method.hpp index 4592cb8a8c0..add8e59b2be 100644 --- a/src/hotspot/share/oops/method.hpp +++ b/src/hotspot/share/oops/method.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -466,8 +466,8 @@ public: // prints byte codes void print_codes(int flags = 0) const { print_codes_on(tty, flags); } - void print_codes_on(outputStream* st, int flags = 0) const; - void print_codes_on(int from, int to, outputStream* st, int flags = 0) const; + void print_codes_on(outputStream* st, int flags = 0, bool buffered = true) const; + void print_codes_on(int from, int to, outputStream* st, int flags = 0, bool buffered = true) const; // method parameters bool has_method_parameters() const diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index cea2b09e142..7d99f4a7336 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -581,7 +581,7 @@ void Compile::print_phase(const char* phase_name) { tty->print_cr("%u.\t%s", ++_phase_counter, phase_name); } -void Compile::print_ideal_ir(const char* phase_name) { +void Compile::print_ideal_ir(const char* compile_phase_name) const { // keep the following output all in one block // This output goes directly to the tty, not the compiler log. // To enable tools to match it up with the compilation activity, @@ -593,7 +593,7 @@ void Compile::print_ideal_ir(const char* phase_name) { stringStream ss; if (_output == nullptr) { - ss.print_cr("AFTER: %s", phase_name); + ss.print_cr("AFTER: %s", compile_phase_name); // Print out all nodes in ascending order of index. // It is important that we traverse both inputs and outputs of nodes, // so that we reach all nodes that are connected to Root. @@ -610,7 +610,7 @@ void Compile::print_ideal_ir(const char* phase_name) { xtty->head("ideal compile_id='%d'%s compile_phase='%s'", compile_id(), is_osr_compilation() ? " compile_kind='osr'" : "", - phase_name); + compile_phase_name); } tty->print("%s", ss.as_string()); @@ -671,7 +671,7 @@ Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci, _coarsened_locks(comp_arena(), 8, 0, nullptr), _congraph(nullptr), NOT_PRODUCT(_igv_printer(nullptr) COMMA) - _unique(0), + _unique(0), _dead_node_count(0), _dead_node_list(comp_arena()), _node_arena_one(mtCompiler, Arena::Tag::tag_node), @@ -865,7 +865,7 @@ Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci, #ifndef PRODUCT if (should_print_ideal()) { - print_ideal_ir("print_ideal"); + print_ideal_ir("PrintIdeal"); } #endif @@ -938,7 +938,7 @@ Compile::Compile(ciEnv* ci_env, _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr), _congraph(nullptr), NOT_PRODUCT(_igv_printer(nullptr) COMMA) - _unique(0), + _unique(0), _dead_node_count(0), _dead_node_list(comp_arena()), _node_arena_one(mtCompiler, Arena::Tag::tag_node), @@ -5165,17 +5165,17 @@ void Compile::sort_macro_nodes() { } } -void Compile::print_method(CompilerPhaseType cpt, int level, Node* n) { +void Compile::print_method(CompilerPhaseType compile_phase, int level, Node* n) { if (failing_internal()) { return; } // failing_internal to not stress bailouts from printing code. EventCompilerPhase event(UNTIMED); if (event.should_commit()) { - CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, cpt, C->_compile_id, level); + CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, compile_phase, C->_compile_id, level); } #ifndef PRODUCT ResourceMark rm; stringStream ss; - ss.print_raw(CompilerPhaseTypeHelper::to_description(cpt)); - int iter = ++_igv_phase_iter[cpt]; + ss.print_raw(CompilerPhaseTypeHelper::to_description(compile_phase)); + int iter = ++_igv_phase_iter[compile_phase]; if (iter > 1) { ss.print(" %d", iter); } @@ -5203,8 +5203,8 @@ void Compile::print_method(CompilerPhaseType cpt, int level, Node* n) { if (should_print_phase(level)) { print_phase(name); } - if (should_print_ideal_phase(cpt)) { - print_ideal_ir(CompilerPhaseTypeHelper::to_name(cpt)); + if (should_print_ideal_phase(compile_phase)) { + print_ideal_ir(CompilerPhaseTypeHelper::to_name(compile_phase)); } #endif C->_latest_stage_start_counter.stamp(); diff --git a/src/hotspot/share/opto/compile.hpp b/src/hotspot/share/opto/compile.hpp index 45a3a4f548f..12812424f5e 100644 --- a/src/hotspot/share/opto/compile.hpp +++ b/src/hotspot/share/opto/compile.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -666,7 +666,7 @@ public: uint next_igv_idx() { return _igv_idx++; } bool trace_opto_output() const { return _trace_opto_output; } void print_phase(const char* phase_name); - void print_ideal_ir(const char* phase_name); + void print_ideal_ir(const char* compile_phase_name) const; bool should_print_ideal() const { return _directive->PrintIdealOption; } bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; } void set_parsed_irreducible_loop(bool z) { _parsed_irreducible_loop = z; } @@ -680,7 +680,7 @@ public: void begin_method(); void end_method(); - void print_method(CompilerPhaseType cpt, int level, Node* n = nullptr); + void print_method(CompilerPhaseType compile_phase, int level, Node* n = nullptr); #ifndef PRODUCT bool should_print_igv(int level); diff --git a/src/hotspot/share/opto/subnode.cpp b/src/hotspot/share/opto/subnode.cpp index a10cd2a8d5b..548df58eb35 100644 --- a/src/hotspot/share/opto/subnode.cpp +++ b/src/hotspot/share/opto/subnode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -745,71 +745,40 @@ const Type* CmpINode::Value(PhaseGVN* phase) const { // Simplify a CmpU (compare 2 integers) node, based on local information. // If both inputs are constants, compare them. -const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { - assert(!t1->isa_ptr(), "obsolete usage of CmpU"); +const Type* CmpUNode::sub(const Type* t1, const Type* t2) const { + const TypeInt* r0 = t1->is_int(); + const TypeInt* r1 = t2->is_int(); - // comparing two unsigned ints - const TypeInt *r0 = t1->is_int(); // Handy access - const TypeInt *r1 = t2->is_int(); - - // Current installed version - // Compare ranges for non-overlap - juint lo0 = r0->_lo; - juint hi0 = r0->_hi; - juint lo1 = r1->_lo; - juint hi1 = r1->_hi; - - // If either one has both negative and positive values, - // it therefore contains both 0 and -1, and since [0..-1] is the - // full unsigned range, the type must act as an unsigned bottom. - bool bot0 = ((jint)(lo0 ^ hi0) < 0); - bool bot1 = ((jint)(lo1 ^ hi1) < 0); - - if (bot0 || bot1) { - // All unsigned values are LE -1 and GE 0. - if (lo0 == 0 && hi0 == 0) { - return TypeInt::CC_LE; // 0 <= bot - } else if ((jint)lo0 == -1 && (jint)hi0 == -1) { - return TypeInt::CC_GE; // -1 >= bot - } else if (lo1 == 0 && hi1 == 0) { - return TypeInt::CC_GE; // bot >= 0 - } else if ((jint)lo1 == -1 && (jint)hi1 == -1) { - return TypeInt::CC_LE; // bot <= -1 - } - } else { - // We can use ranges of the form [lo..hi] if signs are the same. - assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); - // results are reversed, '-' > '+' for unsigned compare - if (hi0 < lo1) { - return TypeInt::CC_LT; // smaller - } else if (lo0 > hi1) { - return TypeInt::CC_GT; // greater - } else if (hi0 == lo1 && lo0 == hi1) { - return TypeInt::CC_EQ; // Equal results - } else if (lo0 >= hi1) { - return TypeInt::CC_GE; - } else if (hi0 <= lo1) { - // Check for special case in Hashtable::get. (See below.) - if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) - return TypeInt::CC_LT; - return TypeInt::CC_LE; - } - } // Check for special case in Hashtable::get - the hash index is // mod'ed to the table size so the following range check is useless. // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have // to be positive. // (This is a gross hack, since the sub method never // looks at the structure of the node in any other case.) - if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) + if (r0->_lo >= 0 && r1->_lo >= 0 && is_index_range_check()) { return TypeInt::CC_LT; + } + + if (r0->_uhi < r1->_ulo) { + return TypeInt::CC_LT; + } else if (r0->_ulo > r1->_uhi) { + return TypeInt::CC_GT; + } else if (r0->is_con() && r1->is_con()) { + // Since r0->_ulo == r0->_uhi == r0->get_con(), we only reach here if the constants are equal + assert(r0->get_con() == r1->get_con(), "must reach a previous branch otherwise"); + return TypeInt::CC_EQ; + } else if (r0->_uhi == r1->_ulo) { + return TypeInt::CC_LE; + } else if (r0->_ulo == r1->_uhi) { + return TypeInt::CC_GE; + } const Type* joined = r0->join(r1); if (joined == Type::TOP) { return TypeInt::CC_NE; } - return TypeInt::CC; // else use worst case results + return TypeInt::CC; } const Type* CmpUNode::Value(PhaseGVN* phase) const { @@ -963,51 +932,21 @@ const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { // Simplify a CmpUL (compare 2 unsigned longs) node, based on local information. // If both inputs are constants, compare them. const Type* CmpULNode::sub(const Type* t1, const Type* t2) const { - assert(!t1->isa_ptr(), "obsolete usage of CmpUL"); - - // comparing two unsigned longs - const TypeLong* r0 = t1->is_long(); // Handy access + const TypeLong* r0 = t1->is_long(); const TypeLong* r1 = t2->is_long(); - // Current installed version - // Compare ranges for non-overlap - julong lo0 = r0->_lo; - julong hi0 = r0->_hi; - julong lo1 = r1->_lo; - julong hi1 = r1->_hi; - - // If either one has both negative and positive values, - // it therefore contains both 0 and -1, and since [0..-1] is the - // full unsigned range, the type must act as an unsigned bottom. - bool bot0 = ((jlong)(lo0 ^ hi0) < 0); - bool bot1 = ((jlong)(lo1 ^ hi1) < 0); - - if (bot0 || bot1) { - // All unsigned values are LE -1 and GE 0. - if (lo0 == 0 && hi0 == 0) { - return TypeInt::CC_LE; // 0 <= bot - } else if ((jlong)lo0 == -1 && (jlong)hi0 == -1) { - return TypeInt::CC_GE; // -1 >= bot - } else if (lo1 == 0 && hi1 == 0) { - return TypeInt::CC_GE; // bot >= 0 - } else if ((jlong)lo1 == -1 && (jlong)hi1 == -1) { - return TypeInt::CC_LE; // bot <= -1 - } - } else { - // We can use ranges of the form [lo..hi] if signs are the same. - assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); - // results are reversed, '-' > '+' for unsigned compare - if (hi0 < lo1) { - return TypeInt::CC_LT; // smaller - } else if (lo0 > hi1) { - return TypeInt::CC_GT; // greater - } else if (hi0 == lo1 && lo0 == hi1) { - return TypeInt::CC_EQ; // Equal results - } else if (lo0 >= hi1) { - return TypeInt::CC_GE; - } else if (hi0 <= lo1) { - return TypeInt::CC_LE; - } + if (r0->_uhi < r1->_ulo) { + return TypeInt::CC_LT; + } else if (r0->_ulo > r1->_uhi) { + return TypeInt::CC_GT; + } else if (r0->is_con() && r1->is_con()) { + // Since r0->_ulo == r0->_uhi == r0->get_con(), we only reach here if the constants are equal + assert(r0->get_con() == r1->get_con(), "must reach a previous branch otherwise"); + return TypeInt::CC_EQ; + } else if (r0->_uhi == r1->_ulo) { + return TypeInt::CC_LE; + } else if (r0->_ulo == r1->_uhi) { + return TypeInt::CC_GE; } const Type* joined = r0->join(r1); @@ -1015,7 +954,7 @@ const Type* CmpULNode::sub(const Type* t1, const Type* t2) const { return TypeInt::CC_NE; } - return TypeInt::CC; // else use worst case results + return TypeInt::CC; } //============================================================================= diff --git a/src/hotspot/share/opto/vectorIntrinsics.cpp b/src/hotspot/share/opto/vectorIntrinsics.cpp index 65d54e076b6..883a0526053 100644 --- a/src/hotspot/share/opto/vectorIntrinsics.cpp +++ b/src/hotspot/share/opto/vectorIntrinsics.cpp @@ -175,6 +175,10 @@ Node* GraphKit::unbox_vector(Node* v, const TypeInstPtr* vbox_type, BasicType el assert(check_vbox(vbox_type), ""); const TypeVect* vt = TypeVect::make(elem_bt, num_elem, is_vector_mask(vbox_type->instance_klass())); Node* unbox = gvn().transform(new VectorUnboxNode(C, vt, v, merged_memory())); + if (gvn().type(unbox)->isa_vect() == nullptr) { + assert(gvn().type(unbox) == Type::TOP, "sanity"); + return nullptr; // not a vector + } return unbox; } diff --git a/src/hotspot/share/opto/vectornode.cpp b/src/hotspot/share/opto/vectornode.cpp index 271dc901dcb..7401efaf7c2 100644 --- a/src/hotspot/share/opto/vectornode.cpp +++ b/src/hotspot/share/opto/vectornode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2026, 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 @@ -1919,6 +1919,15 @@ Node* VectorMaskToLongNode::Ideal_MaskAll(PhaseGVN* phase) { // saved with a predicate type. if (in1->Opcode() == Op_VectorStoreMask) { Node* mask = in1->in(1); + // Skip the optimization if the mask is dead. + if (phase->type(mask) == Type::TOP) { + return nullptr; + } + // If the ideal graph is transformed correctly, the input mask should be a + // vector type node. Following optimization can ignore the mismatched type + // issue. But we still keep the sanity check for the mask type by using + // "is_vect()" in the assertion below, so that there can be less optimizations + // evolved before the compiler finally runs into a problem. assert(!Matcher::mask_op_prefers_predicate(Opcode(), mask->bottom_type()->is_vect()), "sanity"); in1 = mask; } diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 1c06bf3c521..57971897400 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -2211,8 +2211,8 @@ bool os::used_memory(physical_memory_size_type& value) { bool os::Machine::used_memory(physical_memory_size_type& value) { physical_memory_size_type avail_mem = 0; // Return value ignored - defaulting to 0 on failure. - (void)os::available_memory(avail_mem); - physical_memory_size_type phys_mem = os::physical_memory(); + (void)os::Machine::available_memory(avail_mem); + physical_memory_size_type phys_mem = os::Machine::physical_memory(); value = phys_mem - avail_mem; return true; } diff --git a/src/hotspot/share/runtime/sharedRuntime.hpp b/src/hotspot/share/runtime/sharedRuntime.hpp index 140207e5d63..11bd39c839f 100644 --- a/src/hotspot/share/runtime/sharedRuntime.hpp +++ b/src/hotspot/share/runtime/sharedRuntime.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -30,7 +30,6 @@ #include "code/vmreg.hpp" #include "interpreter/linkResolver.hpp" #include "memory/allStatic.hpp" -#include "memory/metaspaceClosure.hpp" #include "memory/resourceArea.hpp" #include "runtime/safepointVerifiers.hpp" #include "runtime/stubInfo.hpp" @@ -38,6 +37,7 @@ class AdapterHandlerEntry; class AdapterFingerPrint; +class MetaspaceClosure; class vframeStream; // Runtime is the base class for various runtime interfaces diff --git a/src/hotspot/share/runtime/vframeArray.cpp b/src/hotspot/share/runtime/vframeArray.cpp index a68a0adf299..9f1c082ed8f 100644 --- a/src/hotspot/share/runtime/vframeArray.cpp +++ b/src/hotspot/share/runtime/vframeArray.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -491,6 +491,15 @@ void vframeArrayElement::unpack_on_stack(int caller_actual_parameters, #ifndef PRODUCT if (PrintDeoptimizationDetails) { + const bool print_codes = WizardMode && Verbose; + ResourceMark rm(thread); + stringStream codes_ss; + if (print_codes) { + // print_codes_on() may acquire MDOExtraData_lock (rank nosafepoint-1). + // To keep the lock acquisition order correct, call it before taking tty_lock. + // Avoid double buffering: set buffered=false. + method()->print_codes_on(&codes_ss, 0, false); + } ttyLocker ttyl; tty->print_cr("[%d. Interpreted Frame]", ++unpack_counter); iframe()->print_on(tty); @@ -500,7 +509,9 @@ void vframeArrayElement::unpack_on_stack(int caller_actual_parameters, RegisterMap::WalkContinuation::skip); vframe* f = vframe::new_vframe(iframe(), &map, thread); f->print(); - if (WizardMode && Verbose) method()->print_codes(); + if (print_codes) { + tty->print("%s", codes_ss.as_string()); + } tty->cr(); } #endif // !PRODUCT diff --git a/src/hotspot/share/utilities/growableArray.hpp b/src/hotspot/share/utilities/growableArray.hpp index 1fef271c8c0..1823a2ba861 100644 --- a/src/hotspot/share/utilities/growableArray.hpp +++ b/src/hotspot/share/utilities/growableArray.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -116,6 +116,12 @@ protected: ~GrowableArrayView() {} +protected: + // Used by AOTGrowableArray for MetaspaceClosure support. + E** data_addr() { + return &_data; + } + public: bool operator==(const GrowableArrayView& rhs) const { if (_len != rhs._len) diff --git a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m index 31572eaeb81..6d8eb832370 100644 --- a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m +++ b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, 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 @@ -134,10 +134,11 @@ static OSStatus completeCertChain( CFArrayAppendValue(certArray, identity); /* the single element in certs-to-be-evaluated comes from the identity */ - ortn = SecIdentityCopyCertificate(identity, &certRef); - if(ortn) { + ortn = SecIdentityCopyCertificate(identity, &certRef); + if (ortn) { /* should never happen */ cssmPerror("SecIdentityCopyCertificate", ortn); + CFRelease(certArray); return ortn; } @@ -283,6 +284,7 @@ static void addIdentitiesToKeystore(JNIEnv *env, jobject keyStore, jmethodID jm_ OSStatus err = SecIdentitySearchCreate(NULL, 0, &identitySearch); SecIdentityRef theIdentity = NULL; OSErr searchResult = noErr; + CFArrayRef certChain = NULL; do { searchResult = SecIdentitySearchCopyNext(identitySearch, &theIdentity); @@ -291,7 +293,6 @@ static void addIdentitiesToKeystore(JNIEnv *env, jobject keyStore, jmethodID jm_ // Get the cert from the identity, then generate a chain. SecCertificateRef certificate; SecIdentityCopyCertificate(theIdentity, &certificate); - CFArrayRef certChain = NULL; // *** Should do something with this error... err = completeCertChain(theIdentity, NULL, TRUE, &certChain); @@ -357,6 +358,11 @@ static void addIdentitiesToKeystore(JNIEnv *env, jobject keyStore, jmethodID jm_ if ((*env)->ExceptionCheck(env)) { goto errOut; } + + if (certChain != NULL) { + CFRelease(certChain); + certChain = NULL; + } } } while (searchResult == noErr); @@ -364,6 +370,9 @@ errOut: if (identitySearch != NULL) { CFRelease(identitySearch); } + if (certChain != NULL) { + CFRelease(certChain); + } } #define ADD(list, str) { \ diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index feb8aaaa1a9..7fde9d1dd89 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2026, 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 @@ -4826,7 +4826,9 @@ assert((int)twice.invokeExact(21) == 42); * Before the method handle is returned, the passed-in value is converted to the requested type. * If the requested type is primitive, widening primitive conversions are attempted, * else reference conversions are attempted. - *

    The returned method handle is equivalent to {@code identity(type).bindTo(value)}. + *

    The returned method handle is equivalent to {@code identity(type).bindTo(value)}, + * for reference types. For all types it is equivalent to + * {@code insertArguments(identity(type), 0, value)}. * @param type the return type of the desired method handle * @param value the value to return * @return a method handle of the given return type and no arguments, which always returns the given value diff --git a/src/java.base/share/classes/java/lang/runtime/ExactConversionsSupport.java b/src/java.base/share/classes/java/lang/runtime/ExactConversionsSupport.java index a1a93859c42..8d4389f7295 100644 --- a/src/java.base/share/classes/java/lang/runtime/ExactConversionsSupport.java +++ b/src/java.base/share/classes/java/lang/runtime/ExactConversionsSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2026, 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 @@ -64,12 +64,9 @@ package java.lang.runtime; * floating-point type is considered exact. * * - * @see - * JLS 5.7.1 Exact Testing Conversions - * @see - * JLS 5.7.2 Unconditionally Exact Testing Conversions - * @see - * JLS 15.20.2 The instanceof Operator + * @jls primitive-types-in-patterns-instanceof-switch-5.7.1 Exact Testing Conversions + * @jls primitive-types-in-patterns-instanceof-switch-5.7.2 Unconditionally Exact Testing Conversions + * @jls primitive-types-in-patterns-instanceof-switch-15.20.2 The {@code instanceof} Operator * * @implNote Some exactness checks describe a test which can be redirected * safely through one of the existing methods. Those are omitted too (i.e., diff --git a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java index 30b6df0073e..087d2cc23a9 100644 --- a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java +++ b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -188,13 +188,17 @@ public final class SwitchBootstraps { String invocationName, MethodType invocationType, Object... labels) { + requireNonNull(lookup); + requireNonNull(invocationType); + requireNonNull(labels); + Class selectorType = invocationType.parameterType(0); if (invocationType.parameterCount() != 2 || (!invocationType.returnType().equals(int.class)) || !invocationType.parameterType(1).equals(int.class)) throw new IllegalArgumentException("Illegal invocation type " + invocationType); - for (Object l : labels) { // implicit null-check + for (Object l : labels) { verifyLabel(l, selectorType); } @@ -292,6 +296,10 @@ public final class SwitchBootstraps { String invocationName, MethodType invocationType, Object... labels) { + requireNonNull(lookup); + requireNonNull(invocationType); + requireNonNull(labels); + if (invocationType.parameterCount() != 2 || (!invocationType.returnType().equals(int.class)) || invocationType.parameterType(0).isPrimitive() @@ -299,7 +307,7 @@ public final class SwitchBootstraps { || !invocationType.parameterType(1).equals(int.class)) throw new IllegalArgumentException("Illegal invocation type " + invocationType); - labels = labels.clone(); // implicit null check + labels = labels.clone(); Class enumClass = invocationType.parameterType(0); boolean constantsOnly = true; @@ -307,7 +315,7 @@ public final class SwitchBootstraps { for (int i = 0; i < len; i++) { Object convertedLabel = - convertEnumConstants(lookup, enumClass, labels[i]); + convertEnumConstants(enumClass, labels[i]); labels[i] = convertedLabel; if (constantsOnly) constantsOnly = convertedLabel instanceof EnumDesc; @@ -331,7 +339,7 @@ public final class SwitchBootstraps { return new ConstantCallSite(target); } - private static > Object convertEnumConstants(MethodHandles.Lookup lookup, Class enumClassTemplate, Object label) { + private static > Object convertEnumConstants(Class enumClassTemplate, Object label) { if (label == null) { throw new IllegalArgumentException("null label found"); } diff --git a/src/java.base/share/classes/java/nio/charset/Charset-X-Coder.java.template b/src/java.base/share/classes/java/nio/charset/Charset-X-Coder.java.template index e900c2eca0f..aca987ed678 100644 --- a/src/java.base/share/classes/java/nio/charset/Charset-X-Coder.java.template +++ b/src/java.base/share/classes/java/nio/charset/Charset-X-Coder.java.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2026, 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 @@ -819,6 +819,12 @@ public abstract class Charset$Coder$ { */ public final $Otype$Buffer $code$($Itype$Buffer in) throws CharacterCodingException + { + return $code$(in, true); + } + + private $Otype$Buffer $code$($Itype$Buffer in, boolean throwOnError) + throws CharacterCodingException { int n = Math.min((int)(in.remaining() * average$ItypesPerOtype$()), ArraysSupport.SOFT_MAX_ARRAY_LENGTH); @@ -844,7 +850,11 @@ public abstract class Charset$Coder$ { out = o; continue; } - cr.throwException(); + if (throwOnError) { + cr.throwException(); + } else { + return null; + } } out.flip(); return out; @@ -938,7 +948,8 @@ public abstract class Charset$Coder$ { try { onMalformedInput(CodingErrorAction.REPORT); onUnmappableCharacter(CodingErrorAction.REPORT); - encode(cb); + ByteBuffer bb = encode(cb, false); + return bb != null; } catch (CharacterCodingException x) { return false; } finally { @@ -946,7 +957,6 @@ public abstract class Charset$Coder$ { onUnmappableCharacter(ua); reset(); } - return true; } /** diff --git a/src/java.base/share/classes/java/util/Optional.java b/src/java.base/share/classes/java/util/Optional.java index 3e577bd379c..3d0375c4354 100644 --- a/src/java.base/share/classes/java/util/Optional.java +++ b/src/java.base/share/classes/java/util/Optional.java @@ -25,7 +25,7 @@ package java.util; -import jdk.internal.vm.annotation.Stable; +import jdk.internal.vm.annotation.TrustFinalFields; import java.util.function.Consumer; import java.util.function.Function; @@ -62,6 +62,7 @@ import java.util.stream.Stream; * @since 1.8 */ @jdk.internal.ValueBased +@TrustFinalFields public final class Optional { /** * Common instance for {@code empty()}. @@ -71,7 +72,6 @@ public final class Optional { /** * If non-null, the value; if null, indicates no value is present */ - @Stable private final T value; /** diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java index 2250009e8f5..70acb8a0889 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java @@ -42,6 +42,8 @@ import java.util.function.IntUnaryOperator; import jdk.internal.misc.Unsafe; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; +import jdk.internal.vm.annotation.TrustFinalFields; + import java.lang.invoke.VarHandle; /** @@ -371,6 +373,7 @@ public abstract class AtomicIntegerFieldUpdater { /** * Standard hotspot implementation using intrinsics. */ + @TrustFinalFields private static final class AtomicIntegerFieldUpdaterImpl extends AtomicIntegerFieldUpdater { private static final Unsafe U = Unsafe.getUnsafe(); diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java index 5f0a666cb04..d3a3fe63d0f 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java @@ -42,6 +42,8 @@ import java.util.function.LongUnaryOperator; import jdk.internal.misc.Unsafe; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; +import jdk.internal.vm.annotation.TrustFinalFields; + import java.lang.invoke.VarHandle; /** @@ -368,6 +370,7 @@ public abstract class AtomicLongFieldUpdater { return next; } + @TrustFinalFields private static final class CASUpdater extends AtomicLongFieldUpdater { private static final Unsafe U = Unsafe.getUnsafe(); private final long offset; diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java index 4a758f77a47..3d47e8e323a 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java @@ -42,6 +42,8 @@ import java.util.function.UnaryOperator; import jdk.internal.misc.Unsafe; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; +import jdk.internal.vm.annotation.TrustFinalFields; + import java.lang.invoke.VarHandle; /** @@ -312,6 +314,7 @@ public abstract class AtomicReferenceFieldUpdater { return next; } + @TrustFinalFields private static final class AtomicReferenceFieldUpdaterImpl extends AtomicReferenceFieldUpdater { private static final Unsafe U = Unsafe.getUnsafe(); diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index 7fa507980c2..a198c35c366 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2026, 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 @@ -37,6 +37,7 @@ import java.nio.charset.Charset; import java.nio.file.InvalidPathException; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.Files; +import java.nio.file.attribute.FileTime; import java.util.*; import java.util.function.Consumer; import java.util.function.IntFunction; @@ -86,11 +87,11 @@ public class ZipFile implements ZipConstants, Closeable { private final ZipCoder zipCoder; private volatile boolean closeRequested; - // The "resource" used by this ZIP file that needs to be - // cleaned after use. + // An object holding state which needs to be cleaned after + // this ZipFile is closed or becomes unreachable: // a) the input streams that need to be closed // b) the list of cached Inflater objects - // c) the "native" source of this ZIP file. + // c) the Source object providing read access to the actual ZIP file private final @Stable CleanableResource res; private static final int STORED = ZipEntry.STORED; @@ -1444,11 +1445,13 @@ public class ZipFile implements ZipConstants, Closeable { * The unique combination of these components identifies a Source of a ZipFile. */ private static class Key { - private final BasicFileAttributes attrs; private final File file; + private final Object fileKey; + private final FileTime lastModifiedTime; // the Charset that was provided when constructing the ZipFile instance private final Charset charset; + /** * Constructs a {@code Key} to a {@code Source} of a {@code ZipFile} * @@ -1457,7 +1460,8 @@ public class ZipFile implements ZipConstants, Closeable { * @param charset the Charset that was provided when constructing the ZipFile instance */ public Key(File file, BasicFileAttributes attrs, Charset charset) { - this.attrs = attrs; + this.fileKey = attrs.fileKey(); + this.lastModifiedTime = attrs.lastModifiedTime(); this.file = file; this.charset = charset; } @@ -1465,10 +1469,9 @@ public class ZipFile implements ZipConstants, Closeable { @Override public int hashCode() { long t = charset.hashCode(); - t += attrs.lastModifiedTime().toMillis(); - Object fk = attrs.fileKey(); + t += lastModifiedTime.toMillis(); return Long.hashCode(t) + - (fk != null ? fk.hashCode() : file.hashCode()); + (fileKey != null ? fileKey.hashCode() : file.hashCode()); } @Override @@ -1477,12 +1480,12 @@ public class ZipFile implements ZipConstants, Closeable { if (!charset.equals(key.charset)) { return false; } - if (!attrs.lastModifiedTime().equals(key.attrs.lastModifiedTime())) { + if (!lastModifiedTime.equals(key.lastModifiedTime)) { return false; } - Object fk = attrs.fileKey(); - if (fk != null) { - return fk.equals(key.attrs.fileKey()); + + if (fileKey != null) { + return fileKey.equals(key.fileKey); } else { return file.equals(key.file); } diff --git a/src/java.base/share/classes/jdk/internal/vm/annotation/TrustFinalFields.java b/src/java.base/share/classes/jdk/internal/vm/annotation/TrustFinalFields.java new file mode 100644 index 00000000000..a94f58159a2 --- /dev/null +++ b/src/java.base/share/classes/jdk/internal/vm/annotation/TrustFinalFields.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package jdk.internal.vm.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/// Indicates all instance final fields declared in the annotated class should +/// be trusted as constants by compilers in `ciField::is_constant`. +/// +/// The compiler already treats static final fields and instance final fields in +/// record classes and hidden classes as constant. All classes in select +/// packages (Defined in `trust_final_non_static_fields` in `ciField.cpp`) in +/// the boot class loader also have their instance final fields trusted. This +/// annotation is not necessary in these cases. +/// +/// The [Stable] annotation treats fields as constants once they are not the +/// zero or null value. In comparison, a non-stable final instance field +/// trusted by this annotation can treat zero and null values as constants. +/// +/// This annotation is suitable when constant treatment of final fields is +/// performance sensitive, yet package-wide final field constant treatment may +/// be at risk from final field modifications such as serialization. +/// +/// This annotation is only recognized on classes from the boot and platform +/// class loaders and is ignored elsewhere. +/// +/// @since 26 +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface TrustFinalFields { +} diff --git a/src/java.base/share/classes/sun/nio/cs/DoubleByte.java b/src/java.base/share/classes/sun/nio/cs/DoubleByte.java index 2a4dbdc95ed..0aaae14bbf9 100644 --- a/src/java.base/share/classes/sun/nio/cs/DoubleByte.java +++ b/src/java.base/share/classes/sun/nio/cs/DoubleByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2026, 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 @@ -583,6 +583,16 @@ public class DoubleByte { return encodeChar(c) != UNMAPPABLE_ENCODING; } + public boolean canEncode(CharSequence cs) { + int length = cs.length(); + for (int i = 0; i < length; i++) { + if (!canEncode(cs.charAt(i))) { + return false; + } + } + return true; + } + protected Surrogate.Parser sgp() { if (sgp == null) sgp = new Surrogate.Parser(); diff --git a/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java b/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java index 39215bfa93d..9240ac3f380 100644 --- a/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java +++ b/src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2026, 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 @@ -136,6 +136,16 @@ public class ISO_8859_1 return c <= '\u00FF'; } + public boolean canEncode(CharSequence cs) { + int length = cs.length(); + for (int i = 0; i < length; i++) { + if (!canEncode(cs.charAt(i))) { + return false; + } + } + return true; + } + public boolean isLegalReplacement(byte[] repl) { return true; // we accept any byte value } diff --git a/src/java.base/share/classes/sun/nio/cs/SingleByte.java b/src/java.base/share/classes/sun/nio/cs/SingleByte.java index 59887b944d3..d4127b7c043 100644 --- a/src/java.base/share/classes/sun/nio/cs/SingleByte.java +++ b/src/java.base/share/classes/sun/nio/cs/SingleByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2026, 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 @@ -201,6 +201,16 @@ public class SingleByte return encode(c) != UNMAPPABLE_ENCODING; } + public boolean canEncode(CharSequence cs) { + int length = cs.length(); + for (int i = 0; i < length; i++) { + if (!canEncode(cs.charAt(i))) { + return false; + } + } + return true; + } + public boolean isLegalReplacement(byte[] repl) { return ((repl.length == 1 && repl[0] == (byte)'?') || super.isLegalReplacement(repl)); diff --git a/src/java.base/share/classes/sun/nio/cs/US_ASCII.java b/src/java.base/share/classes/sun/nio/cs/US_ASCII.java index bb84ab1bd4b..61c4948e949 100644 --- a/src/java.base/share/classes/sun/nio/cs/US_ASCII.java +++ b/src/java.base/share/classes/sun/nio/cs/US_ASCII.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2026, 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 @@ -139,6 +139,16 @@ public class US_ASCII return c < 0x80; } + public boolean canEncode(CharSequence cs) { + int length = cs.length(); + for (int i = 0; i < length; i++) { + if (!canEncode(cs.charAt(i))) { + return false; + } + } + return true; + } + public boolean isLegalReplacement(byte[] repl) { return (repl.length == 1 && repl[0] >= 0) || super.isLegalReplacement(repl); diff --git a/src/java.base/share/classes/sun/security/util/CryptoAlgorithmConstraints.java b/src/java.base/share/classes/sun/security/util/CryptoAlgorithmConstraints.java index a8649106a38..ad3beab350f 100644 --- a/src/java.base/share/classes/sun/security/util/CryptoAlgorithmConstraints.java +++ b/src/java.base/share/classes/sun/security/util/CryptoAlgorithmConstraints.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -82,8 +82,10 @@ public class CryptoAlgorithmConstraints extends AbstractAlgorithmConstraints { CryptoAlgorithmConstraints(String propertyName) { super(null); disabledServices = getAlgorithms(propertyName, true); - debug("Before " + Arrays.deepToString(disabledServices.toArray())); - for (String dk : disabledServices) { + String[] entries = disabledServices.toArray(new String[0]); + debug("Before " + Arrays.deepToString(entries)); + + for (String dk : entries) { int idx = dk.indexOf("."); if (idx < 1 || idx == dk.length() - 1) { // wrong syntax: missing "." or empty service or algorithm diff --git a/src/java.base/share/native/libjimage/imageDecompressor.cpp b/src/java.base/share/native/libjimage/imageDecompressor.cpp index 748bbf8203f..4946e645c55 100644 --- a/src/java.base/share/native/libjimage/imageDecompressor.cpp +++ b/src/java.base/share/native/libjimage/imageDecompressor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -85,10 +85,6 @@ void ImageDecompressor::image_decompressor_init() { } } -void ImageDecompressor::image_decompressor_close() { - delete[] _decompressors; -} - /* * Locate decompressor. */ diff --git a/src/java.base/share/native/libjimage/imageDecompressor.hpp b/src/java.base/share/native/libjimage/imageDecompressor.hpp index 16f354935c3..057fa15917c 100644 --- a/src/java.base/share/native/libjimage/imageDecompressor.hpp +++ b/src/java.base/share/native/libjimage/imageDecompressor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -105,6 +105,7 @@ private: protected: ImageDecompressor(const char* name) : _name(name) { } + virtual void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, const ImageStrings* strings) = 0; @@ -166,6 +167,6 @@ private: public: SharedStringDecompressor(const char* sym) : ImageDecompressor(sym){} void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, - const ImageStrings* strings); + const ImageStrings* strings); }; #endif // LIBJIMAGE_IMAGEDECOMPRESSOR_HPP diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java index baeb249eaa8..76d7abdbce6 100644 --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKStyle.java @@ -32,7 +32,6 @@ import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.synth.*; -import sun.awt.AppContext; import sun.awt.UNIXToolkit; import sun.swing.SwingUtilities2; import javax.swing.plaf.synth.SynthIcon; @@ -961,11 +960,11 @@ class GTKStyle extends SynthStyle implements GTKConstants { static class GTKStockIconInfo { private static Map ICON_TYPE_MAP; - private static final Object ICON_SIZE_KEY = new StringBuffer("IconSize"); + + private static Dimension[] iconSizesMap; private static Dimension[] getIconSizesMap() { - AppContext appContext = AppContext.getAppContext(); - Dimension[] iconSizes = (Dimension[])appContext.get(ICON_SIZE_KEY); + Dimension[] iconSizes = iconSizesMap; if (iconSizes == null) { iconSizes = new Dimension[7]; @@ -976,7 +975,7 @@ class GTKStyle extends SynthStyle implements GTKConstants { iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG - appContext.put(ICON_SIZE_KEY, iconSizes); + iconSizesMap = iconSizes; } return iconSizes; } diff --git a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java index 15a7fbbaa00..ee3f6a449b7 100644 --- a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java +++ b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2026, 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 @@ -32,7 +32,6 @@ import java.util.ServiceLoader; import javax.print.attribute.AttributeSet; -import sun.awt.AppContext; /** * Implementations of this class provide lookup services for print services @@ -58,35 +57,14 @@ public abstract class PrintServiceLookup { protected PrintServiceLookup() {} /** - * Contains a lists of services. + * The list of lookup services. */ - static class Services { - - /** - * The list of lookup services. - */ - private ArrayList listOfLookupServices = null; - - /** - * The list of registered services. - */ - private ArrayList registeredServices = null; - } + private static ArrayList listOfLookupServices = null; /** - * Returns the services from the current appcontext. - * - * @return the services + * The list of registered services. */ - private static Services getServicesForContext() { - Services services = - (Services)AppContext.getAppContext().get(Services.class); - if (services == null) { - services = new Services(); - AppContext.getAppContext().put(Services.class, services); - } - return services; - } + private static ArrayList registeredServices = null; /** * Returns the list of lookup services. @@ -94,7 +72,7 @@ public abstract class PrintServiceLookup { * @return the list of lookup services */ private static ArrayList getListOfLookupServices() { - return getServicesForContext().listOfLookupServices; + return listOfLookupServices; } /** @@ -103,8 +81,7 @@ public abstract class PrintServiceLookup { * @return the list of lookup services */ private static ArrayList initListOfLookupServices() { - ArrayList listOfLookupServices = new ArrayList<>(); - getServicesForContext().listOfLookupServices = listOfLookupServices; + listOfLookupServices = new ArrayList<>(); return listOfLookupServices; } @@ -114,7 +91,7 @@ public abstract class PrintServiceLookup { * @return the list of registered services */ private static ArrayList getRegisteredServices() { - return getServicesForContext().registeredServices; + return registeredServices; } /** @@ -123,8 +100,7 @@ public abstract class PrintServiceLookup { * @return the list of registered services */ private static ArrayList initRegisteredServices() { - ArrayList registeredServices = new ArrayList<>(); - getServicesForContext().registeredServices = registeredServices; + registeredServices = new ArrayList<>(); return registeredServices; } diff --git a/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java b/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java index 7d696f14a94..2667587e9b2 100644 --- a/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java +++ b/src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2026, 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 @@ -33,8 +33,6 @@ import java.util.ServiceLoader; import javax.print.attribute.PrintRequestAttributeSet; -import sun.awt.AppContext; - /** * A {@code StreamPrintServiceFactory} is the factory for * {@link StreamPrintService} instances, which can print to an output stream in @@ -63,24 +61,20 @@ public abstract class StreamPrintServiceFactory { static class Services { /** - * The list of factories which will be stored per appcontext. + * The list of factories. */ private ArrayList listOfFactories = null; } + private static final Services SERVICES = new Services(); + /** - * Returns the services from the current appcontext. + * Returns the singleton Services instance. * * @return the services */ private static Services getServices() { - Services services = - (Services)AppContext.getAppContext().get(Services.class); - if (services == null) { - services = new Services(); - AppContext.getAppContext().put(Services.class, services); - } - return services; + return SERVICES; } /** diff --git a/src/java.desktop/share/classes/javax/swing/plaf/nimbus/Effect.java b/src/java.desktop/share/classes/javax/swing/plaf/nimbus/Effect.java index 30bed2207e4..d1b7ba143b3 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/nimbus/Effect.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/nimbus/Effect.java @@ -24,8 +24,6 @@ */ package javax.swing.plaf.nimbus; -import sun.awt.AppContext; - import java.awt.image.BufferedImage; import java.lang.ref.SoftReference; @@ -81,13 +79,10 @@ abstract class Effect { // ================================================================================================================= // Static data cache + private static final ArrayCache ARRAY_CACHE = new ArrayCache(); + protected static ArrayCache getArrayCache() { - ArrayCache cache = (ArrayCache)AppContext.getAppContext().get(ArrayCache.class); - if (cache == null){ - cache = new ArrayCache(); - AppContext.getAppContext().put(ArrayCache.class,cache); - } - return cache; + return ARRAY_CACHE; } protected static class ArrayCache { diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/ImagePainter.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/ImagePainter.java index 8a1d957b615..1171f64eb23 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/ImagePainter.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/ImagePainter.java @@ -28,7 +28,6 @@ import java.awt.*; import java.lang.ref.WeakReference; import java.net.*; import javax.swing.*; -import sun.awt.AppContext; import sun.swing.plaf.synth.Paint9Painter; /** @@ -41,8 +40,6 @@ import sun.swing.plaf.synth.Paint9Painter; * @author Scott Violet */ class ImagePainter extends SynthPainter { - private static final StringBuffer CACHE_KEY = - new StringBuffer("SynthCacheKey"); private Image image; private Insets sInsets; @@ -53,22 +50,17 @@ class ImagePainter extends SynthPainter { private Paint9Painter imageCache; private boolean center; + private static volatile WeakReference cacheRef; + private static Paint9Painter getPaint9Painter() { // A SynthPainter is created per . We want the - // cache to be shared by all, and we don't use a static because we - // don't want it to persist between look and feels. For that reason - // we use a AppContext specific Paint9Painter. It's backed via + // cache to be shared by all. It's held via // a WeakRef so that it can go away if the look and feel changes. - synchronized(CACHE_KEY) { - @SuppressWarnings("unchecked") - WeakReference cacheRef = - (WeakReference)AppContext.getAppContext(). - get(CACHE_KEY); + synchronized(ImagePainter.class) { Paint9Painter painter; if (cacheRef == null || (painter = cacheRef.get()) == null) { painter = new Paint9Painter(30); cacheRef = new WeakReference(painter); - AppContext.getAppContext().put(CACHE_KEY, cacheRef); } return painter; } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java index 5a59f3bb98d..f8a0800ff8b 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java @@ -24,8 +24,6 @@ */ package javax.swing.plaf.synth; -import sun.awt.AppContext; - import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -72,8 +70,6 @@ import javax.swing.UIDefaults; * @author Scott Violet */ public class Region { - private static final Object UI_TO_REGION_MAP_KEY = new Object(); - private static final Object LOWER_CASE_NAME_MAP_KEY = new Object(); /** * ArrowButton's are special types of buttons that also render a @@ -425,10 +421,10 @@ public class Region { */ public static final Region VIEWPORT = new Region("Viewport", false); - private static Map getUItoRegionMap() { - AppContext context = AppContext.getAppContext(); - @SuppressWarnings("unchecked") - Map map = (Map) context.get(UI_TO_REGION_MAP_KEY); + private static Map regionMap; + + private static synchronized Map getUItoRegionMap() { + Map map = regionMap; if (map == null) { map = new HashMap(); map.put("ArrowButtonUI", ARROW_BUTTON); @@ -476,18 +472,18 @@ public class Region { map.put("ToolBarSeparatorUI", TOOL_BAR_SEPARATOR); map.put("TreeUI", TREE); map.put("ViewportUI", VIEWPORT); - context.put(UI_TO_REGION_MAP_KEY, map); + regionMap = map; } return map; } - private static Map getLowerCaseNameMap() { - AppContext context = AppContext.getAppContext(); - @SuppressWarnings("unchecked") - Map map = (Map) context.get(LOWER_CASE_NAME_MAP_KEY); + private static Map lcRegionMap; + + private static synchronized Map getLowerCaseNameMap() { + Map map = lcRegionMap; if (map == null) { map = new HashMap(); - context.put(LOWER_CASE_NAME_MAP_KEY, map); + lcRegionMap = map; } return map; } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthButtonUI.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthButtonUI.java index 3a3d5719605..f0c7a9a1622 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthButtonUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthButtonUI.java @@ -25,8 +25,6 @@ package javax.swing.plaf.synth; -import sun.awt.AppContext; - import javax.swing.*; import java.awt.*; import java.beans.*; diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java index 700e3ed8a38..095d675d3de 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java @@ -60,7 +60,6 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.basic.BasicLookAndFeel; -import sun.awt.AppContext; import sun.awt.SunToolkit; import sun.swing.DefaultLookup; import sun.swing.SwingAccessor; @@ -101,31 +100,13 @@ public class SynthLookAndFeel extends BasicLookAndFeel { static final Insets EMPTY_UIRESOURCE_INSETS = new InsetsUIResource( 0, 0, 0, 0); - /** - * AppContext key to get the current SynthStyleFactory. - */ - private static final Object STYLE_FACTORY_KEY = - new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache"); + private static ComponentUI selectedUI; + private static int selectedUIStateValue; /** - * AppContext key to get selectedUI. - */ - private static final Object SELECTED_UI_KEY = new StringBuilder("selectedUI"); - - /** - * AppContext key to get selectedUIState. - */ - private static final Object SELECTED_UI_STATE_KEY = new StringBuilder("selectedUIState"); - - /** - * The last SynthStyleFactory that was asked for from AppContext - * lastContext. + * The last SynthStyleFactory that was set. */ private static SynthStyleFactory lastFactory; - /** - * AppContext lastLAF came from. - */ - private static AppContext lastContext; /** * SynthStyleFactory for the this SynthLookAndFeel. @@ -141,7 +122,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { private Handler _handler; static ComponentUI getSelectedUI() { - return (ComponentUI) AppContext.getAppContext().get(SELECTED_UI_KEY); + return selectedUI; } /** @@ -182,23 +163,20 @@ public class SynthLookAndFeel extends BasicLookAndFeel { } } - AppContext context = AppContext.getAppContext(); - - context.put(SELECTED_UI_KEY, uix); - context.put(SELECTED_UI_STATE_KEY, Integer.valueOf(selectedUIState)); + selectedUI = uix; + selectedUIStateValue = selectedUIState; } static int getSelectedUIState() { - Integer result = (Integer) AppContext.getAppContext().get(SELECTED_UI_STATE_KEY); - - return result == null ? 0 : result.intValue(); + return selectedUIStateValue; } /** * Clears out the selected UI that was last set in setSelectedUI. */ static void resetSelectedUI() { - AppContext.getAppContext().remove(SELECTED_UI_KEY); + selectedUI = null; + selectedUIStateValue = 0; } @@ -210,12 +188,8 @@ public class SynthLookAndFeel extends BasicLookAndFeel { */ public static void setStyleFactory(SynthStyleFactory cache) { // We assume the setter is called BEFORE the getter has been invoked - // for a particular AppContext. synchronized(SynthLookAndFeel.class) { - AppContext context = AppContext.getAppContext(); lastFactory = cache; - lastContext = context; - context.put(STYLE_FACTORY_KEY, cache); } } @@ -226,13 +200,6 @@ public class SynthLookAndFeel extends BasicLookAndFeel { */ public static SynthStyleFactory getStyleFactory() { synchronized(SynthLookAndFeel.class) { - AppContext context = AppContext.getAppContext(); - - if (lastContext == context) { - return lastFactory; - } - lastContext = context; - lastFactory = (SynthStyleFactory) context.get(STYLE_FACTORY_KEY); return lastFactory; } } diff --git a/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java b/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java index 03e04d1c1a7..59cee1e12ee 100644 --- a/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java +++ b/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -62,9 +62,6 @@ import javax.accessibility.*; import javax.print.attribute.*; -import sun.awt.AppContext; - - import sun.swing.PrintingStatus; import sun.swing.SwingUtilities2; import sun.swing.text.TextComponentPrintable; @@ -1097,22 +1094,16 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A return getKeymapTable().get(nm); } - private static HashMap getKeymapTable() { - synchronized (KEYMAP_TABLE) { - AppContext appContext = AppContext.getAppContext(); - @SuppressWarnings("unchecked") - HashMap keymapTable = - (HashMap)appContext.get(KEYMAP_TABLE); - if (keymapTable == null) { - keymapTable = new HashMap(17); - appContext.put(KEYMAP_TABLE, keymapTable); - //initialize default keymap - Keymap binding = addKeymap(DEFAULT_KEYMAP, null); - binding.setDefaultAction(new - DefaultEditorKit.DefaultKeyTypedAction()); - } - return keymapTable; + private static HashMap keymapTable; + + private static synchronized HashMap getKeymapTable() { + if (keymapTable == null) { + keymapTable = new HashMap(17); + //initialize default keymap + Keymap binding = addKeymap(DEFAULT_KEYMAP, null); + binding.setDefaultAction(new DefaultEditorKit.DefaultKeyTypedAction()); } + return keymapTable; } /** @@ -1653,7 +1644,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A public void removeNotify() { super.removeNotify(); if (getFocusedComponent() == this) { - AppContext.getAppContext().remove(FOCUSED_COMPONENT); + focusedComponent = null; } } @@ -4084,13 +4075,14 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A } } + private static JTextComponent focusedComponent; + /** * Returns the JTextComponent that most recently had focus. The returned * value may currently have focus. */ static final JTextComponent getFocusedComponent() { - return (JTextComponent)AppContext.getAppContext(). - get(FOCUSED_COMPONENT); + return focusedComponent; } @SuppressWarnings("deprecation") @@ -4105,9 +4097,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A return modifiers; } - private static final Object KEYMAP_TABLE = - new StringBuilder("JTextComponent_KeymapTable"); - // // member variables used for on-the-spot input method // editing style support @@ -4438,9 +4427,6 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A } } - private static final Object FOCUSED_COMPONENT = - new StringBuilder("JTextComponent_FocusedComponent"); - /** * The default keymap that will be shared by all * JTextComponent instances unless they @@ -4493,8 +4479,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A // --- FocusListener methods ----------------------------------- public void focusGained(FocusEvent fe) { - AppContext.getAppContext().put(FOCUSED_COMPONENT, - fe.getSource()); + focusedComponent = (JTextComponent)fe.getSource(); } public void focusLost(FocusEvent fe) { diff --git a/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java b/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java index 6801a84da5b..1a4e7315eb4 100644 --- a/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java +++ b/src/java.desktop/share/classes/javax/swing/text/LayoutQueue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2026, 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 @@ -25,7 +25,6 @@ package javax.swing.text; import java.util.Vector; -import sun.awt.AppContext; /** * A queue of text layout tasks. @@ -36,11 +35,11 @@ import sun.awt.AppContext; */ public class LayoutQueue { - private static final Object DEFAULT_QUEUE = new Object(); - private Vector tasks; private Thread worker; + private static LayoutQueue defaultQueue; + /** * Construct a layout queue. */ @@ -53,15 +52,10 @@ public class LayoutQueue { * @return the default layout queue */ public static LayoutQueue getDefaultQueue() { - AppContext ac = AppContext.getAppContext(); - synchronized (DEFAULT_QUEUE) { - LayoutQueue defaultQueue = (LayoutQueue) ac.get(DEFAULT_QUEUE); - if (defaultQueue == null) { - defaultQueue = new LayoutQueue(); - ac.put(DEFAULT_QUEUE, defaultQueue); - } - return defaultQueue; + if (defaultQueue == null) { + defaultQueue = new LayoutQueue(); } + return defaultQueue; } /** @@ -70,9 +64,7 @@ public class LayoutQueue { * @param q the new queue. */ public static void setDefaultQueue(LayoutQueue q) { - synchronized (DEFAULT_QUEUE) { - AppContext.getAppContext().put(DEFAULT_QUEUE, q); - } + defaultQueue = q; } /** diff --git a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java index 53ceea32668..b5b75e1067b 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -92,7 +92,6 @@ import javax.swing.text.ViewFactory; import javax.swing.text.html.parser.ParserDelegator; import sun.swing.SwingAccessor; -import sun.awt.AppContext; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -432,11 +431,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { * @param s a StyleSheet */ public void setStyleSheet(StyleSheet s) { - if (s == null) { - AppContext.getAppContext().remove(DEFAULT_STYLES_KEY); - } else { - AppContext.getAppContext().put(DEFAULT_STYLES_KEY, s); - } + defaultStyles = s; } /** @@ -448,12 +443,8 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { * @return the StyleSheet */ public StyleSheet getStyleSheet() { - AppContext appContext = AppContext.getAppContext(); - StyleSheet defaultStyles = (StyleSheet) appContext.get(DEFAULT_STYLES_KEY); - if (defaultStyles == null) { defaultStyles = new StyleSheet(); - appContext.put(DEFAULT_STYLES_KEY, defaultStyles); try (InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS); InputStreamReader isr = new InputStreamReader(is, ISO_8859_1); Reader r = new BufferedReader(isr)) @@ -692,6 +683,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible { private static final ViewFactory defaultFactory = new HTMLFactory(); MutableAttributeSet input; + private static StyleSheet defaultStyles = null; private static final Object DEFAULT_STYLES_KEY = new Object(); private LinkController linkHandler = new LinkController(); private static Parser defaultParser = null; diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java index e9999c679eb..d3a4fa76306 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/DTD.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2026, 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 @@ -25,8 +25,6 @@ package javax.swing.text.html.parser; -import sun.awt.AppContext; - import java.io.PrintStream; import java.io.File; import java.io.FileInputStream; @@ -403,11 +401,6 @@ class DTD implements DTDConstants { return name; } - /** - * The hashtable key of DTDs in AppContext. - */ - private static final Object DTD_HASH_KEY = new Object(); - /** * Put a name and appropriate DTD to hashtable. * @@ -415,7 +408,7 @@ class DTD implements DTDConstants { * @param dtd the DTD */ public static void putDTDHash(String name, DTD dtd) { - getDtdHash().put(name, dtd); + DTD_MAP.put(name, dtd); } /** @@ -430,27 +423,14 @@ class DTD implements DTDConstants { */ public static DTD getDTD(String name) throws IOException { name = name.toLowerCase(); - DTD dtd = getDtdHash().get(name); + DTD dtd = DTD_MAP.get(name); if (dtd == null) dtd = new DTD(name); return dtd; } - private static Hashtable getDtdHash() { - AppContext appContext = AppContext.getAppContext(); - - @SuppressWarnings("unchecked") - Hashtable result = (Hashtable) appContext.get(DTD_HASH_KEY); - - if (result == null) { - result = new Hashtable(); - - appContext.put(DTD_HASH_KEY, result); - } - - return result; - } + private static final Hashtable DTD_MAP = new Hashtable(); /** * Recreates a DTD from an archived format. diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java index cf8ea622c9b..8dd00373636 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/Element.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2026, 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 @@ -28,7 +28,6 @@ package javax.swing.text.html.parser; import java.io.Serializable; import java.util.BitSet; import java.util.Map; -import sun.awt.AppContext; /** * An element as described in a DTD using the ELEMENT construct. @@ -107,17 +106,14 @@ public final class Element implements DTDConstants, Serializable { this.name = name; this.index = index; if (index > getMaxIndex()) { - AppContext.getAppContext().put(MAX_INDEX_KEY, index); + maxIndex = index; } } - private static final Object MAX_INDEX_KEY = new Object(); + private static int maxIndex = 0; static int getMaxIndex() { - Integer value = (Integer) AppContext.getAppContext().get(MAX_INDEX_KEY); - return (value != null) - ? value.intValue() - : 0; + return maxIndex; } /** diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java index 2d541abc06f..6971f313558 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2026, 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 @@ -24,8 +24,6 @@ */ package javax.swing.text.html.parser; -import sun.awt.AppContext; - import javax.swing.text.html.HTMLEditorKit; import java.io.BufferedInputStream; import java.io.IOException; @@ -52,7 +50,8 @@ import java.io.Serializable; */ @SuppressWarnings("serial") // Same-version serialization only public class ParserDelegator extends HTMLEditorKit.Parser implements Serializable { - private static final Object DTD_KEY = new Object(); + + private static DTD dtd = null; /** * Sets the default DTD. @@ -62,10 +61,6 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl } private static synchronized DTD getDefaultDTD() { - AppContext appContext = AppContext.getAppContext(); - - DTD dtd = (DTD) appContext.get(DTD_KEY); - if (dtd == null) { DTD _dtd = null; // (PENDING) Hate having to hard code! @@ -77,10 +72,7 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl System.out.println("Throw an exception: could not get default dtd: " + nm); } dtd = createDTD(_dtd, nm); - - appContext.put(DTD_KEY, dtd); } - return dtd; } diff --git a/src/java.desktop/share/native/libawt/awt/image/awt_ImageRep.c b/src/java.desktop/share/native/libawt/awt/image/awt_ImageRep.c index 6079b9e76b8..3cb2df0e0e9 100644 --- a/src/java.desktop/share/native/libawt/awt/image/awt_ImageRep.c +++ b/src/java.desktop/share/native/libawt/awt/image/awt_ImageRep.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, 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 @@ -227,7 +227,7 @@ Java_sun_awt_image_ImageRepresentation_setICMpixels(JNIEnv *env, jclass cls, /* Release the locked arrays */ (*env)->ReleasePrimitiveArrayCritical(env, jlut, srcLUT, JNI_ABORT); (*env)->ReleasePrimitiveArrayCritical(env, jpix, srcData, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, jdata, dstData, JNI_ABORT); + (*env)->ReleasePrimitiveArrayCritical(env, jdata, dstData, 0); return JNI_TRUE; } @@ -385,7 +385,7 @@ Java_sun_awt_image_ImageRepresentation_setDiffICM(JNIEnv *env, jclass cls, } (*env)->ReleasePrimitiveArrayCritical(env, jpix, srcData, JNI_ABORT); - (*env)->ReleasePrimitiveArrayCritical(env, jdata, dstData, JNI_ABORT); + (*env)->ReleasePrimitiveArrayCritical(env, jdata, dstData, 0); return JNI_TRUE; } diff --git a/src/java.desktop/unix/classes/sun/print/AttributeClass.java b/src/java.desktop/unix/classes/sun/print/AttributeClass.java index 10d0714a059..3db6e310dd2 100644 --- a/src/java.desktop/unix/classes/sun/print/AttributeClass.java +++ b/src/java.desktop/unix/classes/sun/print/AttributeClass.java @@ -174,6 +174,30 @@ public final class AttributeClass { } + /** + * Returns 3 int values. + * xres, yres, resolution as either dpi or dpcm + * The resolution is just a single byte of data. + */ + public int[] getIntResolutionValue() { + int[] res = {0, 0, 0}; + byte[] bufArray = (byte[])myValue; + if (bufArray != null) { + int nBytes = 4; // 32-bit signed integer + for (int j=0; j<2; j++) { // 2 set of integers + byte[] intBytes = new byte[nBytes]; + // REMIND: # bytes should be 8 + for (int i=0; i< nBytes; i++) { + //+ 1 because the 1st byte is length + intBytes[i] = bufArray[i+(4*j)+1]; + } + res[j] = convertToInt(intBytes); + } + res[2] = (int)bufArray[9]; + } + return res; + } + /** * Returns String value. */ diff --git a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java index 2bf326fca57..8a3b872b107 100644 --- a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java +++ b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2026, 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 @@ -141,7 +141,7 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService private MediaSizeName[] mediaSizeNames; private CustomMediaSizeName[] customMediaSizeNames; private int defaultMediaIndex; - private int[] rawResolutions = null; + private int[] ppdResolutions = null; private PrinterResolution[] printerResolutions = null; private boolean isCupsPrinter; private boolean init; @@ -205,8 +205,7 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService OrientationRequested.PORTRAIT, new PageRanges(1), //PresentationDirection, - // CUPS does not supply printer-resolution attribute - //new PrinterResolution(300, 300, PrinterResolution.DPI), + new PrinterResolution(300, 300, PrinterResolution.DPI), //PrintQuality.NORMAL, new RequestingUserName("", Locale.getDefault()), //SheetCollate.UNCOLLATED, //CUPS has no sheet collate? @@ -467,7 +466,9 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService : getSupportedOutputBins(); customMediaSizeNames = cps.getCustomMediaSizeNames(); defaultMediaIndex = cps.getDefaultMediaIndex(); - rawResolutions = cps.getRawResolutions(); + if (ppdResolutions == null) { + ppdResolutions = cps.getRawResolutions(); + } } urlConnection.disconnect(); init = true; @@ -821,14 +822,7 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService } } } else if (category == PrinterResolution.class) { - PrinterResolution[] supportedRes = getPrintResolutions(); - if (supportedRes == null) { - return null; - } - PrinterResolution []arr = - new PrinterResolution[supportedRes.length]; - System.arraycopy(supportedRes, 0, arr, 0, supportedRes.length); - return arr; + return getPrintResolutions(); } else if (category == OutputBin.class) { return Arrays.copyOf(outputBins, outputBins.length); } @@ -1137,8 +1131,6 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService catList.add(Chromaticity.class); } - // CUPS does not report printer resolution via IPP but it - // may be gleaned from the PPD. PrinterResolution[] supportedRes = getPrintResolutions(); if (supportedRes != null && (supportedRes.length > 0)) { catList.add(PrinterResolution.class); @@ -1264,7 +1256,6 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService } } - @Override public synchronized PrintServiceAttributeSet getAttributes() { if (!init) { @@ -1684,9 +1675,7 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService } else if (category == PrinterResolution.class) { PrinterResolution[] supportedRes = getPrintResolutions(); if ((supportedRes != null) && (supportedRes.length > 0)) { - return supportedRes[0]; - } else { - return new PrinterResolution(300, 300, PrinterResolution.DPI); + return supportedRes[0]; } } else if (category == OutputBin.class) { if (attribClass != null) { @@ -1697,26 +1686,40 @@ public final class IPPPrintService implements PrintService, SunPrinterJobService return null; } + /* Called only from contexts that have called initAttributes(). + * Try IPP first, and if that produces nothing, fall back to the PPD + */ private PrinterResolution[] getPrintResolutions() { + int[] rawResolutions = null; if (printerResolutions == null) { - if (rawResolutions == null) { - printerResolutions = new PrinterResolution[0]; - } else { - int numRes = rawResolutions.length / 2; - PrinterResolution[] pres = new PrinterResolution[numRes]; - for (int i=0; i < numRes; i++) { - pres[i] = new PrinterResolution(rawResolutions[i*2], - rawResolutions[i*2+1], - PrinterResolution.DPI); - } - printerResolutions = pres; + AttributeClass attribClass = (getAttMap != null) ? + getAttMap.get("printer-resolution-supported") + : null; + if (attribClass != null) { + rawResolutions = attribClass.getIntResolutionValue(); } + if (rawResolutions == null) { + rawResolutions = ppdResolutions; + } + if (rawResolutions == null) { + rawResolutions = new int[] { 300, 300, 3 } ; + } + int numRes = rawResolutions.length / 3; + PrinterResolution[] pres = new PrinterResolution[numRes]; + for (int i = 0; i < numRes; i++) { + int units = (rawResolutions[i*3+2] == 4) ? PrinterResolution.DPCM : PrinterResolution.DPI; + pres[i] = new PrinterResolution(rawResolutions[i*3], + rawResolutions[i*3+1], + units); + } + printerResolutions = pres; } - return printerResolutions; + return printerResolutions.clone(); } private boolean isSupportedResolution(PrinterResolution res) { - PrinterResolution[] supportedRes = getPrintResolutions(); + PrinterResolution[] supportedRes = + (PrinterResolution[])getSupportedAttributeValues(PrinterResolution.class, null, null); if (supportedRes != null) { for (int i=0; iNewObject(env, intCls, intCtr, 3); + CHECK_NULL(dpi); // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. // unlink() must be called to remove the file after using it. @@ -672,6 +691,7 @@ Java_sun_print_CUPSPrinter_getResolutions(JNIEnv *env, CHECK_NULL(ryObj); (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, rxObj); (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, ryObj); + (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, dpi); } for (i = 0; i < resolution->num_choices; i++) { @@ -700,6 +720,41 @@ Java_sun_print_CUPSPrinter_getResolutions(JNIEnv *env, CHECK_NULL(ryObj); (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, rxObj); (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, ryObj); + (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, dpi); + } + } + + } else { + ppd_attr_t *defresolution = j2d_ppdFindAttr(ppd, "DefaultResolution", NULL); + if (defresolution == NULL) { + defresolution = j2d_ppdFindAttr(ppd, "Resolution", NULL); + } + if (defresolution != NULL) { + int matches = sscanf(defresolution->value, "%dx%ddpi", &defx, &defy); + if (matches == 2) { + if (defx <= 0 || defy <= 0) { + defx = 0; + defy = 0; + } + } else { + matches = sscanf(defresolution->value, "%ddpi", &defx); + if (matches == 1) { + if (defx <= 0) { + defx = 0; + } else { + defy = defx; + } + } + } + if (defx > 0) { + jobject rxObj, ryObj; + rxObj = (*env)->NewObject(env, intCls, intCtr, defx); + CHECK_NULL(rxObj); + ryObj = (*env)->NewObject(env, intCls, intCtr, defy); + CHECK_NULL(ryObj); + (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, rxObj); + (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, ryObj); + (*env)->CallBooleanMethod(env, arrayList, arrListAddMID, dpi); } } } diff --git a/src/jdk.compiler/share/data/symbols/java.base-Q.sym.txt b/src/jdk.compiler/share/data/symbols/java.base-Q.sym.txt index 29ecd9f0304..9166b505c51 100644 --- a/src/jdk.compiler/share/data/symbols/java.base-Q.sym.txt +++ b/src/jdk.compiler/share/data/symbols/java.base-Q.sym.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2025, 2026, 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 @@ -429,6 +429,10 @@ innerclass innerClass java/io/ObjectOutputStream$PutField outerClass java/io/Obj innerclass innerClass java/util/AbstractMap$SimpleImmutableEntry outerClass java/util/AbstractMap innerClassName SimpleImmutableEntry flags 9 innerclass innerClass java/util/concurrent/ConcurrentHashMap$CollectionView outerClass java/util/concurrent/ConcurrentHashMap innerClassName CollectionView flags 408 +class name java/util/concurrent/CopyOnWriteArraySet +header extends java/util/AbstractSet implements java/io/Serializable flags 21 signature Ljava/util/AbstractSet;Ljava/io/Serializable; +innerclass innerClass java/io/ObjectInputStream$GetField outerClass java/io/ObjectInputStream innerClassName GetField flags 409 + class name java/util/concurrent/StructuredTaskScope -method name open descriptor (Ljava/util/concurrent/StructuredTaskScope$Joiner;Ljava/util/function/Function;)Ljava/util/concurrent/StructuredTaskScope; method name open descriptor (Ljava/util/concurrent/StructuredTaskScope$Joiner;Ljava/util/function/UnaryOperator;)Ljava/util/concurrent/StructuredTaskScope; flags 9 signature (Ljava/util/concurrent/StructuredTaskScope$Joiner<-TT;+TR;>;Ljava/util/function/UnaryOperator;)Ljava/util/concurrent/StructuredTaskScope; diff --git a/src/jdk.hotspot.agent/linux/native/libsaproc/symtab.c b/src/jdk.hotspot.agent/linux/native/libsaproc/symtab.c index 07cbb46d045..c8f3fb2ed4c 100644 --- a/src/jdk.hotspot.agent/linux/native/libsaproc/symtab.c +++ b/src/jdk.hotspot.agent/linux/native/libsaproc/symtab.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2026, 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 @@ -550,14 +550,33 @@ uintptr_t search_symbol(struct symtab* symtab, uintptr_t base, return (uintptr_t) NULL; } +static bool is_in(uintptr_t offset, struct elf_symbol* sym) { + if (sym->size == 0 && offset == sym->offset) { + // offset points to the top of the symbol. + // Some functions have size 0. For example, __restore_rt() (signal trampoline + // in glibc) would be detected as out of the function incorrectly, even if it + // points to the top of the instruction address, because the size of + // __restore_rt() is 0 (you can see this with "readelf -s libc.so.6" when + // debug symbols are available). + // Hence we need to treat this as a special case if the function size is 0, + // only the exact symbol address should be treated as inside. + return true; + } else if (offset >= sym->offset && offset < sym->offset + sym->size) { + // offset is in address range of the symbol + return true; + } + + // offset is out of address range of the symbol + return false; +} + const char* nearest_symbol(struct symtab* symtab, uintptr_t offset, uintptr_t* poffset) { int n = 0; if (!symtab) return NULL; for (; n < symtab->num_symbols; n++) { struct elf_symbol* sym = &(symtab->symbols[n]); - if (sym->name != NULL && - offset >= sym->offset && offset < sym->offset + sym->size) { + if (sym->name != NULL && is_in(offset, sym)) { if (poffset) *poffset = (offset - sym->offset); return sym->name; } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebugger.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebugger.java index 1106d846eca..a53b8a0a282 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebugger.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebugger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2026, 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 @@ -33,6 +33,14 @@ import sun.jvm.hotspot.debugger.cdbg.*; by the architecture-specific subpackages. */ public interface LinuxDebugger extends JVMDebugger { + // SIGHANDLER_NAMES holds the name of signal handler. + public static final List SIGHANDLER_NAMES = List.of( + // For AMD64 + // - sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c in glibc + // - gdb/amd64-linux-tdep.c in GDB + "__restore_rt" + ); + public String addressValueToString(long address) throws DebuggerException; public boolean readJBoolean(long address) throws DebuggerException; public byte readJByte(long address) throws DebuggerException; @@ -52,6 +60,7 @@ public interface LinuxDebugger extends JVMDebugger { public long[] getThreadIntegerRegisterSet(int lwp_id) throws DebuggerException; public long getAddressValue(Address addr) throws DebuggerException; public Address findLibPtrByAddress(Address pc); + public boolean isSignalTrampoline(Address pc); // For LinuxCDebugger public List getThreadList(); diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java index 261df12c8f1..9a75511e44d 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/LinuxDebuggerLocal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2026, 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 @@ -130,6 +130,12 @@ public class LinuxDebuggerLocal extends DebuggerBase implements LinuxDebugger { : new LinuxAddress(this, ptr); } + @Override + public boolean isSignalTrampoline(Address pc) { + var sym = lookup(getAddressValue(pc)); + return sym == null ? false : SIGHANDLER_NAMES.contains(sym.getName()); + } + // Note on Linux threads are really processes. When target process is // attached by a serviceability agent thread, only that thread can do // ptrace operations on the target. This is because from kernel's point diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64CFrame.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64CFrame.java index 612203634f3..4bf6a0305a3 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64CFrame.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64CFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2026, 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 @@ -24,9 +24,12 @@ package sun.jvm.hotspot.debugger.linux.amd64; +import java.util.function.Function; + import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.amd64.*; import sun.jvm.hotspot.debugger.linux.*; +import sun.jvm.hotspot.debugger.linux.amd64.*; import sun.jvm.hotspot.debugger.cdbg.*; import sun.jvm.hotspot.debugger.cdbg.basic.*; import sun.jvm.hotspot.runtime.*; @@ -34,6 +37,36 @@ import sun.jvm.hotspot.runtime.amd64.*; public final class LinuxAMD64CFrame extends BasicCFrame { + private static LinuxAMD64CFrame getFrameFromReg(LinuxDebugger dbg, Function getreg) { + Address rip = getreg.apply(AMD64ThreadContext.RIP); + Address rsp = getreg.apply(AMD64ThreadContext.RSP); + Address libptr = dbg.findLibPtrByAddress(rip); + Address cfa = getreg.apply(AMD64ThreadContext.RBP); + DwarfParser dwarf = null; + + if (libptr != null) { // Native frame + dwarf = new DwarfParser(libptr); + try { + dwarf.processDwarf(rip); + } catch (DebuggerException e) { + // DWARF processing should succeed when the frame is native + // but it might fail if Common Information Entry (CIE) has language + // personality routine and/or Language Specific Data Area (LSDA). + return new LinuxAMD64CFrame(dbg, rsp, cfa, rip, dwarf, true); + } + + cfa = getreg.apply(dwarf.getCFARegister()) + .addOffsetTo(dwarf.getCFAOffset()); + } + + return (cfa == null) ? null + : new LinuxAMD64CFrame(dbg, rsp, cfa, rip, dwarf); + } + + public static LinuxAMD64CFrame getTopFrame(LinuxDebugger dbg, Address rip, ThreadContext context) { + return getFrameFromReg(dbg, context::getRegisterAsAddress); + } + public static LinuxAMD64CFrame getTopFrame(LinuxDebugger dbg, Address rsp, Address rip, ThreadContext context) { Address libptr = dbg.findLibPtrByAddress(rip); Address cfa = context.getRegisterAsAddress(AMD64ThreadContext.RBP); @@ -80,8 +113,12 @@ public final class LinuxAMD64CFrame extends BasicCFrame { // override base class impl to avoid ELF parsing public ClosestSymbol closestSymbolToPC() { Address symAddr = use1ByteBeforeToLookup ? pc().addOffsetTo(-1) : pc(); - // try native lookup in debugger. - return dbg.lookup(dbg.getAddressValue(symAddr)); + + // Returns a special symbol if the address is signal handler, + // otherwise returns closest symbol generated by LinuxDebugger. + return dbg.isSignalTrampoline(symAddr) + ? new ClosestSymbol("", 0) + : dbg.lookup(dbg.getAddressValue(symAddr)); } public Address pc() { @@ -159,7 +196,12 @@ public final class LinuxAMD64CFrame extends BasicCFrame { return null; } - return isValidFrame(nextCFA, isNative) ? nextCFA : null; + if (dbg.isSignalTrampoline(senderPC)) { + // Return without frame check if sender is signal trampoline. + return nextCFA; + } else { + return isValidFrame(nextCFA, isNative) ? nextCFA : null; + } } @Override @@ -173,6 +215,12 @@ public final class LinuxAMD64CFrame extends BasicCFrame { return null; } + if (dbg.isSignalTrampoline(pc())) { + // RSP points signal context + // https://github.com/torvalds/linux/blob/v6.17/arch/x86/kernel/signal.c#L94 + return getFrameFromReg(dbg, r -> LinuxAMD64ThreadContext.getRegFromSignalTrampoline(this.rsp, r.intValue())); + } + ThreadContext context = th.getContext(); Address nextRSP = sp != null ? sp : getNextRSP(); diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64ThreadContext.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64ThreadContext.java index 3884bab796b..8b2a7301cf2 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64ThreadContext.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/linux/amd64/LinuxAMD64ThreadContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2026, 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 @@ -27,6 +27,7 @@ package sun.jvm.hotspot.debugger.linux.amd64; import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.amd64.*; import sun.jvm.hotspot.debugger.linux.*; +import sun.jvm.hotspot.runtime.*; public class LinuxAMD64ThreadContext extends AMD64ThreadContext { private LinuxDebugger debugger; @@ -43,4 +44,23 @@ public class LinuxAMD64ThreadContext extends AMD64ThreadContext { public Address getRegisterAsAddress(int index) { return debugger.newAddress(getRegister(index)); } + + public static Address getRegFromSignalTrampoline(Address sp, int index) { + // ucontext_t is located at top of stack. + // See definition of rt_sigframe in arch/x86/include/asm/sigframe.h + // in Linux Kernel. + Address addrUCMContext = sp.addOffsetTo(40); // offsetof(ucontext_t, uc_mcontext) = 40 + Address addrGRegs = addrUCMContext; // gregs is located at top of ucontext_t + + // They are from sys/ucontext.h + final int REG_RBP = 10; + final int REG_RSP = 15; + final int REG_RIP = 16; + return switch(index) { + case AMD64ThreadContext.RBP -> addrGRegs.getAddressAt(REG_RBP * VM.getVM().getAddressSize()); + case AMD64ThreadContext.RSP -> addrGRegs.getAddressAt(REG_RSP * VM.getVM().getAddressSize()); + case AMD64ThreadContext.RIP -> addrGRegs.getAddressAt(REG_RIP * VM.getVM().getAddressSize()); + default -> throw new IllegalArgumentException("Unsupported register index: " + index); + }; + } } diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java index 350931cd443..09bb0607759 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractVector.java @@ -182,7 +182,44 @@ abstract class AbstractVector extends Vector { final AbstractVector asVectorRawTemplate(LaneType laneType) { // NOTE: This assumes that convert0('X') // respects REGISTER_ENDIAN order. - return convert0('X', vspecies().withLanes(laneType)); + return convert0('X', vspecies().withLanes(laneType)).swapIfNeeded(vspecies()); + } + + @ForceInline + protected static VectorShuffle normalizeSubLanesForSpecies(AbstractSpecies targetSpecies, int subLanesPerSrc) { + final int lanes = targetSpecies.laneCount(); + + if ((lanes % subLanesPerSrc) != 0) { + throw new IllegalArgumentException("laneCount " + lanes + " not divisible by subLanesPerSrc " + subLanesPerSrc); + } + + // Each group corresponds to one source lane. + // For each group, reverse the lanes inside that group. + final int groups = lanes / subLanesPerSrc; + int[] map = new int[lanes]; + for (int g = 0; g < groups; ++g) { + int base = g * subLanesPerSrc; + for (int j = 0; j < subLanesPerSrc; ++j) { + map[base + j] = base + (subLanesPerSrc - 1 - j); + } + } + return VectorShuffle.fromArray(targetSpecies, map, 0); + } + + @ForceInline + protected final int subLanesToSwap(AbstractSpecies srcSpecies) { + if (java.nio.ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN) { + return -1; + } + int sBytes = srcSpecies.elementSize(); + int tBytes = vspecies().elementSize(); + + // No lane reordering needed for same size or widening reinterprets + if (sBytes == tBytes || (sBytes % tBytes) != 0) { + return -1; + } + int subLanesPerSrc = sBytes / tBytes; + return subLanesPerSrc; } /*package-private*/ @@ -242,6 +279,9 @@ abstract class AbstractVector extends Vector { /*package-private*/ abstract AbstractVector maybeSwap(ByteOrder bo); + /*package-private*/ + abstract AbstractVector swapIfNeeded(AbstractSpecies srcSpecies); + /*package-private*/ @ForceInline VectorShuffle swapBytesShuffle() { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java index 02e15d5f8dd..c071026a3b3 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java @@ -4101,6 +4101,14 @@ public abstract class ByteVector extends AbstractVector { return this; } + /*package-private*/ + @Override + @ForceInline + final + ByteVector swapIfNeeded(AbstractSpecies srcSpecies) { + return this; + } + static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_BYTE_INDEX_SCALE); static final long ARRAY_BASE = diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java index 08fda9c96e6..e280ca4150c 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java @@ -3612,6 +3612,18 @@ public abstract class DoubleVector extends AbstractVector { return this; } + @Override + @ForceInline + final + DoubleVector swapIfNeeded(AbstractSpecies srcSpecies) { + int subLanesPerSrc = subLanesToSwap(srcSpecies); + if (subLanesPerSrc < 0) { + return this; + } + VectorShuffle shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc); + return (DoubleVector) this.rearrange(shuffle); + } + static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_DOUBLE_INDEX_SCALE); static final long ARRAY_BASE = diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java index 0f70a2b81c8..35a8f4a78cf 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java @@ -3562,6 +3562,18 @@ public abstract class FloatVector extends AbstractVector { return this; } + @Override + @ForceInline + final + FloatVector swapIfNeeded(AbstractSpecies srcSpecies) { + int subLanesPerSrc = subLanesToSwap(srcSpecies); + if (subLanesPerSrc < 0) { + return this; + } + VectorShuffle shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc); + return (FloatVector) this.rearrange(shuffle); + } + static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_FLOAT_INDEX_SCALE); static final long ARRAY_BASE = diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java index 23e703dcada..f340aed4fce 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java @@ -3720,6 +3720,18 @@ public abstract class IntVector extends AbstractVector { return this; } + @Override + @ForceInline + final + IntVector swapIfNeeded(AbstractSpecies srcSpecies) { + int subLanesPerSrc = subLanesToSwap(srcSpecies); + if (subLanesPerSrc < 0) { + return this; + } + VectorShuffle shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc); + return (IntVector) this.rearrange(shuffle); + } + static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_INT_INDEX_SCALE); static final long ARRAY_BASE = diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java index 58bfd4d7772..b842bdebdc4 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java @@ -3655,6 +3655,18 @@ public abstract class LongVector extends AbstractVector { return this; } + @Override + @ForceInline + final + LongVector swapIfNeeded(AbstractSpecies srcSpecies) { + int subLanesPerSrc = subLanesToSwap(srcSpecies); + if (subLanesPerSrc < 0) { + return this; + } + VectorShuffle shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc); + return (LongVector) this.rearrange(shuffle); + } + static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_LONG_INDEX_SCALE); static final long ARRAY_BASE = diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java index 7ab7e7c4417..8b4c9bc5a77 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java @@ -4074,6 +4074,18 @@ public abstract class ShortVector extends AbstractVector { return this; } + @Override + @ForceInline + final + ShortVector swapIfNeeded(AbstractSpecies srcSpecies) { + int subLanesPerSrc = subLanesToSwap(srcSpecies); + if (subLanesPerSrc < 0) { + return this; + } + VectorShuffle shuffle = normalizeSubLanesForSpecies(this.vspecies(), subLanesPerSrc); + return (ShortVector) this.rearrange(shuffle); + } + static final int ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(Unsafe.ARRAY_SHORT_INDEX_SCALE); static final long ARRAY_BASE = diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/stylesheet.css b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/stylesheet.css index 53b9d8ca6b2..6198df5c2f3 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/stylesheet.css +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/stylesheet.css @@ -163,6 +163,13 @@ \ '); --current-theme-svg: url("moon.svg"); + div.block a[href], div.horizontal-scroll a[href], div.inherited-list h3 a[href], header > div a[href], + .hierarchy a[href], .index a[href], div.caption a[href], .sub-title a[href], .deprecation-comment a[href], + .serialized-class-details a[href] { + text-decoration: underline; + text-decoration-thickness: 0.02em; + text-underline-offset: 0.12em; + } } /* * Styles for individual HTML elements. diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java index 825672cfe6d..3baae08eed6 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -248,8 +248,8 @@ public class JlinkTask { * Read the release.txt from the module. */ private static Optional getReleaseInfo(ModuleReference mref) { - try { - Optional release = mref.open().open(JDK_RELEASE_RESOURCE); + try (var moduleReader = mref.open()) { + Optional release = moduleReader.open(JDK_RELEASE_RESOURCE); if (release.isEmpty()) { return Optional.empty(); diff --git a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java index d5b44b569a4..1cf0c85702f 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -43,7 +43,6 @@ import com.sun.source.tree.NewClassTree; import com.sun.source.tree.Scope; import com.sun.source.tree.Tree; import com.sun.source.tree.Tree.Kind; -import static com.sun.source.tree.Tree.Kind.METHOD; import com.sun.source.tree.TypeParameterTree; import com.sun.source.tree.VariableTree; import com.sun.source.tree.YieldTree; @@ -81,6 +80,7 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.function.Predicate; +import java.util.TreeSet; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -114,7 +114,6 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Optional; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.BiConsumer; @@ -149,14 +148,10 @@ import javax.tools.JavaFileManager.Location; import javax.tools.StandardLocation; import jdk.jshell.ExpressionToTypeInfo.ExpressionInfo; -import static jdk.jshell.Util.REPL_DOESNOTMATTER_CLASS_NAME; import static jdk.jshell.SourceCodeAnalysis.Completeness.DEFINITELY_INCOMPLETE; import static jdk.jshell.TreeDissector.printType; import static java.util.stream.Collectors.joining; -import static javax.lang.model.element.ElementKind.CONSTRUCTOR; -import static javax.lang.model.element.ElementKind.MODULE; -import static javax.lang.model.element.ElementKind.PACKAGE; import javax.lang.model.type.IntersectionType; import javax.lang.model.util.Elements; @@ -815,7 +810,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis { }; String wrappedCode = codeWrap.wrapped(); return this.proc.taskFactory.analyze(codeWrap, task -> { - List result = new ArrayList<>(); + TreeSet result = new TreeSet<>(Comparator.comparing(Highlight::start).thenComparing(Highlight::end)); CompilationUnitTree cut = task.cuTrees().iterator().next(); Trees trees = task.trees(); SourcePositions sp = trees.getSourcePositions(); @@ -1050,8 +1045,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis { } }.scan(cut, null); result.removeIf(h -> h.start() == h.end()); - Collections.sort(result, (h1, h2) -> h1.start() - h2.start()); - return result; + return new ArrayList<>(result); }); } diff --git a/test/hotspot/gtest/gc/g1/test_g1CardSetContainers.cpp b/test/hotspot/gtest/gc/g1/test_g1CardSetContainers.cpp index d83d8ffeef6..91951b35405 100644 --- a/test/hotspot/gtest/gc/g1/test_g1CardSetContainers.cpp +++ b/test/hotspot/gtest/gc/g1/test_g1CardSetContainers.cpp @@ -25,6 +25,7 @@ #include "gc/g1/g1HeapRegionBounds.inline.hpp" #include "gc/shared/cardTable.hpp" #include "memory/allocation.inline.hpp" +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/powerOfTwo.hpp" #include "unittest.hpp" @@ -82,48 +83,48 @@ void G1CardSetContainersTest::cardset_inlineptr_test(uint bits_per_card) { G1AddCardResult res; - G1CardSet::ContainerPtr value = G1CardSetInlinePtr(); + Atomic value{}; for (uint i = 0; i < CardsPerSet; i++) { { - G1CardSetInlinePtr cards(&value, value); + G1CardSetInlinePtr cards(&value, value.load_relaxed()); res = cards.add(i + 1, bits_per_card, CardsPerSet); ASSERT_TRUE(res == Added); } { - G1CardSetInlinePtr cards(&value, value); + G1CardSetInlinePtr cards(&value, value.load_relaxed()); ASSERT_TRUE(cards.contains(i + 1, bits_per_card)); } } for (uint i = 0; i < CardsPerSet; i++) { - G1CardSetInlinePtr cards(value); + G1CardSetInlinePtr cards(value.load_relaxed()); ASSERT_TRUE(cards.contains(i + 1, bits_per_card)); } // Try to add again, should all return that the card had been added. for (uint i = 0; i < CardsPerSet; i++) { - G1CardSetInlinePtr cards(&value, value); + G1CardSetInlinePtr cards(&value, value.load_relaxed()); res = cards.add(i + 1, bits_per_card, CardsPerSet); ASSERT_TRUE(res == Found); } // Should be no more space in set. { - G1CardSetInlinePtr cards(&value, value); + G1CardSetInlinePtr cards(&value, value.load_relaxed()); res = cards.add(CardsPerSet + 1, bits_per_card, CardsPerSet); ASSERT_TRUE(res == Overflow); } // Cards should still be in the set. for (uint i = 0; i < CardsPerSet; i++) { - G1CardSetInlinePtr cards(value); + G1CardSetInlinePtr cards(value.load_relaxed()); ASSERT_TRUE(cards.contains(i + 1, bits_per_card)); } // Boundary cards should not be in the set. { - G1CardSetInlinePtr cards(value); + G1CardSetInlinePtr cards(value.load_relaxed()); ASSERT_TRUE(!cards.contains(0, bits_per_card)); ASSERT_TRUE(!cards.contains(CardsPerSet + 1, bits_per_card)); } @@ -131,7 +132,7 @@ void G1CardSetContainersTest::cardset_inlineptr_test(uint bits_per_card) { // Verify iteration finds all cards too and only those. { G1FindCardsInRange found(1, CardsPerSet); - G1CardSetInlinePtr cards(value); + G1CardSetInlinePtr cards(value.load_relaxed()); cards.iterate(found, bits_per_card); found.verify_all_found(); } diff --git a/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp b/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp index b2acf45c470..c98b38b8c3c 100644 --- a/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp +++ b/test/hotspot/gtest/utilities/test_metaspaceClosure.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -21,6 +21,7 @@ * questions. */ +#include "cds/aotGrowableArray.inline.hpp" #include "memory/allocation.hpp" #include "memory/metadataFactory.hpp" #include "memory/metaspaceClosure.hpp" @@ -58,7 +59,7 @@ public: class MyUniqueMetaspaceClosure : public MetaspaceClosure { static constexpr int SIZE = 10; - MyMetaData* _visited[SIZE]; + void* _visited[SIZE]; int _count; public: MyUniqueMetaspaceClosure() { @@ -71,11 +72,22 @@ public: virtual bool do_ref(Ref* ref, bool read_only) { MyMetaData* ptr = (MyMetaData*)ref->obj(); assert(_count < SIZE, "out of bounds"); - _visited[_count++] = ptr; + for (int i = 0; i < _count; i++) { + if (_visited[i] == (void*)ptr) { + // We have walked this before. + return false; + } + } + + // Found a new pointer. Let's walk it + _visited[_count++] = (void*)ptr; return true; // recurse } bool has_visited(MyMetaData* p) { + return has_visited((void*)p); + } + bool has_visited(void* p) { for (int i = 0; i < SIZE; i++) { if (_visited[i] == p) { return true; @@ -83,6 +95,9 @@ public: } return false; } + int visited_count() { + return _count; + } }; // iterate an Array @@ -104,7 +119,9 @@ TEST_VM(MetaspaceClosure, MSOPointerArrayRef) { MyUniqueMetaspaceClosure closure; closure.push(&array); + closure.finish(); + EXPECT_TRUE(closure.has_visited(array)) << "must be"; EXPECT_TRUE(closure.has_visited(&x)) << "must be"; EXPECT_TRUE(closure.has_visited(&y)) << "must be"; EXPECT_TRUE(closure.has_visited(&z)) << "must be"; @@ -130,8 +147,85 @@ TEST_VM(MetaspaceClosure, MSOArrayRef) { MyUniqueMetaspaceClosure closure; closure.push(&array); + closure.finish(); + EXPECT_TRUE(closure.has_visited(array)) << "must be"; EXPECT_TRUE(closure.has_visited(&x)) << "must be"; EXPECT_TRUE(closure.has_visited(&y)) << "must be"; EXPECT_TRUE(closure.has_visited(&z)) << "must be"; } + +// iterate an Array +TEST_VM(MetaspaceClosure, OtherArrayRef) { + JavaThread* THREAD = JavaThread::current(); + ClassLoaderData* cld = ClassLoaderData::the_null_class_loader_data(); + Array* array = MetadataFactory::new_array(cld, 4, THREAD); + + MyUniqueMetaspaceClosure closure; + closure.push(&array); + closure.finish(); + + EXPECT_TRUE(closure.has_visited(array)) << "must be"; +} + +// iterate an AOTGrowableArray +TEST_VM(MetaspaceClosure, GrowableArray_MSOPointer) { + AOTGrowableArray* array = new(mtClass) AOTGrowableArray(2, mtClass); + + MyMetaData x; + MyMetaData y; + MyMetaData z; + + array->push(&x); + array->push(&y); + y._a = &z; + + MyUniqueMetaspaceClosure closure; + closure.push(&array); + closure.finish(); + + EXPECT_TRUE(closure.has_visited(array)) << "must be"; + EXPECT_TRUE(closure.has_visited(&x)) << "must be"; + EXPECT_TRUE(closure.has_visited(&y)) << "must be"; + EXPECT_TRUE(closure.has_visited(&z)) << "must be"; +} + +// iterate an AOTGrowableArray +TEST_VM(MetaspaceClosure, GrowableArray_MSO) { + AOTGrowableArray* array = new(mtClass) AOTGrowableArray(4, mtClass); + + for (int i = 0; i < array->length(); i++) { + EXPECT_TRUE(array->at(i)._a == nullptr) << "should be initialized to null"; + EXPECT_TRUE(array->at(i)._b == nullptr) << "should be initialized to null"; + } + + MyMetaData x; + MyMetaData y; + MyMetaData z; + + z._a = &x; + z._b = &y; + y._a = &z; + array->push(z); + + MyUniqueMetaspaceClosure closure; + closure.push(&array); + closure.finish(); + + EXPECT_TRUE(closure.has_visited(array)) << "must be"; + EXPECT_TRUE(closure.has_visited(&x)) << "must be"; + EXPECT_TRUE(closure.has_visited(&y)) << "must be"; + EXPECT_TRUE(closure.has_visited(&z)) << "must be"; +} + +// iterate an AOTGrowableArray +TEST_VM(MetaspaceClosure, GrowableArray_jlong) { + AOTGrowableArray* array = new(mtClass) AOTGrowableArray(4, mtClass); + + MyUniqueMetaspaceClosure closure; + closure.push(&array); + closure.finish(); + + EXPECT_TRUE(closure.has_visited(array)) << "must be"; + EXPECT_TRUE(closure.visited_count() == 2) << "must visit buffer inside GrowableArray"; +} diff --git a/test/hotspot/jtreg/ProblemList-AotJdk.txt b/test/hotspot/jtreg/ProblemList-AotJdk.txt index af3994289df..e27e85645f5 100644 --- a/test/hotspot/jtreg/ProblemList-AotJdk.txt +++ b/test/hotspot/jtreg/ProblemList-AotJdk.txt @@ -1,3 +1,32 @@ +# +# Copyright (c) 2024, 2026, 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. +# + +############################################################################# +# +# List of quarantined tests for testing in AOT_JDK mode. +# +############################################################################# + runtime/modules/PatchModule/PatchModuleClassList.java 0000000 generic-all runtime/NMT/NMTWithCDS.java 0000000 generic-all runtime/symbols/TestSharedArchiveConfigFile.java 0000000 generic-all diff --git a/test/hotspot/jtreg/compiler/c2/gvn/CmpUNodeValueTests.java b/test/hotspot/jtreg/compiler/c2/gvn/CmpUNodeValueTests.java new file mode 100644 index 00000000000..cbcbda3422f --- /dev/null +++ b/test/hotspot/jtreg/compiler/c2/gvn/CmpUNodeValueTests.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2026, 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. + */ +package compiler.c2.gvn; + +import compiler.lib.generators.Generators; +import compiler.lib.ir_framework.*; +import jdk.test.lib.Asserts; + +/* + * @test + * @bug 8375653 + * @summary Test that Value computations of CmpUNode are being performed as expected. + * @library /test/lib / + * @run driver ${test.main.class} + */ +public class CmpUNodeValueTests { + public static void main(String[] args) { + TestFramework.run(); + } + + @DontInline + public static int one() { + return 1; + } + + // Move to a separate method to prevent javac folding the constant comparison + @ForceInline + public static int oneInline() { + return 1; + } + + @Run(test = {"testIntControl", "testIntLT", "testIntLE", "testIntGT", "testIntGE", "testIntEQ", "testIntNE", + "testLongControl", "testLongLT", "testLongLE", "testLongGT", "testLongGE", "testLongEQ", "testLongNE"}) + public void run() { + var stream = Generators.G.longs(); + long x = stream.next(); + long y = stream.next(); + + Asserts.assertEQ(0, testIntControl(false, false)); + Asserts.assertEQ(0, testIntControl(false, true)); + Asserts.assertEQ(0, testIntControl(true, false)); + Asserts.assertEQ(1, testIntControl(true, true)); + Asserts.assertEQ(0, testIntLT((int) x)); + Asserts.assertEQ(0, testIntLE(false, false)); + Asserts.assertEQ(0, testIntLE(false, true)); + Asserts.assertEQ(0, testIntLE(true, false)); + Asserts.assertEQ(0, testIntLE(true, true)); + Asserts.assertEQ(0, testIntGT(false, false)); + Asserts.assertEQ(0, testIntGT(false, true)); + Asserts.assertEQ(0, testIntGT(true, false)); + Asserts.assertEQ(0, testIntGT(true, true)); + Asserts.assertEQ(0, testIntGE((int) x, (int) y)); + Asserts.assertEQ(0, testIntEQ()); + Asserts.assertEQ(0, testIntNE(false, false)); + Asserts.assertEQ(0, testIntNE(false, true)); + Asserts.assertEQ(0, testIntNE(true, false)); + Asserts.assertEQ(0, testIntNE(true, true)); + + Asserts.assertEQ(0, testLongControl(false, false)); + Asserts.assertEQ(0, testLongControl(false, true)); + Asserts.assertEQ(0, testLongControl(true, false)); + Asserts.assertEQ(1, testLongControl(true, true)); + Asserts.assertEQ(0, testLongLT((int) x, false)); + Asserts.assertEQ(0, testLongLT((int) x, true)); + Asserts.assertEQ(0, testLongLE(false, false)); + Asserts.assertEQ(0, testLongLE(false, true)); + Asserts.assertEQ(0, testLongLE(true, false)); + Asserts.assertEQ(0, testLongLE(true, true)); + Asserts.assertEQ(0, testLongGT(false, false)); + Asserts.assertEQ(0, testLongGT(false, true)); + Asserts.assertEQ(0, testLongGT(true, false)); + Asserts.assertEQ(0, testLongGT(true, true)); + Asserts.assertEQ(0, testLongGE((int) x, (int) y)); + Asserts.assertEQ(0, testLongEQ()); + Asserts.assertEQ(0, testLongNE(false, false)); + Asserts.assertEQ(0, testLongNE(false, true)); + Asserts.assertEQ(0, testLongNE(true, false)); + Asserts.assertEQ(0, testLongNE(true, true)); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, counts = {IRNode.CMP_U, "1"}) + int testIntControl(boolean b1, boolean b2) { + int v1 = b1 ? 1 : -1; + int v2 = b2 ? 1 : 0; + return Integer.compareUnsigned(v1, v2) > 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_U, IRNode.CALL}) + int testIntLT(int x) { + int v1 = x & Integer.MAX_VALUE; // Unset the highest bit, make v1 non-negative + int v2 = Integer.MIN_VALUE; + return Integer.compareUnsigned(v1, v2) < 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_U, IRNode.CALL}) + int testIntLE(boolean b1, boolean b2) { + int v1 = b1 ? 2 : 0; + int v2 = b2 ? -1 : 2; + return Integer.compareUnsigned(v1, v2) <= 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_U, IRNode.CALL}) + int testIntGT(boolean b1, boolean b2) { + int v1 = b1 ? Integer.MIN_VALUE : Integer.MAX_VALUE; + int v2 = b2 ? 0 : 2; + return Integer.compareUnsigned(v1, v2) > 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_U, IRNode.CALL}) + int testIntGE(int x, int y) { + int v1 = x | Integer.MIN_VALUE; // Set the highest bit, make v1 negative + int v2 = y & Integer.MAX_VALUE; // Unset the highest bit, make v2 non-negative + return Integer.compareUnsigned(v1, v2) >= 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_U, IRNode.CALL}) + int testIntEQ() { + return Integer.compareUnsigned(oneInline(), 1) == 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_U, IRNode.CALL}) + int testIntNE(boolean b1, boolean b2) { + int v1 = b1 ? 1 : -1; + int v2 = b2 ? 0 : 2; + return Integer.compareUnsigned(v1, v2) != 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, counts = {IRNode.CMP_UL, "1"}) + int testLongControl(boolean b1, boolean b2) { + long v1 = b1 ? 1 : -1; + long v2 = b2 ? 1 : 0; + return Long.compareUnsigned(v1, v2) > 0 ? 0 : one(); + } + + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_UL, IRNode.CALL}) + int testLongLT(int x, boolean b2) { + long v1 = Integer.toUnsignedLong(x); + long v2 = Integer.MIN_VALUE; + return Long.compareUnsigned(v1, v2) < 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_UL, IRNode.CALL}) + int testLongLE(boolean b1, boolean b2) { + long v1 = b1 ? 2 : 0; + long v2 = b2 ? -1 : 2; + return Long.compareUnsigned(v1, v2) <= 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_UL, IRNode.CALL}) + int testLongGT(boolean b1, boolean b2) { + long v1 = b1 ? Long.MIN_VALUE : Long.MAX_VALUE; + long v2 = b2 ? 0 : 2; + return Long.compareUnsigned(v1, v2) > 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_UL, IRNode.CALL}) + int testLongGE(int x, int y) { + long v1 = x | Long.MIN_VALUE; // Set the highest bit, make v1 negative + long v2 = y & Long.MAX_VALUE; // Unset the highest bit, make v2 non-negative + return Long.compareUnsigned(v1, v2) >= 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_UL, IRNode.CALL}) + int testLongEQ() { + return Long.compareUnsigned(oneInline(), 1L) == 0 ? 0 : one(); + } + + @Test + @IR(applyIfPlatformOr = {"x64", "true", "aarch64", "true"}, failOn = {IRNode.CMP_UL, IRNode.CALL}) + int testLongNE(boolean b1, boolean b2) { + long v1 = b1 ? 1 : -1; + long v2 = b2 ? 0 : 2; + return Long.compareUnsigned(v1, v2) != 0 ? 0 : one(); + } +} diff --git a/test/hotspot/jtreg/compiler/ccp/TestCmpUMonotonicity.java b/test/hotspot/jtreg/compiler/ccp/TestCmpUMonotonicity.java new file mode 100644 index 00000000000..5ebdd9469fc --- /dev/null +++ b/test/hotspot/jtreg/compiler/ccp/TestCmpUMonotonicity.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2026, 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. + */ +package compiler.ccp; + +/* + * @test + * @bug 8375653 + * @summary Test that CmpUNode::sub conforms monotonicity + * + * @run main ${test.main.class} + * @run main/othervm -Xbatch -XX:CompileCommand=compileonly,${test.main.class}::test* ${test.main.class} + */ +public class TestCmpUMonotonicity { + public static void main(String[] args) { + for (int i = 0; i < 20000; i++) { + testInt(true, 1, 100, 2); + testInt(false, 1, 100, 2); + testLong(true, 1, 100, 2); + testLong(false, 1, 100, 2); + } + } + + private static int testInt(boolean b, int start, int limit, int step) { + int v2 = b ? 1 : -1; + int v1 = 0; + for (int i = start; i < limit; i *= step) { + if (Integer.compareUnsigned(v1, v2) < 0) { + v1 = 2; + } else { + v1 = 0; + } + } + return v1; + } + + private static long testLong(boolean b, int start, int limit, int step) { + long v2 = b ? 1 : -1; + long v1 = 0; + for (int i = start; i < limit; i *= step) { + if (Long.compareUnsigned(v1, v2) < 0) { + v1 = 2; + } else { + v1 = 0; + } + } + return v1; + } +} diff --git a/test/hotspot/jtreg/compiler/corelibs/OptionalFold.java b/test/hotspot/jtreg/compiler/corelibs/OptionalFold.java new file mode 100644 index 00000000000..1f850aaf7cd --- /dev/null +++ b/test/hotspot/jtreg/compiler/corelibs/OptionalFold.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025, 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. + */ + +package compiler.corelibs; + +import java.util.Optional; + +import compiler.lib.ir_framework.Check; +import compiler.lib.ir_framework.IR; +import compiler.lib.ir_framework.IRNode; +import compiler.lib.ir_framework.Test; +import compiler.lib.ir_framework.TestFramework; + +/* + * @test + * @bug 8372696 + * @summary Verify constant folding for Optional, both present and absent + * @library /test/lib / + * @run driver ${test.main.class} + */ +public class OptionalFold { + + public static void main(String[] args) { + // Somehow fails with -XX:-TieredCompilation + TestFramework.runWithFlags("-XX:+TieredCompilation"); + } + + // Ensure both present and empty values can fold + static final Optional ONE = Optional.of(5), TWO = Optional.empty(); + + @Test + @IR(failOn = {IRNode.ADD_I}) + public int testSum() { + return ONE.orElse(7) + TWO.orElse(12); + } + + @Check(test = "testSum") + public void checkTestSum(int res) { + if (res != 5 + 12) { + throw new RuntimeException("incorrect result: " + res); + } + } + +} diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java b/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java index a536808d269..1e3ba7c314e 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -161,7 +161,7 @@ public enum CompilePhase { static { for (CompilePhase phase : CompilePhase.values()) { if (phase == PRINT_IDEAL) { - PHASES_BY_PARSED_NAME.put("print_ideal", phase); + PHASES_BY_PARSED_NAME.put("PrintIdeal", phase); } else { PHASES_BY_PARSED_NAME.put(phase.name(), phase); } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java b/test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java index 1fea5da52ef..137efd18136 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/TestFramework.java @@ -183,7 +183,7 @@ public class TestFramework { private List flags; private int defaultWarmup = -1; private boolean testClassesOnBootClassPath; - private boolean isAllowNotCompilable = false; + private boolean allowNotCompilable = false; /* * Public interface methods @@ -498,7 +498,7 @@ public class TestFramework { * and else it is ignored silently. */ public TestFramework allowNotCompilable() { - this.isAllowNotCompilable = true; + this.allowNotCompilable = true; return this; } @@ -721,7 +721,7 @@ public class TestFramework { nonWhiteListedFlags.forEach((f) -> System.out.println(" - " + f)); } - System.out.println(""); + System.out.println(); } /** @@ -860,8 +860,8 @@ public class TestFramework { private List anyNonWhitelistedJTregVMAndJavaOptsFlags() { List flags = Arrays.stream(Utils.getTestJavaOpts()) .map(s -> s.replaceFirst("-XX:[+|-]?|-(?=[^D|^e])", "")) - .collect(Collectors.toList()); - List nonWhiteListedFlags = new ArrayList(); + .toList(); + List nonWhiteListedFlags = new ArrayList<>(); for (String flag : flags) { if (flag.contains("agentpath")) { throw new SkippedException("Can't run test with -javaagent"); @@ -877,10 +877,10 @@ public class TestFramework { private void runTestVM(List additionalFlags) { TestVMProcess testVMProcess = new TestVMProcess(additionalFlags, testClass, helperClasses, defaultWarmup, - isAllowNotCompilable, testClassesOnBootClassPath); + allowNotCompilable, testClassesOnBootClassPath); if (shouldVerifyIR) { try { - TestClassParser testClassParser = new TestClassParser(testClass, isAllowNotCompilable); + TestClassParser testClassParser = new TestClassParser(testClass, allowNotCompilable); Matchable testClassMatchable = testClassParser.parse(testVMProcess.getHotspotPidFileName(), testVMProcess.getApplicableIRRules()); IRMatcher matcher = new IRMatcher(testClassMatchable); diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/TestVMProcess.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/TestVMProcess.java index a172dce1991..931d687b0bc 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/TestVMProcess.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/TestVMProcess.java @@ -38,7 +38,6 @@ import java.io.File; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; /** * This class prepares, creates, and runs the Test VM with verification of proper termination. The class also stores @@ -108,7 +107,7 @@ public class TestVMProcess { cmds.add("-XX:+UnlockDiagnosticVMOptions"); cmds.add("-XX:+WhiteBoxAPI"); // Ignore CompileCommand flags which have an impact on the profiling information. - List jtregVMFlags = Arrays.stream(Utils.getTestJavaOpts()).filter(s -> !s.contains("CompileThreshold")).collect(Collectors.toList()); + List jtregVMFlags = Arrays.stream(Utils.getTestJavaOpts()).filter(s -> !s.contains("CompileThreshold")).toList(); if (!PREFER_COMMAND_LINE_FLAGS) { cmds.addAll(jtregVMFlags); } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java index 714af5c6519..893312c5196 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/IRMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -32,6 +32,7 @@ import compiler.lib.ir_framework.driver.irmatching.Matchable; import compiler.lib.ir_framework.driver.irmatching.MatchableMatcher; import compiler.lib.ir_framework.driver.irmatching.irrule.IRRule; import compiler.lib.ir_framework.driver.irmatching.parser.VMInfo; +import compiler.lib.ir_framework.driver.network.testvm.java.IRRuleIds; import compiler.lib.ir_framework.shared.TestFormat; import compiler.lib.ir_framework.shared.TestFormatException; @@ -53,14 +54,14 @@ public class IRMethod implements IRMethodMatchable { private final Method method; private final MatchableMatcher matcher; - public IRMethod(Method method, int[] ruleIds, IR[] irAnnos, Compilation compilation, VMInfo vmInfo) { + public IRMethod(Method method, IRRuleIds irRuleIds, IR[] irAnnos, Compilation compilation, VMInfo vmInfo) { this.method = method; - this.matcher = new MatchableMatcher(createIRRules(method, ruleIds, irAnnos, compilation, vmInfo)); + this.matcher = new MatchableMatcher(createIRRules(method, irRuleIds, irAnnos, compilation, vmInfo)); } - private List createIRRules(Method method, int[] ruleIds, IR[] irAnnos, Compilation compilation, VMInfo vmInfo) { + private List createIRRules(Method method, IRRuleIds irRuleIds, IR[] irAnnos, Compilation compilation, VMInfo vmInfo) { List irRules = new ArrayList<>(); - for (int ruleId : ruleIds) { + for (int ruleId : irRuleIds) { try { irRules.add(new IRRule(ruleId, irAnnos[ruleId - 1], compilation, vmInfo)); } catch (TestFormatException e) { @@ -89,13 +90,12 @@ public class IRMethod implements IRMethodMatchable { return new IRMethodMatchResult(method, matcher.match()); } - List match; for (int i = 0; i < 10; i++) { // warm up - match = matcher.match(); + matcher.match(); } long startTime = System.nanoTime(); - match = matcher.match(); + List match = matcher.match(); long endTime = System.nanoTime(); long duration = (endTime - startTime); System.out.println("Verifying IR rules for " + name() + ": " + duration + " ns = " + (duration / 1000000) + " ms"); diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java index d74825c8d4f..cb99ea219fe 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -24,8 +24,7 @@ package compiler.lib.ir_framework.driver.irmatching.irmethod; import compiler.lib.ir_framework.IR; -import compiler.lib.ir_framework.Run; -import compiler.lib.ir_framework.RunMode; +import compiler.lib.ir_framework.Test; import java.lang.reflect.Method; diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java index 011b596cc9e..bea8dc3ab27 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/irmethod/NotCompilableIRMethodMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -23,8 +23,7 @@ package compiler.lib.ir_framework.driver.irmatching.irmethod; -import compiler.lib.ir_framework.Run; -import compiler.lib.ir_framework.RunMode; +import compiler.lib.ir_framework.Test; import compiler.lib.ir_framework.driver.irmatching.MatchResult; import compiler.lib.ir_framework.driver.irmatching.visitor.MatchResultVisitor; diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/ApplicableIRRulesParser.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/ApplicableIRRulesParser.java index 7aaf0c2b285..be44c3f3d91 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/ApplicableIRRulesParser.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/ApplicableIRRulesParser.java @@ -26,12 +26,15 @@ package compiler.lib.ir_framework.driver.irmatching.parser; import compiler.lib.ir_framework.IR; import compiler.lib.ir_framework.TestFramework; import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.HotSpotPidFileParser; +import compiler.lib.ir_framework.driver.network.testvm.java.IRRuleIds; import compiler.lib.ir_framework.shared.TestFormat; import compiler.lib.ir_framework.shared.TestFrameworkException; import compiler.lib.ir_framework.test.ApplicableIRRulesPrinter; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -75,15 +78,15 @@ public class ApplicableIRRulesParser { * assembly output in {@link HotSpotPidFileParser}. */ private void createTestMethodMap(String applicableIRRules, Class testClass) { - Map irRulesMap = parseApplicableIRRules(applicableIRRules); + Map irRulesMap = parseApplicableIRRules(applicableIRRules); createTestMethodsWithApplicableIRRules(testClass, irRulesMap); } /** * Read the Applicable IR Rules emitted by the Test VM to decide if an @IR rule must be checked for a method. */ - private Map parseApplicableIRRules(String applicableIRRules) { - Map irRulesMap = new HashMap<>(); + private Map parseApplicableIRRules(String applicableIRRules) { + Map irRulesMap = new HashMap<>(); String[] applicableIRRulesLines = getApplicableIRRulesLines(applicableIRRules); for (String s : applicableIRRulesLines) { String line = s.trim(); @@ -92,8 +95,8 @@ public class ApplicableIRRulesParser { throw new TestFrameworkException("Invalid Applicable IR Rules format. No comma found: " + splitLine[0]); } String testName = splitLine[0]; - int[] irRulesIdx = getRuleIndexes(splitLine); - irRulesMap.put(testName, irRulesIdx); + IRRuleIds irRuleIds = parseIrRulesIds(splitLine); + irRulesMap.put(testName, irRuleIds); } return irRulesMap; } @@ -116,24 +119,24 @@ public class ApplicableIRRulesParser { /** * Parse rule indexes from a single line of the Applicable IR Rules in the format: */ - private int[] getRuleIndexes(String[] splitLine) { - int[] irRulesIdx = new int[splitLine.length - 1]; + private IRRuleIds parseIrRulesIds(String[] splitLine) { + List irRuleIds = new ArrayList<>(); for (int i = 1; i < splitLine.length; i++) { try { - irRulesIdx[i - 1] = Integer.parseInt(splitLine[i]); + irRuleIds.add(Integer.parseInt(splitLine[i])); } catch (NumberFormatException e) { throw new TestFrameworkException("Invalid Applicable IR Rules format. No number found: " + splitLine[i]); } } - return irRulesIdx; + return new IRRuleIds(irRuleIds); } - private void createTestMethodsWithApplicableIRRules(Class testClass, Map irRulesMap) { + private void createTestMethodsWithApplicableIRRules(Class testClass, Map irRulesMap) { for (Method m : testClass.getDeclaredMethods()) { IR[] irAnnos = m.getAnnotationsByType(IR.class); if (irAnnos.length > 0) { // Validation of legal @IR attributes and placement of the annotation was already done in Test VM. - int[] irRuleIds = irRulesMap.get(m.getName()); + IRRuleIds irRuleIds = irRulesMap.get(m.getName()); validateIRRuleIds(m, irAnnos, irRuleIds); if (hasAnyApplicableIRRules(irRuleIds)) { testMethods.put(m.getName(), new TestMethod(m, irAnnos, irRuleIds)); @@ -142,18 +145,18 @@ public class ApplicableIRRulesParser { } } - private void validateIRRuleIds(Method m, IR[] irAnnos, int[] ids) { - TestFramework.check(ids != null, "Should find method name in validIrRulesMap for " + m); - TestFramework.check(ids.length > 0, "Did not find any rule indices for " + m); - TestFramework.check((ids[0] >= 1 || ids[0] == ApplicableIRRulesPrinter.NO_RULE_APPLIED) - && ids[ids.length - 1] <= irAnnos.length, + private void validateIRRuleIds(Method m, IR[] irAnnos, IRRuleIds irRuleIds) { + TestFramework.check(irRuleIds != null, "Should find method name in validIrRulesMap for " + m); + TestFramework.check(!irRuleIds.isEmpty(), "Did not find any rule indices for " + m); + TestFramework.check((irRuleIds.first() >= 1 || irRuleIds.first() == ApplicableIRRulesPrinter.NO_RULE_APPLIED) + && irRuleIds.last() <= irAnnos.length, "Invalid IR rule index found in validIrRulesMap for " + m); } /** * Does the list of IR rules contain any applicable IR rules for the given conditions? */ - private boolean hasAnyApplicableIRRules(int[] irRuleIds) { - return irRuleIds[0] != ApplicableIRRulesPrinter.NO_RULE_APPLIED; + private boolean hasAnyApplicableIRRules(IRRuleIds irRuleIds) { + return irRuleIds.first() != ApplicableIRRulesPrinter.NO_RULE_APPLIED; } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/IRMethodBuilder.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/IRMethodBuilder.java index d7a10acd1cd..46a237576e6 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/IRMethodBuilder.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/IRMethodBuilder.java @@ -71,9 +71,9 @@ class IRMethodBuilder { Test[] testAnnos = testMethod.method().getAnnotationsByType(Test.class); boolean allowMethodNotCompilable = allowNotCompilable || testAnnos[0].allowNotCompilable(); if (allowMethodNotCompilable) { - return new NotCompilableIRMethod(testMethod.method(), testMethod.irRuleIds().length); + return new NotCompilableIRMethod(testMethod.method(), testMethod.irRuleIds().count()); } else { - return new NotCompiledIRMethod(testMethod.method(), testMethod.irRuleIds().length); + return new NotCompiledIRMethod(testMethod.method(), testMethod.irRuleIds().count()); } } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/TestMethod.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/TestMethod.java index 43f27c80ac6..37989d8810b 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/TestMethod.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/irmatching/parser/TestMethod.java @@ -26,6 +26,7 @@ package compiler.lib.ir_framework.driver.irmatching.parser; import compiler.lib.ir_framework.IR; import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethod; import compiler.lib.ir_framework.driver.irmatching.parser.hotspot.LoggedMethod; +import compiler.lib.ir_framework.driver.network.testvm.java.IRRuleIds; import java.lang.reflect.Method; @@ -40,9 +41,9 @@ import java.lang.reflect.Method; public class TestMethod { private final Method method; private final IR[] irAnnos; - private final int[] irRuleIds; + private final IRRuleIds irRuleIds; - public TestMethod(Method m, IR[] irAnnos, int[] irRuleIds) { + public TestMethod(Method m, IR[] irAnnos, IRRuleIds irRuleIds) { this.method = m; this.irAnnos = irAnnos; this.irRuleIds = irRuleIds; @@ -56,7 +57,7 @@ public class TestMethod { return irAnnos; } - public int[] irRuleIds() { + public IRRuleIds irRuleIds() { return irRuleIds; } } diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/driver/network/testvm/java/IRRuleIds.java b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/network/testvm/java/IRRuleIds.java new file mode 100644 index 00000000000..b8ea1765b4f --- /dev/null +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/driver/network/testvm/java/IRRuleIds.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2026, 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. + */ + +package compiler.lib.ir_framework.driver.network.testvm.java; + +import compiler.lib.ir_framework.IR; +import compiler.lib.ir_framework.driver.irmatching.irmethod.IRMethod; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Stream; + +/** + * Class to hold the indices of the applicable {@link IR @IR} rules of an {@link IRMethod}. + */ +public class IRRuleIds implements Iterable { + private final List ruleIds; + + public IRRuleIds(List ruleIds) { + this.ruleIds = ruleIds; + } + + public int first() { + return ruleIds.getFirst(); + } + + public int last() { + return ruleIds.getLast(); + } + + public boolean isEmpty() { + return ruleIds.isEmpty(); + } + + public int count() { + return ruleIds.size(); + } + + @Override + public Iterator iterator() { + return ruleIds.iterator(); + } + + public Stream stream() { + return ruleIds.stream(); + } +} diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/test/TestVM.java b/test/hotspot/jtreg/compiler/lib/ir_framework/test/TestVM.java index c5ab318d67d..c2580e087f0 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/test/TestVM.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/test/TestVM.java @@ -92,7 +92,7 @@ public class TestVM { static final boolean XCOMP = Platform.isComp(); static final boolean VERBOSE = Boolean.getBoolean("Verbose"); - private static final boolean PRINT_TIMES = Boolean.getBoolean("PrintTimes"); + private static final boolean PRINT_TIMES = Boolean.getBoolean("PrintTimes") || VERBOSE; public static final boolean USE_COMPILER = WHITE_BOX.getBooleanVMFlag("UseCompiler"); static final boolean EXCLUDE_RANDOM = Boolean.getBoolean("ExcludeRandom"); private static final String TESTLIST = System.getProperty("Test", ""); @@ -823,14 +823,14 @@ public class TestVM { forceCompileMap.forEach((key, value) -> builder.append("- ").append(key).append(" at CompLevel.").append(value) .append(System.lineSeparator())); throw new TestRunException("Could not force compile the following @ForceCompile methods:" - + System.lineSeparator() + builder.toString()); + + System.lineSeparator() + builder); } /** * Once all framework tests are collected, they are run in this method. */ private void runTests() { - TreeMap durations = (PRINT_TIMES || VERBOSE) ? new TreeMap<>() : null; + TreeMap durations = PRINT_TIMES ? new TreeMap<>() : null; long startTime = System.nanoTime(); List testList; boolean testFilterPresent = testFilterPresent(); @@ -867,11 +867,11 @@ public class TestVM { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); - builder.append(test.toString()).append(":").append(System.lineSeparator()).append(sw.toString()) + builder.append(test).append(":").append(System.lineSeparator()).append(sw) .append(System.lineSeparator()).append(System.lineSeparator()); failures++; } - if (PRINT_TIMES || VERBOSE) { + if (PRINT_TIMES) { long endTime = System.nanoTime(); long duration = (endTime - startTime); durations.put(duration, test.getName()); @@ -886,7 +886,7 @@ public class TestVM { } // Print execution times - if (VERBOSE || PRINT_TIMES) { + if (PRINT_TIMES) { TestFrameworkSocket.write("Test execution times:", PRINT_TIMES_TAG, true); for (Map.Entry entry : durations.entrySet()) { TestFrameworkSocket.write(String.format("%-25s%15d ns%n", entry.getValue() + ":", entry.getKey()), @@ -898,7 +898,7 @@ public class TestVM { // Finally, report all occurred exceptions in a nice format. String msg = System.lineSeparator() + System.lineSeparator() + "Test Failures (" + failures + ")" + System.lineSeparator() + "----------------" + "-".repeat(String.valueOf(failures).length()); - throw new TestRunException(msg + System.lineSeparator() + builder.toString()); + throw new TestRunException(msg + System.lineSeparator() + builder); } } diff --git a/test/hotspot/jtreg/compiler/uncommontrap/TestDeoptDetailsLockRank.java b/test/hotspot/jtreg/compiler/uncommontrap/TestDeoptDetailsLockRank.java new file mode 100644 index 00000000000..2866a84ba46 --- /dev/null +++ b/test/hotspot/jtreg/compiler/uncommontrap/TestDeoptDetailsLockRank.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026, 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. + */ + + /** + * @test + * @bug 8374862 + * @summary Regression test for -XX:+Verbose -XX:+WizardMode -XX:+PrintDeoptimizationDetails crash + * @requires vm.debug + * @run main/othervm -XX:+Verbose -XX:+WizardMode -XX:+PrintDeoptimizationDetails compiler.uncommontrap.TestDeoptDetailsLockRank + */ + +package compiler.uncommontrap; + +public class TestDeoptDetailsLockRank { + + public static void main(String[] args) { + System.out.println("passed"); + } +} \ No newline at end of file diff --git a/test/hotspot/jtreg/containers/docker/TestJcmd.java b/test/hotspot/jtreg/containers/docker/TestJcmd.java index 3cfe2945e92..fcd5c665f2b 100644 --- a/test/hotspot/jtreg/containers/docker/TestJcmd.java +++ b/test/hotspot/jtreg/containers/docker/TestJcmd.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -143,6 +143,7 @@ public class TestJcmd { sb.append(String.format("FROM %s:%s\n", DockerfileConfig.getBaseImageName(), DockerfileConfig.getBaseImageVersion())); sb.append("COPY /jdk /jdk\n"); + sb.append("ENV LANG=C.UTF-8\n"); sb.append("ENV JAVA_HOME=/jdk\n"); if (!IS_PODMAN) { // only needed for docker diff --git a/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/ArraySuperTest.java b/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/ArraySuperTest.java new file mode 100644 index 00000000000..5274c140f32 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/ArraySuperTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2026, 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. + * + */ + +/* + * @test + * @bug 8304147 + * @summary make sure dynamic archive does not archive array classes with incorrect values in + * Array::_secondary_supers + * @requires vm.cds + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds + * @build ArraySuperTest jdk.test.whitebox.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar ArraySuperApp.jar ArraySuperApp + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. ArraySuperTest + */ + +import java.util.function.Predicate; +import jdk.test.lib.helpers.ClassFileInstaller; + +public class ArraySuperTest extends DynamicArchiveTestBase { + + public static void main(String[] args) throws Exception { + runTest(ArraySuperTest::test); + } + + static void test() throws Exception { + String topArchiveName = getNewArchiveName(); + String appJar = ClassFileInstaller.getJarPath("ArraySuperApp.jar"); + String mainClass = ArraySuperApp.class.getName(); + + dump(topArchiveName, "-cp", appJar, mainClass).assertNormalExit(); + run(topArchiveName, "-cp", appJar, "-Xshare:off", mainClass, "withDynamicArchive").assertNormalExit(); + run(topArchiveName, "-cp", appJar, mainClass, "withDynamicArchive").assertNormalExit(); + } +} + +class ArraySuperApp implements Predicate { + static volatile Object array; + public boolean test(Object o) { + return true; + } + static void main(String args[]) { + array = new ArraySuperApp[1]; + if (args.length > 0) { + Predicate[] p = new Predicate[0]; + System.out.println(p.getClass().isInstance(array)); + p = (Predicate[])array; + p[0] = new ArraySuperApp(); + System.out.println("All tests passed"); + } + } +} diff --git a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixedCore.java b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixedCore.java new file mode 100644 index 00000000000..b8b19c743e9 --- /dev/null +++ b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixedCore.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026, NTT DATA + * 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. + */ + +import jdk.test.lib.JDKToolFinder; +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.SA.SATestUtils; +import jdk.test.lib.Utils; +import jdk.test.lib.apps.LingeredApp; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.util.CoreUtils; + +/** + * @test + * @bug 8374482 + * @requires (os.family == "linux") & (vm.hasSA) + * @requires os.arch == "amd64" + * @library /test/lib + * @run driver TestJhsdbJstackMixedCore + */ +public class TestJhsdbJstackMixedCore { + + private static void runJstackMixed(String coreFileName) throws Exception { + JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); + launcher.addVMArgs(Utils.getTestJavaOpts()); + launcher.addToolArg("jstack"); + launcher.addToolArg("--mixed"); + launcher.addToolArg("--exe"); + launcher.addToolArg(JDKToolFinder.getTestJDKTool("java")); + launcher.addToolArg("--core"); + launcher.addToolArg(coreFileName); + + ProcessBuilder pb = SATestUtils.createProcessBuilder(launcher); + Process jhsdb = pb.start(); + OutputAnalyzer out = new OutputAnalyzer(jhsdb); + + jhsdb.waitFor(); + + System.out.println(out.getStdout()); + System.err.println(out.getStderr()); + + out.shouldContain(""); + out.shouldContain("Java_jdk_test_lib_apps_LingeredApp_crash"); + } + + public static void main(String... args) throws Throwable { + LingeredApp app = new LingeredApp(); + app.setForceCrash(true); + LingeredApp.startApp(app, CoreUtils.getAlwaysPretouchArg(true)); + app.waitAppTerminate(); + + String crashOutput = app.getOutput().getStdout(); + String coreFileName = CoreUtils.getCoreFileLocation(crashOutput, app.getPid()); + runJstackMixed(coreFileName); + } +} diff --git a/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestCheckedTests.java b/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestCheckedTests.java index 5b7cd3c38a8..d4c12de3e4b 100644 --- a/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestCheckedTests.java +++ b/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestCheckedTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -180,6 +180,12 @@ class BadIRAndRuntimeCheckedTests { throw new BadCheckedTestException("expected"); } } + + static class BadCheckedTestException extends RuntimeException { + BadCheckedTestException(String s) { + super(s); + } + } } class BadIRCheckedTests { @@ -224,9 +230,3 @@ class BadIRCheckedTests { } } } - -class BadCheckedTestException extends RuntimeException { - BadCheckedTestException(String s) { - super(s); - } -} diff --git a/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestSetupTests.java b/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestSetupTests.java index 782a773515a..1cdb6c2797a 100644 --- a/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestSetupTests.java +++ b/test/hotspot/jtreg/testlibrary_tests/ir_framework/tests/TestSetupTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2026, 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 @@ -25,7 +25,6 @@ package ir_framework.tests; import compiler.lib.ir_framework.*; import compiler.lib.ir_framework.driver.TestVMException; -import compiler.lib.ir_framework.shared.TestRunException; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -360,10 +359,11 @@ class TestSetupTestsWithExpectedExceptions { public void checkThrowInCheck(int x) { throw new BadCheckedTestException("expected check"); } -} -class BadCheckedTestException extends RuntimeException { - BadCheckedTestException(String s) { - super(s); + + static class BadCheckedTestException extends RuntimeException { + BadCheckedTestException(String s) { + super(s); + } } } diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 291b2163b0d..5e8406b13a6 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -503,6 +503,7 @@ java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java 8151492 generic- java/lang/invoke/LFCaching/LFGarbageCollectedTest.java 8078602 generic-all java/lang/invoke/lambda/LambdaFileEncodingSerialization.java 8249079 linux-all java/lang/invoke/RicochetTest.java 8251969 generic-all +java/lang/ProcessBuilder/PipelineLeaksFD.java 8375585 generic-all ############################################################################ diff --git a/test/jdk/build/CheckFiles.java b/test/jdk/build/CheckFiles.java index 5a915e881f0..7ef5b803d2d 100644 --- a/test/jdk/build/CheckFiles.java +++ b/test/jdk/build/CheckFiles.java @@ -106,6 +106,8 @@ public class CheckFiles { allowedEndingsLibDir.add("psfont.properties.ja"); allowedEndingsLibDir.add("src.zip"); allowedEndingsLibDir.add("tzdb.dat"); + allowedEndingsLibDir.add("javafx-swt.jar"); + allowedEndingsLibDir.add("javafx.properties"); if (Platform.isWindows()) { allowedEndingsLibDir.add(".lib"); allowedEndingsLibDir.add("tzmappings"); diff --git a/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java b/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java index b47433ca16f..b139f12da25 100644 --- a/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java +++ b/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -131,6 +131,7 @@ public class LdapPoolTimeoutTest { || msg.contains("No route to host") || msg.contains("Timed out waiting for lock") || msg.contains("Connect timed out") + || msg.contains("Connection timed out") || msg.contains("Timeout exceeded while waiting for a connection"))) { // got the expected exception System.out.println("Received expected NamingException with message: " + msg); diff --git a/test/jdk/java/lang/invoke/8147078/Test8147078.java b/test/jdk/java/lang/invoke/8147078/Test8147078.java index 08532d30929..51580aa6f10 100644 --- a/test/jdk/java/lang/invoke/8147078/Test8147078.java +++ b/test/jdk/java/lang/invoke/8147078/Test8147078.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -23,17 +23,18 @@ /* @test * @bug 8147078 - * @run testng/othervm -ea -esa Test8147078 + * @run junit/othervm -ea -esa Test8147078 */ -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class Test8147078 { @@ -65,16 +66,10 @@ public class Test8147078 { @Test public void testNoExceptionType() { - boolean caught = false; - try { + var cce = assertThrows(ClassCastException.class, () -> { MethodHandle eek = (MethodHandle) MH_catchException.invoke(MH_target, String.class, MH_handler); - } catch (ClassCastException cce) { - assertEquals("java.lang.String", cce.getMessage()); - caught = true; - } catch (Throwable t) { - fail("unexpected exception caught: " + t); - } - assertTrue(caught); + }); + assertEquals("java.lang.String", cce.getMessage()); } } \ No newline at end of file diff --git a/test/jdk/java/lang/invoke/8177146/TestMethodHandleBind.java b/test/jdk/java/lang/invoke/8177146/TestMethodHandleBind.java index 134cc9f7514..518d07b1518 100644 --- a/test/jdk/java/lang/invoke/8177146/TestMethodHandleBind.java +++ b/test/jdk/java/lang/invoke/8177146/TestMethodHandleBind.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, 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 @@ -23,17 +23,16 @@ /* @test * @bug 8177146 - * @run testng/othervm TestMethodHandleBind + * @run junit/othervm TestMethodHandleBind */ -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; import static java.lang.invoke.MethodHandles.lookup; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class TestMethodHandleBind extends pkg.A { static class B extends TestMethodHandleBind {} @@ -42,7 +41,7 @@ public class TestMethodHandleBind extends pkg.A { public void testInstanceOfCallerClass() throws Throwable { MethodHandle bound = lookup().bind(new TestMethodHandleBind() , "m1", MethodType.methodType(String.class)); String x = (String)bound.invoke(); - assertEquals(x, this.getClass().getSimpleName()); + assertEquals(this.getClass().getSimpleName(), x); } @Test @@ -50,47 +49,37 @@ public class TestMethodHandleBind extends pkg.A { MethodHandle bound = lookup().bind(new B() , "m1", MethodType.methodType(String.class)); // MethodHandle bound = lookup().findVirtual(B.class, "m1", MethodType.methodType(String.class)).bindTo(new B()); String x = (String)bound.invoke(); - assertEquals(x, "B"); + assertEquals("B", x); } @Test public void testInstanceOfReceiverClass() throws Throwable { - try { - MethodHandle bound = lookup().bind(new pkg.A() , "m1", MethodType.methodType(String.class)); - bound.invoke(); - fail("IllegalAccessException expected"); - } catch (IllegalAccessException e) { - } + assertThrows(IllegalAccessException.class, () -> lookup().bind(new pkg.A() , "m1", MethodType.methodType(String.class))); } @Test public void testPublicMethod() throws Throwable { MethodHandle bound = lookup().bind(new pkg.A() , "m2", MethodType.methodType(String.class)); String x = (String)bound.invoke(); - assertEquals(x, "A"); + assertEquals("A", x); } @Test public void testPublicMethod2() throws Throwable { MethodHandle bound = lookup().bind(new TestMethodHandleBind(), "m2", MethodType.methodType(String.class)); String x = (String)bound.invoke(); - assertEquals(x, this.getClass().getSimpleName()); + assertEquals(this.getClass().getSimpleName(), x); } @Test public void testInstanceOfCallerClassVarargs() throws Throwable { MethodHandle bound = lookup().bind(new TestMethodHandleBind() , "m3", MethodType.methodType(String.class, String[].class)); String x = (String)bound.invoke("a", "b", "c"); - assertEquals(x, this.getClass().getSimpleName() + "abc"); + assertEquals(this.getClass().getSimpleName() + "abc", x); } @Test public void testInstanceOfReceiverClassVarargs() throws Throwable { - try { - MethodHandle bound = lookup().bind(new pkg.A(), "m3", MethodType.methodType(String.class, String[].class)); - bound.invoke(); - fail("IllegalAccessException expected"); - } catch (IllegalAccessException e) { - } + assertThrows(IllegalAccessException.class, () -> lookup().bind(new pkg.A(), "m3", MethodType.methodType(String.class, String[].class))); } } diff --git a/test/jdk/java/lang/invoke/AccessControlTest.java b/test/jdk/java/lang/invoke/AccessControlTest.java index e177f08d876..fcd945a5d7f 100644 --- a/test/jdk/java/lang/invoke/AccessControlTest.java +++ b/test/jdk/java/lang/invoke/AccessControlTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @summary test access checking by java.lang.invoke.MethodHandles.Lookup * @compile AccessControlTest.java AccessControlTest_subpkg/Acquaintance_remote.java - * @run testng/othervm test.java.lang.invoke.AccessControlTest + * @run junit/othervm test.java.lang.invoke.AccessControlTest */ package test.java.lang.invoke; @@ -33,12 +33,13 @@ import java.lang.invoke.*; import java.lang.reflect.*; import java.lang.reflect.Modifier; import java.util.*; -import org.testng.annotations.*; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodHandles.Lookup.*; import static java.lang.invoke.MethodType.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; import test.java.lang.invoke.AccessControlTest_subpkg.Acquaintance_remote; @@ -69,7 +70,7 @@ public class AccessControlTest { this.prevLookupClass = lookup.previousLookupClass(); this.lookupModes = lookup.lookupModes(); - assert(lookupString().equals(lookup.toString())); + assertEquals(lookupString(), lookup.toString()); numberOf(lookupClass().getClassLoader()); // assign CL# } public LookupCase(Class lookupClass, Class prevLookupClass, int lookupModes) { @@ -96,7 +97,7 @@ public class AccessControlTest { int cmp = c1.getName().compareTo(c2.getName()); if (cmp != 0) return cmp; cmp = numberOf(c1.getClassLoader()) - numberOf(c2.getClassLoader()); - assert(cmp != 0); + assertNotEquals(0, cmp); return cmp; } else if (p1 != p2){ if (p1 == null) @@ -106,7 +107,7 @@ public class AccessControlTest { int cmp = p1.getName().compareTo(p2.getName()); if (cmp != 0) return cmp; cmp = numberOf(p1.getClassLoader()) - numberOf(p2.getClassLoader()); - assert(cmp != 0); + assertNotEquals(0, cmp); return cmp; } return -(this.lookupModes() - that.lookupModes()); @@ -211,8 +212,8 @@ public class AccessControlTest { c1.getPackageName().equals(c2.getPackageName())); boolean sameTopLevel = (topLevelClass(c1) == topLevelClass(c2)); boolean sameClass = (c1 == c2); - assert(samePackage || !sameTopLevel); - assert(sameTopLevel || !sameClass); + assertTrue(samePackage || !sameTopLevel); + assertTrue(sameTopLevel || !sameClass); boolean accessible = sameClass; if ((modes1 & PACKAGE) != 0) accessible |= samePackage; @@ -251,17 +252,17 @@ public class AccessControlTest { changed |= (PRIVATE|PROTECTED); // [A5] } if (sameClass) { - assert(changed == 0); // [A11] (no deprivation if same class) + assertEquals(0, changed); // [A11] (no deprivation if same class) } - if (accessible) assert((changed & PUBLIC) == 0); + if (accessible) assertEquals(0, changed & PUBLIC); int modes2 = modes1 & ~changed; Class plc = (m1 == m2) ? prevLookupClass() : c1; // [A9] [A10] if ((modes1 & UNCONDITIONAL) != 0) plc = null; // [A8] LookupCase l2 = new LookupCase(c2, plc, modes2); - assert(l2.lookupClass() == c2); // [A1] - assert((modes1 | modes2) == modes1); // [A1-a] (no elevation of access) - assert(l2.prevLookupClass() == null || (modes2 & MODULE) == 0); + assertSame(l2.lookupClass(), c2); // [A1] + assertEquals(modes1, modes1 | modes2); // [A1-a] (no elevation of access) + assertTrue(l2.prevLookupClass() == null || (modes2 & MODULE) == 0); return l2; } @@ -280,8 +281,8 @@ public class AccessControlTest { } if (newModes == oldModes) return this; // return self if no change LookupCase l2 = new LookupCase(lookupClass(), prevLookupClass(), newModes); - assert((oldModes | newModes) == oldModes); // [A2] (no elevation of access) - assert(l2.prevLookupClass() == null || (newModes & MODULE) == 0); + assertEquals(oldModes, oldModes | newModes); // [A2] (no elevation of access) + assertTrue(l2.prevLookupClass() == null || (newModes & MODULE) == 0); return l2; } @@ -331,7 +332,7 @@ public class AccessControlTest { && Modifier.isPublic(m.getModifiers()); } - assert(m1 == m2 && prevLookupClass == null); + assertNull(prevLookupClass); if (!willAccessClass(c2, false)) return false; @@ -380,7 +381,7 @@ public class AccessControlTest { && Modifier.isPublic(c2.getModifiers()); } - assert(m1 == m2 && prevLookupClass == null); + assertNull(prevLookupClass); LookupCase lc = this.in(c2); int modes1 = lc.lookupModes(); @@ -409,8 +410,8 @@ public class AccessControlTest { Class c = cls; for (Class ec; (ec = c.getEnclosingClass()) != null; ) c = ec; - assert(c.getEnclosingClass() == null); - assert(c == cls || cls.getEnclosingClass() != null); + assertNull(c.getEnclosingClass()); + assertTrue(c == cls || cls.getEnclosingClass() != null); return c; } @@ -443,14 +444,14 @@ public class AccessControlTest { if (edges == null) CASE_EDGES.put(l2, edges = new TreeSet<>()); if (edges.add(l1)) { Class c1 = l1.lookupClass(); - assert(l2.lookupClass() == c2); // [A1] + assertSame(l2.lookupClass(), c2); // [A1] int m1 = l1.lookupModes(); int m2 = l2.lookupModes(); - assert((m1 | m2) == m1); // [A2] (no elevation of access) + assertEquals(m1, (m1 | m2)); // [A2] (no elevation of access) LookupCase expect = dropAccess == 0 ? l1.in(c2) : l1.in(c2).dropLookupMode(dropAccess); if (!expect.equals(l2)) System.out.println("*** expect "+l1+" => "+expect+" but got "+l2); - assertEquals(l2, expect); + assertEquals(expect, l2); } } @@ -567,7 +568,7 @@ public class AccessControlTest { if (willAccess != didAccess) { System.out.println(sourceCase+" => "+targetClass.getSimpleName()+(isFindOrAccessClass?"":"."+methodName+methodType)); System.out.println("fail "+(isFindOrAccessClass?kind:"on "+method)+" ex="+accessError); - assertEquals(willAccess, didAccess); + assertEquals(didAccess, willAccess); } testCount++; if (!didAccess) testCountFails++; @@ -579,10 +580,10 @@ public class AccessControlTest { System.out.println(targetClass.getSimpleName()+"."+methodName+methodType); try { Method method = targetClass.getDeclaredMethod(methodName, methodType.parameterArray()); - assertEquals(method.getReturnType(), methodType.returnType()); + assertEquals(methodType.returnType(), method.getReturnType()); int haveMods = method.getModifiers(); - assert(Modifier.isStatic(haveMods)); - assert(targetAccess == fixMods(haveMods)); + assertTrue(Modifier.isStatic(haveMods)); + assertEquals(targetAccess, fixMods(haveMods)); return method; } catch (NoSuchMethodException ex) { throw new AssertionError(methodName, ex); @@ -604,7 +605,7 @@ public class AccessControlTest { case PACKAGE: return "pkg_in_"; case PRIVATE: return "pri_in_"; } - assert(false); + fail(); return "?"; } private static final int[] ACCESS_CASES = { diff --git a/test/jdk/java/lang/invoke/ArrayConstructorTest.java b/test/jdk/java/lang/invoke/ArrayConstructorTest.java index 749bb7926a0..313c2828380 100644 --- a/test/jdk/java/lang/invoke/ArrayConstructorTest.java +++ b/test/jdk/java/lang/invoke/ArrayConstructorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -23,7 +23,7 @@ /* @test * @bug 8155106 - * @run testng/othervm -ea -esa test.java.lang.invoke.ArrayConstructorTest + * @run junit/othervm -ea -esa test.java.lang.invoke.ArrayConstructorTest */ package test.java.lang.invoke; @@ -32,30 +32,22 @@ import java.lang.invoke.MethodHandles; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; - -import org.testng.annotations.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.api.Assertions.*; public class ArrayConstructorTest { static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); @Test - public static void testFindConstructorArray() { - boolean caught = false; - try { - MethodHandle h = LOOKUP.findConstructor(Object[].class, methodType(void.class)); - } catch (NoSuchMethodException nsme) { - assertEquals("no constructor for array class: [Ljava.lang.Object;", nsme.getMessage()); - caught = true; - } catch (Exception e) { - throw new AssertionError("unexpected exception: " + e); - } - assertTrue(caught); + public void testFindConstructorArray() { + var nsme = assertThrows(NoSuchMethodException.class, () -> LOOKUP.findConstructor(Object[].class, methodType(void.class))); + assertEquals("no constructor for array class: [Ljava.lang.Object;", nsme.getMessage()); } - @DataProvider static Object[][] arrayConstructorNegative() { return new Object[][]{ {String.class, IllegalArgumentException.class, "not an array class: java.lang.String"}, @@ -63,34 +55,28 @@ public class ArrayConstructorTest { }; } - @Test(dataProvider = "arrayConstructorNegative") - public static void testArrayConstructorNegative(Class clazz, Class exceptionClass, String message) { - boolean caught = false; - try { - MethodHandle h = MethodHandles.arrayConstructor(clazz); - } catch (Exception e) { - assertEquals(exceptionClass, e.getClass()); - if (message != null) { - assertEquals(message, e.getMessage()); - } - caught = true; + @ParameterizedTest + @MethodSource("arrayConstructorNegative") + public void testArrayConstructorNegative(Class clazz, Class exceptionClass, String message) { + var e = assertThrowsExactly(exceptionClass, () -> MethodHandles.arrayConstructor(clazz)); + if (message != null) { + assertEquals(message, e.getMessage()); } - assertTrue(caught); } @Test - public static void testArrayConstructor() throws Throwable { + public void testArrayConstructor() throws Throwable { MethodHandle h = MethodHandles.arrayConstructor(String[].class); assertEquals(methodType(String[].class, int.class), h.type()); String[] a = (String[]) h.invoke(17); assertEquals(17, a.length); } - @Test(expectedExceptions = {NegativeArraySizeException.class}) - public static void testArrayConstructorNegativeIndex() throws Throwable { + @Test + public void testArrayConstructorNegativeIndex() throws Throwable { MethodHandle h = MethodHandles.arrayConstructor(String[].class); assertEquals(methodType(String[].class, int.class), h.type()); - h.invoke(-1); // throws exception + assertThrows(NegativeArraySizeException.class, () -> h.invoke(-1)); } } diff --git a/test/jdk/java/lang/invoke/ArrayLengthTest.java b/test/jdk/java/lang/invoke/ArrayLengthTest.java index 9f3cc6fe240..2ef97442638 100644 --- a/test/jdk/java/lang/invoke/ArrayLengthTest.java +++ b/test/jdk/java/lang/invoke/ArrayLengthTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -22,36 +22,39 @@ */ /* @test - * @run testng/othervm -ea -esa test.java.lang.invoke.ArrayLengthTest + * @run junit/othervm -ea -esa test.java.lang.invoke.ArrayLengthTest */ package test.java.lang.invoke; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class ArrayLengthTest { - @DataProvider - Object[][] arrayClasses() { - return new Object[][] { - {int[].class}, - {long[].class}, - {float[].class}, - {double[].class}, - {boolean[].class}, - {byte[].class}, - {short[].class}, - {char[].class}, - {Object[].class}, - {StringBuffer[].class} + static Object[] arrayClasses() { + return new Object[] { + int[].class, + long[].class, + float[].class, + double[].class, + boolean[].class, + byte[].class, + short[].class, + char[].class, + Object[].class, + StringBuffer[].class }; } - @Test(dataProvider = "arrayClasses") + @ParameterizedTest + @MethodSource("arrayClasses") public void testArrayLength(Class arrayClass) throws Throwable { MethodHandle arrayLength = MethodHandles.arrayLength(arrayClass); assertEquals(int.class, arrayLength.type().returnType()); @@ -60,25 +63,28 @@ public class ArrayLengthTest { assertEquals(10, arrayLength.invoke(array)); } - @Test(dataProvider = "arrayClasses", expectedExceptions = NullPointerException.class) + @ParameterizedTest + @MethodSource("arrayClasses") public void testArrayLengthInvokeNPE(Class arrayClass) throws Throwable { MethodHandle arrayLength = MethodHandles.arrayLength(arrayClass); - arrayLength.invoke(null); + assertThrows(NullPointerException.class, () -> arrayLength.invoke(null)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testArrayLengthNoArray() { - MethodHandles.arrayLength(String.class); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.arrayLength(String.class)); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testArrayLengthNPE() { - MethodHandles.arrayLength(null); + assertThrows(NullPointerException.class, () -> MethodHandles.arrayLength(null)); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testNullReference() throws Throwable { MethodHandle arrayLength = MethodHandles.arrayLength(String[].class); - int len = (int)arrayLength.invokeExact((String[])null); + assertThrows(NullPointerException.class, () -> { + int len = (int)arrayLength.invokeExact((String[])null); + }); } } diff --git a/test/jdk/java/lang/invoke/CallerSensitiveMethodHandle.java b/test/jdk/java/lang/invoke/CallerSensitiveMethodHandle.java index 369c2c2bea1..a2756fc2f23 100644 --- a/test/jdk/java/lang/invoke/CallerSensitiveMethodHandle.java +++ b/test/jdk/java/lang/invoke/CallerSensitiveMethodHandle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, 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 @@ -22,20 +22,19 @@ */ /* @test - * @run testng/othervm CallerSensitiveMethodHandle + * @run junit/othervm CallerSensitiveMethodHandle * @summary Check Lookup findVirtual, findStatic and unreflect behavior with * caller sensitive methods with focus on AccessibleObject.setAccessible */ -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.reflect.Field; import static java.lang.invoke.MethodType.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class CallerSensitiveMethodHandle { private static int field = 0; @@ -46,7 +45,7 @@ public class CallerSensitiveMethodHandle { MethodHandle mh = l.findVirtual(Field.class, "setInt", methodType(void.class, Object.class, int.class)); int newValue = 5; mh.invokeExact(f, (Object) null, newValue); - assertTrue(field == newValue); + assertEquals(newValue, field); } @Test @@ -55,6 +54,6 @@ public class CallerSensitiveMethodHandle { MethodHandle MH_lookup2 = lookup.findStatic(MethodHandles.class, "lookup", methodType(Lookup.class)); Lookup lookup2 = (Lookup) MH_lookup2.invokeExact(); System.out.println(lookup2 + " original lookup class " + lookup.lookupClass()); - assertTrue(lookup2.lookupClass() == lookup.lookupClass()); + assertSame(lookup.lookupClass(), lookup2.lookupClass()); } } diff --git a/test/jdk/java/lang/invoke/ClassSpecializerTest.java b/test/jdk/java/lang/invoke/ClassSpecializerTest.java index 671cf39e217..8bc5c58ad52 100644 --- a/test/jdk/java/lang/invoke/ClassSpecializerTest.java +++ b/test/jdk/java/lang/invoke/ClassSpecializerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -24,15 +24,13 @@ /* @test * @summary Smoke-test class specializer, used to create BoundMethodHandle classes * @compile/module=java.base java/lang/invoke/ClassSpecializerHelper.java - * @run testng/othervm/timeout=250 -ea -esa ClassSpecializerTest + * @run junit/othervm/timeout=250 -ea -esa ClassSpecializerTest */ // Useful diagnostics to try: // -Djava.lang.invoke.MethodHandle.TRACE_RESOLVE=true // -Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true - -import org.testng.annotations.*; import java.lang.invoke.*; import java.util.ArrayList; import java.util.Arrays; @@ -40,6 +38,11 @@ import java.util.List; import static java.lang.invoke.ClassSpecializerHelper.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + public class ClassSpecializerTest { @Test @@ -58,12 +61,12 @@ public class ClassSpecializerTest { } args.set(0, key * 1000 + 42); Frob f = (Frob) mh.invokeWithArguments(args.toArray()); - assert(f.kind() == k); + assertSame(k, f.kind()); System.out.println("k.f(...) = " + f.toString()); List l = f.asList(); System.out.println("f.l = " + l); args.subList(0,1).clear(); // drop label - assert(args.equals(l)); + assertEquals(args, l); } } private static Object coughUpA(Class pt) throws Throwable { diff --git a/test/jdk/java/lang/invoke/CompileThresholdBootstrapTest.java b/test/jdk/java/lang/invoke/CompileThresholdBootstrapTest.java index 848264b83a3..c6e093bd09a 100644 --- a/test/jdk/java/lang/invoke/CompileThresholdBootstrapTest.java +++ b/test/jdk/java/lang/invoke/CompileThresholdBootstrapTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -26,27 +26,19 @@ * @bug 8143232 * @summary Test verifies that LF bootstraps properly when run with COMPILE_THRESHOLD set * @compile CompileThresholdBootstrapTest.java - * @run testng/othervm -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=30 test.java.lang.invoke.CompileThresholdBootstrapTest + * @run junit/othervm -Djava.lang.invoke.MethodHandle.COMPILE_THRESHOLD=30 test.java.lang.invoke.CompileThresholdBootstrapTest */ package test.java.lang.invoke; import java.lang.invoke.MethodHandles; -import org.testng.*; -import org.testng.annotations.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public final class CompileThresholdBootstrapTest { @Test public void testBootstrap() throws Throwable { - Assert.assertEquals((int)MethodHandles.constant(int.class, (int)0).invokeExact(), 0); - } - - public static void main(String ... args) { - try { - CompileThresholdBootstrapTest test = new CompileThresholdBootstrapTest(); - test.testBootstrap(); - } catch (Throwable t) { - t.printStackTrace(); - } + assertEquals(0, (int)MethodHandles.constant(int.class, (int)0).invokeExact()); } } diff --git a/test/jdk/java/lang/invoke/ConstantIdentityMHTest.java b/test/jdk/java/lang/invoke/ConstantIdentityMHTest.java index 320fd29abe6..43770ea023b 100644 --- a/test/jdk/java/lang/invoke/ConstantIdentityMHTest.java +++ b/test/jdk/java/lang/invoke/ConstantIdentityMHTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -23,7 +23,7 @@ /* @test * @summary unit tests for java.lang.invoke.MethodHandles - * @run testng/othervm -ea -esa test.java.lang.invoke.ConstantIdentityMHTest + * @run junit/othervm -ea -esa test.java.lang.invoke.ConstantIdentityMHTest */ package test.java.lang.invoke; @@ -31,13 +31,14 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; -import static org.testng.Assert.*; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class ConstantIdentityMHTest { - @DataProvider(name = "testZeroData") - private Object[][] testZeroData() { + private static Object[][] testZeroData() { return new Object[][] { {void.class, "()void"}, {int.class, "()int"}, @@ -52,26 +53,27 @@ public class ConstantIdentityMHTest { }; } - @Test(dataProvider = "testZeroData") + @ParameterizedTest + @MethodSource("testZeroData") public void testZero(Class expectedtype, String expected) throws Throwable { - assertEquals(MethodHandles.zero(expectedtype).type().toString(), expected); + assertEquals(expected, MethodHandles.zero(expectedtype).type().toString()); } - @Test(expectedExceptions={ NullPointerException.class }) + @Test public void testZeroNPE() { - MethodHandle mh = MethodHandles.zero(null); + assertThrows(NullPointerException.class, () -> MethodHandles.zero(null)); } @Test void testEmpty() throws Throwable { MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class)); - assertEquals((String)cat.invoke("x","y"), "xy"); + assertEquals("xy", (String)cat.invoke("x","y")); MethodHandle mhEmpty = MethodHandles.empty(cat.type()); - assertEquals((String)mhEmpty.invoke("x","y"), null); + assertNull((String) mhEmpty.invoke("x", "y")); } - @Test(expectedExceptions = { NullPointerException.class }) + @Test void testEmptyNPE() { - MethodHandle lenEmptyMH = MethodHandles.empty(null); + assertThrows(NullPointerException.class, () -> MethodHandles.empty(null)); } } diff --git a/test/jdk/java/lang/invoke/DefineClassTest.java b/test/jdk/java/lang/invoke/DefineClassTest.java index f712c945e59..889607f38f5 100644 --- a/test/jdk/java/lang/invoke/DefineClassTest.java +++ b/test/jdk/java/lang/invoke/DefineClassTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, 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 @@ -23,7 +23,7 @@ /* @test * @modules java.base/java.lang:open - * @run testng/othervm test.DefineClassTest + * @run junit/othervm test.DefineClassTest * @summary Basic test for java.lang.invoke.MethodHandles.Lookup.defineClass */ @@ -38,7 +38,6 @@ import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.testng.annotations.Test; import static java.lang.classfile.ClassFile.ACC_PUBLIC; import static java.lang.classfile.ClassFile.ACC_STATIC; @@ -48,7 +47,8 @@ import static java.lang.constant.ConstantDescs.INIT_NAME; import static java.lang.constant.ConstantDescs.MTD_void; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodHandles.Lookup.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class DefineClassTest { private static final String THIS_PACKAGE = DefineClassTest.class.getPackageName(); @@ -60,9 +60,9 @@ public class DefineClassTest { * protection domain, as a lookup class. */ void testSameAbode(Class clazz, Class lc) { - assertTrue(clazz.getClassLoader() == lc.getClassLoader()); - assertEquals(clazz.getPackageName(), lc.getPackageName()); - assertTrue(clazz.getProtectionDomain() == lc.getProtectionDomain()); + assertSame(lc.getClassLoader(), clazz.getClassLoader()); + assertEquals(lc.getPackageName(), clazz.getPackageName()); + assertSame(lc.getProtectionDomain(), clazz.getProtectionDomain()); } /** @@ -72,8 +72,8 @@ public class DefineClassTest { void testDiscoverable(Class clazz, Lookup lookup) throws Exception { String cn = clazz.getName(); ClassLoader loader = clazz.getClassLoader(); - assertTrue(Class.forName(cn, false, loader) == clazz); - assertTrue(lookup.findClass(cn) == clazz); + assertSame(clazz, Class.forName(cn, false, loader)); + assertSame(clazz, lookup.findClass(cn)); } /** @@ -86,7 +86,7 @@ public class DefineClassTest { Class clazz = lookup.defineClass(generateClass(CLASS_NAME)); // test name - assertEquals(clazz.getName(), CLASS_NAME); + assertEquals(CLASS_NAME, clazz.getName()); // test loader/package/protection-domain testSameAbode(clazz, lookup.lookupClass()); @@ -95,10 +95,8 @@ public class DefineClassTest { testDiscoverable(clazz, lookup); // attempt defineClass again - try { - lookup.defineClass(generateClass(CLASS_NAME)); - assertTrue(false); - } catch (LinkageError expected) { } + var bytes = generateClass(CLASS_NAME); + assertThrows(LinkageError.class, () -> lookup.defineClass(bytes)); } /** @@ -126,10 +124,7 @@ public class DefineClassTest { classBytes = generateRunner(CLASS_NAME + nextNumber(), THIS_CLASS, "method4"); Class clazz = lookup.defineClass(classBytes); Runnable r = (Runnable) clazz.newInstance(); - try { - r.run(); - assertTrue(false); - } catch (IllegalAccessError expected) { } + assertThrows(IllegalAccessError.class, r::run); } public static void method1() { } @@ -154,12 +149,8 @@ public class DefineClassTest { Class clazz = lookup().defineClass(classBytes); // trigger initializer to run - try { - clazz.newInstance(); - assertTrue(false); - } catch (ExceptionInInitializerError e) { - assertTrue(e.getCause() instanceof IllegalCallerException); - } + var e = assertThrows(ExceptionInInitializerError.class, clazz::newInstance); + assertInstanceOf(IllegalCallerException.class, e.getCause()); } static void fail() { throw new IllegalCallerException(); } @@ -189,9 +180,9 @@ public class DefineClassTest { ClassLoader loader = new URLClassLoader(new URL[] { url1, url2 }); Class target1 = Class.forName("p.C1", false, loader); Class target2 = Class.forName("p.C2", false, loader); - assertTrue(target1.getClassLoader() == loader); - assertTrue(target1.getClassLoader() == loader); - assertNotEquals(target1.getProtectionDomain(), target2.getProtectionDomain()); + assertSame(loader, target1.getClassLoader()); + assertSame(loader, target1.getClassLoader()); + assertNotEquals(target2.getProtectionDomain(), target1.getProtectionDomain()); // protection domain 1 Lookup lookup1 = privateLookupIn(target1, lookup()); @@ -214,43 +205,43 @@ public class DefineClassTest { @Test public void testBootLoader() throws Exception { Lookup lookup = privateLookupIn(Thread.class, lookup()); - assertTrue(lookup.getClass().getClassLoader() == null); + assertNull(lookup.getClass().getClassLoader()); Class clazz = lookup.defineClass(generateClass("java.lang.Foo")); - assertEquals(clazz.getName(), "java.lang.Foo"); + assertEquals("java.lang.Foo", clazz.getName()); testSameAbode(clazz, Thread.class); testDiscoverable(clazz, lookup); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void testWrongPackage() throws Exception { - lookup().defineClass(generateClass("other.C")); + assertThrows(IllegalArgumentException.class, () -> lookup().defineClass(generateClass("other.C"))); } - @Test(expectedExceptions = { IllegalAccessException.class }) + @Test public void testNoPackageAccess() throws Exception { Lookup lookup = lookup().dropLookupMode(PACKAGE); - lookup.defineClass(generateClass(THIS_PACKAGE + ".C")); + assertThrows(IllegalAccessException.class, () -> lookup.defineClass(generateClass(THIS_PACKAGE + ".C"))); } - @Test(expectedExceptions = { ClassFormatError.class }) + @Test public void testTruncatedClassFile() throws Exception { - lookup().defineClass(new byte[0]); + assertThrows(ClassFormatError.class, () -> lookup().defineClass(new byte[0])); } - @Test(expectedExceptions = { NullPointerException.class }) + @Test public void testNull() throws Exception { - lookup().defineClass(null); + assertThrows(NullPointerException.class, () -> lookup().defineClass(null)); } - @Test(expectedExceptions = { NoClassDefFoundError.class }) + @Test public void testLinking() throws Exception { - lookup().defineClass(generateNonLinkableClass(THIS_PACKAGE + ".NonLinkableClass")); + assertThrows(NoClassDefFoundError.class, () -> lookup().defineClass(generateNonLinkableClass(THIS_PACKAGE + ".NonLinkableClass"))); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void testModuleInfo() throws Exception { - lookup().defineClass(generateModuleInfo()); + assertThrows(IllegalArgumentException.class, () -> lookup().defineClass(generateModuleInfo())); } /** diff --git a/test/jdk/java/lang/invoke/DropArgumentsTest.java b/test/jdk/java/lang/invoke/DropArgumentsTest.java index 2df9b5f63ba..fb82bb312cd 100644 --- a/test/jdk/java/lang/invoke/DropArgumentsTest.java +++ b/test/jdk/java/lang/invoke/DropArgumentsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -24,19 +24,24 @@ /* @test * @bug 8158169 * @summary unit tests for java.lang.invoke.MethodHandles - * @run testng test.java.lang.invoke.DropArgumentsTest + * @run junit test.java.lang.invoke.DropArgumentsTest */ package test.java.lang.invoke; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; -import static org.testng.AssertJUnit.*; -import org.testng.annotations.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class DropArgumentsTest { @@ -53,8 +58,7 @@ public class DropArgumentsTest { } - @DataProvider(name = "dropArgumentsToMatchNPEData") - private Object[][] dropArgumentsToMatchNPEData() + private static Object[][] dropArgumentsToMatchNPEData() throws NoSuchMethodException, IllegalAccessException { MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class)); return new Object[][] { @@ -63,13 +67,13 @@ public class DropArgumentsTest { }; } - @Test(dataProvider = "dropArgumentsToMatchNPEData", expectedExceptions = { NullPointerException.class }) + @ParameterizedTest + @MethodSource("dropArgumentsToMatchNPEData") public void dropArgumentsToMatchNPE(MethodHandle target, int pos, List> valueType, int skip) { - MethodHandles.dropArgumentsToMatch(target, pos, valueType , skip); + assertThrows(NullPointerException.class, () -> MethodHandles.dropArgumentsToMatch(target, pos, valueType, skip)); } - @DataProvider(name = "dropArgumentsToMatchIAEData") - private Object[][] dropArgumentsToMatchIAEData() + private static Object[][] dropArgumentsToMatchIAEData() throws NoSuchMethodException, IllegalAccessException { MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class)); MethodType bigType = cat.type().insertParameterTypes(0, String.class, String.class, int.class); @@ -82,17 +86,20 @@ public class DropArgumentsTest { }; } - @Test(dataProvider = "dropArgumentsToMatchIAEData", expectedExceptions = { IllegalArgumentException.class }) + @ParameterizedTest + @MethodSource("dropArgumentsToMatchIAEData") public void dropArgumentsToMatchIAE(MethodHandle target, int pos, List> valueType, int skip) { - MethodHandles.dropArgumentsToMatch(target, pos, valueType , skip); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.dropArgumentsToMatch(target, pos, valueType, skip)); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void dropArgumentsToMatchTestWithVoid() throws Throwable { MethodHandle cat = lookup().findVirtual(String.class, "concat", - MethodType.methodType(String.class, String.class)); - MethodType bigTypewithVoid = cat.type().insertParameterTypes(0, void.class, String.class, int.class); - MethodHandle handle2 = MethodHandles.dropArgumentsToMatch(cat, 0, bigTypewithVoid.parameterList(), 1); + MethodType.methodType(String.class, String.class)); + List> bigTypewithVoid = new ArrayList<>(cat.type().parameterList()); + bigTypewithVoid.addAll(0, List.of(void.class, String.class, int.class)); + assertThrows(IllegalArgumentException.class, () -> + MethodHandles.dropArgumentsToMatch(cat, 0, bigTypewithVoid, 1)); } public static class MethodSet { diff --git a/test/jdk/java/lang/invoke/DropLookupModeTest.java b/test/jdk/java/lang/invoke/DropLookupModeTest.java index 1a4c311be8b..7619793c3c6 100644 --- a/test/jdk/java/lang/invoke/DropLookupModeTest.java +++ b/test/jdk/java/lang/invoke/DropLookupModeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -21,9 +21,9 @@ * questions. */ -/** +/* * @test - * @run testng DropLookupModeTest + * @run junit DropLookupModeTest * @summary Basic unit tests Lookup::dropLookupMode */ @@ -31,83 +31,85 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import static java.lang.invoke.MethodHandles.Lookup.*; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; -@Test public class DropLookupModeTest { /** * Basic test of dropLookupMode */ + @Test public void testBasic() { final Lookup fullPowerLookup = MethodHandles.lookup(); final Class lc = fullPowerLookup.lookupClass(); - assertTrue(fullPowerLookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PROTECTED|PRIVATE|ORIGINAL)); + assertEquals(PUBLIC | MODULE | PACKAGE | PROTECTED | PRIVATE | ORIGINAL, fullPowerLookup.lookupModes()); Lookup lookup = fullPowerLookup.dropLookupMode(PRIVATE); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE | PACKAGE, lookup.lookupModes()); lookup = fullPowerLookup.dropLookupMode(PROTECTED); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PRIVATE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE | PACKAGE | PRIVATE, lookup.lookupModes()); lookup = fullPowerLookup.dropLookupMode(PACKAGE); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE, lookup.lookupModes()); lookup = fullPowerLookup.dropLookupMode(MODULE); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC, lookup.lookupModes()); lookup = fullPowerLookup.dropLookupMode(PUBLIC); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == 0); + assertSame(lc, lookup.lookupClass()); + assertEquals(0, lookup.lookupModes()); lookup = fullPowerLookup.dropLookupMode(UNCONDITIONAL); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PRIVATE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE | PACKAGE | PRIVATE, lookup.lookupModes()); } /** * Starting with a full power Lookup, use dropLookupMode to create new Lookups * with reduced access. */ + @Test public void testReducingAccess() { Lookup lookup = MethodHandles.lookup(); final Class lc = lookup.lookupClass(); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PROTECTED|PRIVATE|ORIGINAL)); + assertEquals(PUBLIC | MODULE | PACKAGE | PROTECTED | PRIVATE | ORIGINAL, lookup.lookupModes()); lookup = lookup.dropLookupMode(PROTECTED); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE|PRIVATE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE | PACKAGE | PRIVATE, lookup.lookupModes()); lookup = lookup.dropLookupMode(PRIVATE); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE|PACKAGE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE | PACKAGE, lookup.lookupModes()); lookup = lookup.dropLookupMode(PACKAGE); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == (PUBLIC|MODULE)); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC | MODULE, lookup.lookupModes()); lookup = lookup.dropLookupMode(MODULE); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == PUBLIC); + assertSame(lc, lookup.lookupClass()); + assertEquals(PUBLIC, lookup.lookupModes()); lookup = lookup.dropLookupMode(PUBLIC); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == 0); + assertSame(lc, lookup.lookupClass()); + assertEquals(0, lookup.lookupModes()); // repeat with lookup has no access lookup = lookup.dropLookupMode(PUBLIC); - assertTrue(lookup.lookupClass() == lc); - assertTrue(lookup.lookupModes() == 0); + assertSame(lc, lookup.lookupClass()); + assertEquals(0, lookup.lookupModes()); } - @DataProvider(name = "unconditionals") - public Object[][] unconditionals() { + public static Object[][] unconditionals() { Lookup publicLookup = MethodHandles.publicLookup(); return new Object[][] { { publicLookup, Object.class }, @@ -120,9 +122,10 @@ public class DropLookupModeTest { * Test dropLookupMode on the lookup with public lookup * and UNCONDITIONAL */ - @Test(dataProvider = "unconditionals") + @ParameterizedTest + @MethodSource("unconditionals") public void testUnconditionalLookup(Lookup unconditionalLookup, Class expected) { - assertTrue(unconditionalLookup.lookupModes() == UNCONDITIONAL); + assertEquals(UNCONDITIONAL, unconditionalLookup.lookupModes()); assertPublicLookup(unconditionalLookup.dropLookupMode(PRIVATE), expected); assertPublicLookup(unconditionalLookup.dropLookupMode(PROTECTED), expected); @@ -132,31 +135,27 @@ public class DropLookupModeTest { // drop all access Lookup lookup = unconditionalLookup.dropLookupMode(UNCONDITIONAL); - assertTrue(lookup.lookupClass() == expected); - assertTrue(lookup.lookupModes() == 0); + assertSame(expected, lookup.lookupClass()); + assertEquals(0, lookup.lookupModes()); } private void assertPublicLookup(Lookup lookup, Class expected) { - assertTrue(lookup.lookupClass() == expected); - assertTrue(lookup.lookupModes() == UNCONDITIONAL); - } - - @DataProvider(name = "badInput") - public Object[][] badInput() { - return new Object[][] { - { 0, null }, - { (PACKAGE|PRIVATE), null }, // two modes - { Integer.MAX_VALUE, null }, - { Integer.MIN_VALUE, null }, - }; + assertSame(expected, lookup.lookupClass()); + assertEquals(UNCONDITIONAL, lookup.lookupModes()); } /** * Check that IllegalArgumentException is thrown for bad input */ - @Test(dataProvider = "badInput", expectedExceptions = {IllegalArgumentException.class}) - public void testBadInput(Integer modeToDrop, Object ignore) { - MethodHandles.lookup().dropLookupMode(modeToDrop); + @ParameterizedTest + @ValueSource(ints = { + 0, + (PACKAGE|PRIVATE), // two modes + Integer.MAX_VALUE, + Integer.MIN_VALUE, + }) + public void testBadInput(int modeToDrop) { + assertThrows(IllegalArgumentException.class, () -> MethodHandles.lookup().dropLookupMode(modeToDrop)); } } diff --git a/test/jdk/java/lang/invoke/FilterArgumentsTest.java b/test/jdk/java/lang/invoke/FilterArgumentsTest.java index 3c4884e7c6a..2326799cc1c 100644 --- a/test/jdk/java/lang/invoke/FilterArgumentsTest.java +++ b/test/jdk/java/lang/invoke/FilterArgumentsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -24,7 +24,7 @@ /* * @test * @bug 8194554 - * @run testng/othervm test.java.lang.invoke.FilterArgumentsTest + * @run junit/othervm test.java.lang.invoke.FilterArgumentsTest */ package test.java.lang.invoke; @@ -37,40 +37,40 @@ import java.util.List; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.methodType; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class FilterArgumentsTest { @Test - public static void testFilterA_B_C() throws Throwable { + public void testFilterA_B_C() throws Throwable { FilterTest test = new FilterTest( filterArguments(MH_TEST, 0, MH_FILTER_A, MH_FILTER_B, MH_FILTER_C)); test.run(List.of("A", "B", "C")); } @Test - public static void testFilterA_B() throws Throwable { + public void testFilterA_B() throws Throwable { FilterTest test = new FilterTest( filterArguments(MH_TEST, 0, MH_FILTER_A, MH_FILTER_B)); test.run(List.of("A", "B")); } @Test - public static void testFilterB_C() throws Throwable { + public void testFilterB_C() throws Throwable { FilterTest test = new FilterTest( filterArguments(MH_TEST, 1, MH_FILTER_B, MH_FILTER_C)); test.run(List.of("B", "C")); } @Test - public static void testFilterB() throws Throwable { + public void testFilterB() throws Throwable { FilterTest test = new FilterTest(filterArguments(MH_TEST, 1, MH_FILTER_B)); test.run(List.of("B")); } @Test - public static void testFilterC() throws Throwable { + public void testFilterC() throws Throwable { FilterTest test = new FilterTest(filterArguments(MH_TEST, 2, MH_FILTER_C)); test.run(List.of("C")); } @@ -85,8 +85,8 @@ public class FilterArgumentsTest { void run(List expected) throws Throwable { filters.clear(); - assertEquals((String)mh.invokeExact("x", 0, 'z'), "x-0-z"); - assertEquals(filters, expected); + assertEquals("x-0-z", (String)mh.invokeExact("x", 0, 'z')); + assertEquals(expected, filters); } static String filterA(String s) { diff --git a/test/jdk/java/lang/invoke/FindAccessTest.java b/test/jdk/java/lang/invoke/FindAccessTest.java index f8602ee22bd..3bcff4f5324 100644 --- a/test/jdk/java/lang/invoke/FindAccessTest.java +++ b/test/jdk/java/lang/invoke/FindAccessTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -23,7 +23,7 @@ /* @test * @bug 8139885 - * @run testng/othervm -ea -esa test.java.lang.invoke.FindAccessTest + * @run junit/othervm -ea -esa test.java.lang.invoke.FindAccessTest */ package test.java.lang.invoke; @@ -33,9 +33,10 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests for Lookup.findClass/accessClass extensions added in JEP 274. @@ -45,7 +46,7 @@ public class FindAccessTest { static final Lookup LOOKUP = MethodHandles.lookup(); @Test - public static void testFindSpecial() throws Throwable { + public void testFindSpecial() throws Throwable { FindSpecial.C c = new FindSpecial.C(); assertEquals("I1.m", c.m()); MethodType t = MethodType.methodType(String.class); @@ -54,25 +55,18 @@ public class FindAccessTest { } @Test - public static void testFindSpecialAbstract() throws Throwable { + public void testFindSpecialAbstract() throws Throwable { FindSpecial.C c = new FindSpecial.C(); assertEquals("q", c.q()); MethodType t = MethodType.methodType(String.class); - boolean caught = false; - try { - MethodHandle ci3q = LOOKUP.findSpecial(FindSpecial.I3.class, "q", t, FindSpecial.C.class); - } catch (Throwable thrown) { - if (!(thrown instanceof IllegalAccessException) || !FindSpecial.ABSTRACT_ERROR.equals(thrown.getMessage())) { - throw new AssertionError(thrown.getMessage(), thrown); - } - caught = true; - } - assertTrue(caught); + var thrown = assertThrows(IllegalAccessException.class, + () -> LOOKUP.findSpecial(FindSpecial.I3.class, "q", t, FindSpecial.C.class)); + assertEquals(FindSpecial.ABSTRACT_ERROR, thrown.getMessage()); } - @Test(expectedExceptions = {ClassNotFoundException.class}) - public static void testFindClassCNFE() throws ClassNotFoundException, IllegalAccessException { - LOOKUP.findClass("does.not.Exist"); + @Test + public void testFindClassCNFE() throws ClassNotFoundException, IllegalAccessException { + assertThrows(ClassNotFoundException.class, () -> LOOKUP.findClass("does.not.Exist")); } static class FindSpecial { diff --git a/test/jdk/java/lang/invoke/FoldTest.java b/test/jdk/java/lang/invoke/FoldTest.java index 157cfbffe2e..92ba246ebc8 100644 --- a/test/jdk/java/lang/invoke/FoldTest.java +++ b/test/jdk/java/lang/invoke/FoldTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -23,7 +23,7 @@ /* @test * @bug 8139885 - * @run testng/othervm -ea -esa test.java.lang.invoke.FoldTest + * @run junit/othervm -ea -esa test.java.lang.invoke.FoldTest */ package test.java.lang.invoke; @@ -36,9 +36,9 @@ import java.lang.invoke.MethodType; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for the new fold method handle combinator added in JEP 274. @@ -48,7 +48,7 @@ public class FoldTest { static final Lookup LOOKUP = MethodHandles.lookup(); @Test - public static void testFold0a() throws Throwable { + public void testFold0a() throws Throwable { // equivalence to foldArguments(MethodHandle,MethodHandle) MethodHandle fold = MethodHandles.foldArguments(Fold.MH_multer, 0, Fold.MH_adder); assertEquals(Fold.MT_folded1, fold.type()); @@ -56,7 +56,7 @@ public class FoldTest { } @Test - public static void testFold1a() throws Throwable { + public void testFold1a() throws Throwable { // test foldArguments for folding position 1 MethodHandle fold = MethodHandles.foldArguments(Fold.MH_multer, 1, Fold.MH_adder1); assertEquals(Fold.MT_folded1, fold.type()); @@ -64,7 +64,7 @@ public class FoldTest { } @Test - public static void testFold0b() throws Throwable { + public void testFold0b() throws Throwable { // test foldArguments equivalence with multiple types MethodHandle fold = MethodHandles.foldArguments(Fold.MH_str, 0, Fold.MH_comb); assertEquals(Fold.MT_folded2, fold.type()); @@ -72,7 +72,7 @@ public class FoldTest { } @Test - public static void testFold1b() throws Throwable { + public void testFold1b() throws Throwable { // test folgArguments for folding position 1, with multiple types MethodHandle fold = MethodHandles.foldArguments(Fold.MH_str, 1, Fold.MH_comb2); assertEquals(Fold.MT_folded3, fold.type()); @@ -81,7 +81,7 @@ public class FoldTest { } @Test - public static void testFoldArgumentsExample() throws Throwable { + public void testFoldArgumentsExample() throws Throwable { // test the JavaDoc foldArguments-with-pos example StringWriter swr = new StringWriter(); MethodHandle trace = LOOKUP.findVirtual(StringWriter.class, "write", methodType(void.class, String.class)).bindTo(swr); diff --git a/test/jdk/java/lang/invoke/InvokeGenericTest.java b/test/jdk/java/lang/invoke/InvokeGenericTest.java index ef201caead1..0be810506de 100644 --- a/test/jdk/java/lang/invoke/InvokeGenericTest.java +++ b/test/jdk/java/lang/invoke/InvokeGenericTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @summary unit tests for java.lang.invoke.MethodHandle.invoke * @compile InvokeGenericTest.java - * @run testng/othervm test.java.lang.invoke.InvokeGenericTest + * @run junit/othervm test.java.lang.invoke.InvokeGenericTest */ package test.java.lang.invoke; @@ -34,9 +34,13 @@ import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; import java.lang.reflect.*; import java.util.*; -import org.testng.*; -import static org.testng.AssertJUnit.*; -import org.testng.annotations.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * @@ -68,7 +72,7 @@ public class InvokeGenericTest { String testName; static int allPosTests, allNegTests; int posTests, negTests; - @AfterMethod + @AfterEach public void printCounts() { if (verbosity >= 2 && (posTests | negTests) != 0) { System.out.println(); @@ -92,14 +96,14 @@ public class InvokeGenericTest { testName = name; } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { calledLog.clear(); calledLog.add(null); nextArgVal = INITIAL_ARG_VAL; } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { int posTests = allPosTests, negTests = allNegTests; if (verbosity >= 2 && (posTests | negTests) != 0) { @@ -127,7 +131,7 @@ public class InvokeGenericTest { System.out.println("actual: "+actual); System.out.println("ex. types: "+getClasses(expected)); System.out.println("act. types: "+getClasses(actual)); - assertEquals("previous method call", expected, actual); + assertEquals(expected, actual, "previous method call"); } static void printCalled(MethodHandle target, String name, Object... args) { if (verbosity >= 3) @@ -389,8 +393,7 @@ public class InvokeGenericTest { } public void testWrongArgumentCount(List> expect, List> observe) throws Throwable { countTest(false); - if (expect.equals(observe)) - assert(false); + assertNotEquals(expect, observe); MethodHandle target = callable(expect); Object[] args = zeroArgs(observe); Object junk; @@ -473,28 +476,25 @@ public class InvokeGenericTest { mh = MethodHandles.filterReturnValue(mh, toString_MH); mh = mh.asType(type); Object res = null; - if (nargs == 2) { - res = mh.invoke((Object)args[0], (Object)args[1]); - assertEquals(expectString, res); - res = mh.invoke((String)args[0], (Object)args[1]); - assertEquals(expectString, res); - res = mh.invoke((Object)args[0], (String)args[1]); - assertEquals(expectString, res); - res = mh.invoke((String)args[0], (String)args[1]); - assertEquals(expectString, res); - res = mh.invoke((String)args[0], (CharSequence)args[1]); - assertEquals(expectString, res); - res = mh.invoke((CharSequence)args[0], (Object)args[1]); - assertEquals(expectString, res); - res = (String) mh.invoke((Object)args[0], (Object)args[1]); - assertEquals(expectString, res); - res = (String) mh.invoke((String)args[0], (Object)args[1]); - assertEquals(expectString, res); - res = (CharSequence) mh.invoke((String)args[0], (Object)args[1]); - assertEquals(expectString, res); - } else { - assert(false); // write this code - } + assertEquals(2, nargs); + res = mh.invoke((Object)args[0], (Object)args[1]); + assertEquals(expectString, res); + res = mh.invoke((String)args[0], (Object)args[1]); + assertEquals(expectString, res); + res = mh.invoke((Object)args[0], (String)args[1]); + assertEquals(expectString, res); + res = mh.invoke((String)args[0], (String)args[1]); + assertEquals(expectString, res); + res = mh.invoke((String)args[0], (CharSequence)args[1]); + assertEquals(expectString, res); + res = mh.invoke((CharSequence)args[0], (Object)args[1]); + assertEquals(expectString, res); + res = (String) mh.invoke((Object)args[0], (Object)args[1]); + assertEquals(expectString, res); + res = (String) mh.invoke((String)args[0], (Object)args[1]); + assertEquals(expectString, res); + res = (CharSequence) mh.invoke((String)args[0], (Object)args[1]); + assertEquals(expectString, res); //System.out.println(res); } diff --git a/test/jdk/java/lang/invoke/InvokeMethodHandleWithBadArgument.java b/test/jdk/java/lang/invoke/InvokeMethodHandleWithBadArgument.java index 2479c22b2f4..f2749cfb164 100644 --- a/test/jdk/java/lang/invoke/InvokeMethodHandleWithBadArgument.java +++ b/test/jdk/java/lang/invoke/InvokeMethodHandleWithBadArgument.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -25,7 +25,7 @@ * @test * @bug 8157246 * @summary Tests invocation of MethodHandle with invalid leading argument - * @run testng/othervm test.java.lang.invoke.InvokeMethodHandleWithBadArgument + * @run junit/othervm test.java.lang.invoke.InvokeMethodHandleWithBadArgument */ package test.java.lang.invoke; @@ -38,9 +38,9 @@ import java.lang.invoke.VarHandle; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; /** * Tests invocation of MethodHandle with invalid leading argument such as @@ -49,86 +49,100 @@ import org.testng.annotations.*; public class InvokeMethodHandleWithBadArgument { // ---- null array reference ---- - @Test(expectedExceptions = {NullPointerException.class}) - public static void testAsSpreaderPosInvokeWithNull() throws Throwable { + @Test + public void testAsSpreaderPosInvokeWithNull() throws Throwable { MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 3); - spreader.invoke("A", null, "B"); + assertThrows(NullPointerException.class, () -> spreader.invoke("A", null, "B")); } - @Test(expectedExceptions = {NullPointerException.class}) - public static void testAsSpreaderInvokeWithNull() throws Throwable { + @Test + public void testAsSpreaderInvokeWithNull() throws Throwable { MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 2); - assert ((boolean) spreader.invokeExact(new String[]{"me", "me"})); - boolean eq = (boolean) spreader.invokeExact((String[]) null); + assertTrue((boolean) spreader.invokeExact(new String[]{"me", "me"})); + assertThrows(NullPointerException.class, () -> { + boolean eq = (boolean) spreader.invokeExact((String[]) null); + }); } // ---- incorrect array element count ---- - @Test(expectedExceptions = {IllegalArgumentException.class}) - public static void testAsSpreaderPosInvokeWithBadElementCount() throws Throwable { + @Test + public void testAsSpreaderPosInvokeWithBadElementCount() throws Throwable { MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 3); - spreader.invoke("A", new int[]{1, 2}, "B"); + assertThrows(IllegalArgumentException.class, () -> spreader.invoke("A", new int[]{1, 2}, "B")); } - @Test(expectedExceptions = {IllegalArgumentException.class}) - public static void testAsSpreaderInvokeWithBadElementCount() throws Throwable { + @Test + public void testAsSpreaderInvokeWithBadElementCount() throws Throwable { MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 2); - assert (!(boolean) spreader.invokeExact(new String[]{"me", "thee"})); - boolean eq = (boolean) spreader.invokeExact(new String[0]); + assertFalse((boolean) spreader.invokeExact(new String[]{"me", "thee"})); + assertThrows(IllegalArgumentException.class, () -> { + boolean eq = (boolean) spreader.invokeExact(new String[0]); + }); } // ---- spread no argument ---- @Test - public static void testAsSpreaderPosInvokeWithZeroLength() throws Throwable { + public void testAsSpreaderPosInvokeWithZeroLength() throws Throwable { MethodHandle spreader = MH_spread.asSpreader(1, int[].class, 0); - assert("A123B".equals(spreader.invoke("A", (int[])null, 1, 2, 3, "B"))); + assertEquals("A123B", spreader.invoke("A", (int[]) null, 1, 2, 3, "B")); } @Test - public static void testAsSpreaderInvokeWithZeroLength() throws Throwable { + public void testAsSpreaderInvokeWithZeroLength() throws Throwable { MethodHandle spreader = MH_String_equals.asSpreader(String[].class, 0); - assert ((boolean) spreader.invokeExact("me", (Object)"me", new String[0])); + assertTrue((boolean) spreader.invokeExact("me", (Object)"me", new String[0])); boolean eq = (boolean) spreader.invokeExact("me", (Object)"me", (String[]) null); } // ---- invokers with null method/var handle argument ---- - @Test(expectedExceptions = {NullPointerException.class}) - public static void testInvokerWithNull() throws Throwable { + @Test + public void testInvokerWithNull() throws Throwable { MethodType type = methodType(int.class, int.class, int.class); MethodHandle invoker = MethodHandles.invoker(type); - assert((int) invoker.invoke(MH_add, 1, 2) == 3); - int sum = (int)invoker.invoke((MethodHandle)null, 1, 2); + assertEquals(3, (int) invoker.invoke(MH_add, 1, 2)); + assertThrows(NullPointerException.class, () -> { + int sum = (int)invoker.invoke((MethodHandle)null, 1, 2); + }); } - @Test(expectedExceptions = {NullPointerException.class}) - public static void testExactInvokerWithNull() throws Throwable { + @Test + public void testExactInvokerWithNull() throws Throwable { MethodType type = methodType(int.class, int.class, int.class); MethodHandle invoker = MethodHandles.exactInvoker(type); - assert((int) invoker.invoke(MH_add, 1, 2) == 3); - int sum = (int)invoker.invokeExact((MethodHandle)null, 1, 2); + assertEquals(3, (int) invoker.invoke(MH_add, 1, 2)); + assertThrows(NullPointerException.class, () -> { + int sum = (int)invoker.invokeExact((MethodHandle)null, 1, 2); + }); } - @Test(expectedExceptions = {NullPointerException.class}) - public static void testSpreadInvokerWithNull() throws Throwable { + @Test + public void testSpreadInvokerWithNull() throws Throwable { MethodType type = methodType(boolean.class, String.class, String.class); MethodHandle invoker = MethodHandles.spreadInvoker(type, 0); - assert ((boolean) invoker.invoke(MH_String_equals, new String[]{"me", "me"})); - boolean eq = (boolean) invoker.invoke((MethodHandle)null, new String[]{"me", "me"}); + assertTrue((boolean) invoker.invoke(MH_String_equals, new String[]{"me", "me"})); + assertThrows(NullPointerException.class, () -> { + boolean eq = (boolean) invoker.invoke((MethodHandle)null, new String[]{"me", "me"}); + }); } - @Test(expectedExceptions = {NullPointerException.class}) - public static void testVarHandleInvokerWithNull() throws Throwable { + @Test + public void testVarHandleInvokerWithNull() throws Throwable { VarHandle.AccessMode am = VarHandle.AccessMode.GET; MethodHandle invoker = MethodHandles.varHandleInvoker(am, VH_array.accessModeType(am)); - assert ((int) invoker.invoke(VH_array, array, 3) == 3); - int value = (int)invoker.invoke((VarHandle)null, array, 3); + assertEquals(3, (int) invoker.invoke(VH_array, array, 3)); + assertThrows(NullPointerException.class, () -> { + int value = (int)invoker.invoke((VarHandle)null, array, 3); + }); } - @Test(expectedExceptions = {NullPointerException.class}) - public static void testVarHandleExactInvokerWithNull() throws Throwable { + @Test + public void testVarHandleExactInvokerWithNull() throws Throwable { VarHandle.AccessMode am = VarHandle.AccessMode.GET; MethodHandle invoker = MethodHandles.varHandleExactInvoker(am, VH_array.accessModeType(am)); - assert ((int) invoker.invoke(VH_array, array, 3) == 3); - int value = (int)invoker.invokeExact((VarHandle)null, array, 3); + assertEquals(3, (int) invoker.invoke(VH_array, array, 3)); + assertThrows(NullPointerException.class, () -> { + int value = (int)invoker.invokeExact((VarHandle)null, array, 3); + }); } static final Lookup LOOKUP = MethodHandles.lookup(); diff --git a/test/jdk/java/lang/invoke/InvokeWithArgumentsTest.java b/test/jdk/java/lang/invoke/InvokeWithArgumentsTest.java index 63a2101bd67..3a705aca699 100644 --- a/test/jdk/java/lang/invoke/InvokeWithArgumentsTest.java +++ b/test/jdk/java/lang/invoke/InvokeWithArgumentsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -23,19 +23,19 @@ /* @test * @summary basic tests for MethodHandle.invokeWithArguments - * @run testng test.java.lang.invoke.InvokeWithArgumentsTest + * @run junit test.java.lang.invoke.InvokeWithArgumentsTest */ package test.java.lang.invoke; -import org.testng.Assert; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.WrongMethodTypeException; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public class InvokeWithArgumentsTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); @@ -49,10 +49,7 @@ public class InvokeWithArgumentsTest { MethodHandle mh = L.findStatic(L.lookupClass(), "arity", methodType(Object[].class, Object.class, Object.class, Object[].class)); - try { - mh.invokeWithArguments(""); - Assert.fail("WrongMethodTypeException expected"); - } catch (WrongMethodTypeException e) {} + assertThrows(WrongMethodTypeException.class, () -> mh.invokeWithArguments("")); } static Object[] passThrough(String... a) { @@ -72,10 +69,10 @@ public class InvokeWithArgumentsTest { // Note: the actual array is not preserved, the elements will be // unpacked and then packed into a new array before invoking the method - String[] expected = (String[]) mh.invokeWithArguments(actual); + String[] result = (String[]) mh.invokeWithArguments(actual); - Assert.assertTrue(actual != expected, "Array should not pass through"); - Assert.assertEquals(actual, expected, "Array contents should be equal"); + assertNotSame(actual, result, "Array should not pass through"); + assertArrayEquals(actual, result, "Array contents should be equal"); } @Test @@ -89,8 +86,8 @@ public class InvokeWithArgumentsTest { // will cast to Object become the single element of a new Object[] array Object[] expected = (Object[]) mh.invokeWithArguments("", actual); - Assert.assertEquals(1, expected.length, "Array should contain just one element"); - Assert.assertTrue(actual == expected[0], "Array should pass through"); + assertEquals(1, expected.length, "Array should contain just one element"); + assertSame(actual, expected[0], "Array should pass through"); } static void intArray(int... a) { @@ -100,20 +97,14 @@ public class InvokeWithArgumentsTest { public void testPrimitiveArrayWithNull() throws Throwable { MethodHandle mh = L.findStatic(L.lookupClass(), "intArray", methodType(void.class, int[].class)); - try { - mh.invokeWithArguments(null, null); - Assert.fail("NullPointerException expected"); - } catch (NullPointerException e) {} + assertThrows(NullPointerException.class, () -> mh.invokeWithArguments(null, null)); } @Test public void testPrimitiveArrayWithRef() throws Throwable { MethodHandle mh = L.findStatic(L.lookupClass(), "intArray", methodType(void.class, int[].class)); - try { - mh.invokeWithArguments("A", "B"); - Assert.fail("ClassCastException expected"); - } catch (ClassCastException e) {} + assertThrows(ClassCastException.class, () -> mh.invokeWithArguments("A", "B")); } @@ -127,9 +118,6 @@ public class InvokeWithArgumentsTest { // All numbers, should not throw mh.invokeWithArguments(1, 1.0, 1.0F, 1L); - try { - mh.invokeWithArguments("A"); - Assert.fail("ClassCastException expected"); - } catch (ClassCastException e) {} + assertThrows(ClassCastException.class, () -> mh.invokeWithArguments("A")); } } diff --git a/test/jdk/java/lang/invoke/JavaDocExamplesTest.java b/test/jdk/java/lang/invoke/JavaDocExamplesTest.java index 53257d9876d..0fa2614c83f 100644 --- a/test/jdk/java/lang/invoke/JavaDocExamplesTest.java +++ b/test/jdk/java/lang/invoke/JavaDocExamplesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2025, 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 @@ -24,7 +24,7 @@ /* @test * @summary example code used in javadoc for java.lang.invoke API * @compile JavaDocExamplesTest.java - * @run testng/othervm test.java.lang.invoke.JavaDocExamplesTest + * @run junit/othervm test.java.lang.invoke.JavaDocExamplesTest */ package test.java.lang.invoke; @@ -36,8 +36,8 @@ import static java.lang.invoke.MethodType.*; import java.util.*; -import org.testng.*; -import org.testng.annotations.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author jrose @@ -350,14 +350,14 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum")); static void assertEquals(Object exp, Object act) { if (verbosity > 0) System.out.println("result: "+act); - Assert.assertEquals(exp, act); + Assertions.assertEquals(exp, act); } static void assertTrue(boolean b) { if (verbosity > 0) { System.out.println("result: " + b); } - Assert.assertTrue(b); + Assertions.assertTrue(b); } @Test public void testMethodHandlesSummary() throws Throwable { diff --git a/test/jdk/java/lang/invoke/JavaUtilConcurrentLookupTest.java b/test/jdk/java/lang/invoke/JavaUtilConcurrentLookupTest.java index 9715de8fd46..a9a6861bc05 100644 --- a/test/jdk/java/lang/invoke/JavaUtilConcurrentLookupTest.java +++ b/test/jdk/java/lang/invoke/JavaUtilConcurrentLookupTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -25,12 +25,11 @@ * @summary Tests that Lookup can be produced from classes under java.util.concurrent * @bug 8154447 * @compile/module=java.base java/util/concurrent/LookupTester.java - * @run testng/othervm JavaUtilConcurrentLookupTest + * @run junit/othervm JavaUtilConcurrentLookupTest */ -import org.testng.annotations.Test; - import java.util.concurrent.LookupTester; +import org.junit.jupiter.api.Test; public class JavaUtilConcurrentLookupTest { diff --git a/test/jdk/java/lang/invoke/LoopCombinatorTest.java b/test/jdk/java/lang/invoke/LoopCombinatorTest.java index 15fb9d320a3..91a752f2666 100644 --- a/test/jdk/java/lang/invoke/LoopCombinatorTest.java +++ b/test/jdk/java/lang/invoke/LoopCombinatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -32,7 +32,7 @@ * @bug 8154751 * @bug 8154754 * @bug 8167974 - * @run testng/othervm -ea -esa test.java.lang.invoke.LoopCombinatorTest + * @run junit/othervm -ea -esa test.java.lang.invoke.LoopCombinatorTest */ package test.java.lang.invoke; @@ -45,9 +45,12 @@ import java.util.*; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; /** * Tests for the loop combinators introduced in JEP 274. @@ -57,7 +60,7 @@ public class LoopCombinatorTest { static final Lookup LOOKUP = MethodHandles.lookup(); @Test - public static void testLoopFac() throws Throwable { + public void testLoopFac() throws Throwable { MethodHandle[] counterClause = new MethodHandle[]{Fac.MH_zero, Fac.MH_inc}; MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin}; MethodHandle loop = MethodHandles.loop(counterClause, accumulatorClause); @@ -66,7 +69,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopFacNullInit() throws Throwable { + public void testLoopFacNullInit() throws Throwable { // null initializer for counter, should initialize to 0 MethodHandle[] counterClause = new MethodHandle[]{null, Fac.MH_inc}; MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin}; @@ -76,7 +79,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopNullInit() throws Throwable { + public void testLoopNullInit() throws Throwable { // null initializer for counter, should initialize to 0, one-clause loop MethodHandle[] counterClause = new MethodHandle[]{null, Loop.MH_inc, Loop.MH_pred, Loop.MH_fin}; MethodHandle loop = MethodHandles.loop(counterClause); @@ -85,7 +88,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopVoid1() throws Throwable { + public void testLoopVoid1() throws Throwable { // construct a post-checked loop that only does one iteration and has a void body and void local state MethodHandle loop = MethodHandles.loop(new MethodHandle[]{Empty.MH_f, Empty.MH_f, Empty.MH_pred, null}); assertEquals(MethodType.methodType(void.class), loop.type()); @@ -93,7 +96,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopVoid2() throws Throwable { + public void testLoopVoid2() throws Throwable { // construct a post-checked loop that only does one iteration and has a void body and void local state, // initialized implicitly from the step type MethodHandle loop = MethodHandles.loop(new MethodHandle[]{null, Empty.MH_f, Empty.MH_pred, null}); @@ -102,7 +105,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopVoid3() throws Throwable { + public void testLoopVoid3() throws Throwable { // construct a post-checked loop that only does one iteration and has a void body and void local state, // and that has a void finalizer MethodHandle loop = MethodHandles.loop(new MethodHandle[]{null, Empty.MH_f, Empty.MH_pred, Empty.MH_f}); @@ -111,7 +114,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopFacWithVoidState() throws Throwable { + public void testLoopFacWithVoidState() throws Throwable { // like testLoopFac, but with additional void state that outputs a dot MethodHandle[] counterClause = new MethodHandle[]{Fac.MH_zero, Fac.MH_inc}; MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin}; @@ -122,7 +125,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopVoidInt() throws Throwable { + public void testLoopVoidInt() throws Throwable { // construct a post-checked loop that only does one iteration and has a void body and void local state, // and that returns a constant MethodHandle loop = MethodHandles.loop(new MethodHandle[]{null, Empty.MH_f, Empty.MH_pred, Empty.MH_c}); @@ -131,7 +134,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopWithVirtuals() throws Throwable { + public void testLoopWithVirtuals() throws Throwable { // construct a loop (to calculate factorial) that uses a mix of static and virtual methods MethodHandle[] counterClause = new MethodHandle[]{null, LoopWithVirtuals.permute(LoopWithVirtuals.MH_inc)}; MethodHandle[] accumulatorClause = new MethodHandle[]{ @@ -147,7 +150,7 @@ public class LoopCombinatorTest { } @Test - public static void testLoopOmitPred() throws Throwable { + public void testLoopOmitPred() throws Throwable { // construct a loop to calculate factorial that omits a predicate MethodHandle[] counterClause = new MethodHandle[]{null, Fac.MH_inc, null, Fac.MH_fin}; MethodHandle[] accumulatorClause = new MethodHandle[]{Fac.MH_one, Fac.MH_mult, Fac.MH_pred, Fac.MH_fin}; @@ -156,7 +159,6 @@ public class LoopCombinatorTest { assertEquals(120, loop.invoke(5)); } - @DataProvider static Object[][] negativeTestData() { MethodHandle i0 = MethodHandles.constant(int.class, 0); MethodHandle ii = MethodHandles.dropArguments(i0, 0, int.class, int.class); @@ -214,36 +216,36 @@ public class LoopCombinatorTest { } } - @Test(dataProvider = "negativeTestData") - public static void testLoopNegative(MethodHandle[][] clauses, String expectedMessage) throws Throwable { - boolean caught = false; - try { - MH_loop.invokeWithArguments((Object[]) clauses); - } catch (IllegalArgumentException iae) { - assertEquals(expectedMessage, iae.getMessage()); - caught = true; - } - assertTrue(caught); + @ParameterizedTest + @MethodSource("negativeTestData") + public void testLoopNegative(MethodHandle[][] clauses, String expectedMessage) throws Throwable { + var iae = assertThrows(IllegalArgumentException.class, () -> MH_loop.invokeWithArguments((Object[]) clauses)); + assertEquals(expectedMessage, iae.getMessage()); } - @Test(dataProvider = "whileLoopTestData") - public static void testWhileLoop(MethodHandle MH_zero, - MethodHandle MH_pred, - MethodHandle MH_step, - String messageOrNull) throws Throwable { + @ParameterizedTest + @MethodSource("whileLoopPassData") + public void testWhileLoop(MethodHandle MH_zero, + MethodHandle MH_pred, + MethodHandle MH_step) throws Throwable { // int i = 0; while (i < limit) { ++i; } return i; => limit - try { - MethodHandle loop = MethodHandles.whileLoop(MH_zero, MH_pred, MH_step); - assert messageOrNull == null; - if (MH_step.type().equals(While.MH_step.type())) - assertEquals(While.MT_while, loop.type()); - assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type()); - while (loop.type().parameterCount() > 1) loop = snip(loop); - assertEquals(23, loop.invoke(23)); - } catch (IllegalArgumentException iae) { - assert messageOrNull != null; - assertEqualsFIXME(messageOrNull, iae.getMessage()); - } + MethodHandle loop = MethodHandles.whileLoop(MH_zero, MH_pred, MH_step); + if (MH_step.type().equals(While.MH_step.type())) + assertEquals(While.MT_while, loop.type()); + assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type()); + while (loop.type().parameterCount() > 1) loop = snip(loop); + assertEquals(23, loop.invoke(23)); + } + + @ParameterizedTest + @MethodSource("whileLoopFailData") + public void testWhileLoopFail(MethodHandle MH_zero, + MethodHandle MH_pred, + MethodHandle MH_step, + String message) throws Throwable { + // int i = 0; while (i < limit) { ++i; } return i; => limit + var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.whileLoop(MH_zero, MH_pred, MH_step)); + assertEqualsFIXME(message, iae.getMessage()); } static void assertEqualsFIXME(String expect, String actual) { @@ -253,8 +255,7 @@ public class LoopCombinatorTest { } } - @DataProvider - static Object[][] whileLoopTestData() { + static Object[][] whileLoopPassData() { MethodHandle zeroI = While.MH_zero, zeroX = snip(zeroI), @@ -268,28 +269,44 @@ public class LoopCombinatorTest { ; return new Object[][] { // normal while loop clauses, perhaps with effectively-identical reductions - {zeroI, predII, stepII, null}, - {zeroX, predII, stepII, null}, - {null, predII, stepII, null}, + {zeroI, predII, stepII}, + {zeroX, predII, stepII}, + {null, predII, stepII}, // expanded while loop clauses - {zeroIB, predIIB, stepIIB, null}, - {zeroI, predIIB, stepIIB, null}, - {null, predIIB, stepIIB, null}, - {zeroIB, predII, stepIIB, null}, - {zeroX, predII, stepIIB, null}, - {null, predII, stepIIB, null}, - // short step clauses cause errors - {zeroI, predII, stepIX, "loop predicate must match: (int,int)boolean != (int)boolean"}, - {zeroIB, predIX, stepIX, "loop initializer must match: (int,byte)int != ()int"}, - // bad body type - {zeroI, predII, tweak(stepII, -1, char.class), "body function must match: (int,int)char != (char,int,int)char"}, - {zeroI, predII, tweak(stepII, 0, char.class), "body function must match: (char,int)int != (int,char,int)int"}, - // bad pred type - {zeroI, tweak(predII, -1, char.class), stepII, "loop predicate must match: (int,int)char != (int,int)boolean"}, - {zeroI, tweak(predII, 0, char.class), stepII, "loop predicate must match: (char,int)boolean != (int,int)boolean"}, - // bad init type - {tweak(zeroI, -1, char.class), predII, stepII, "loop initializer must match: (int)char != (int)int"}, - {tweak(zeroI, 0, char.class), predII, stepII, "loop initializer must match: (char)int != (int)int"}, + {zeroIB, predIIB, stepIIB}, + {zeroI, predIIB, stepIIB}, + {null, predIIB, stepIIB}, + {zeroIB, predII, stepIIB}, + {zeroX, predII, stepIIB}, + {null, predII, stepIIB}, + }; + } + + static Object[][] whileLoopFailData() { + MethodHandle + zeroI = While.MH_zero, + zeroX = snip(zeroI), + zeroIB = slap(zeroI, byte.class), + predII = While.MH_pred, + predIX = snip(predII), + predIIB = slap(predII, byte.class), + stepII = While.MH_step, + stepIX = snip(stepII), + stepIIB = slap(stepII, byte.class) + ; + return new Object[][] { + // short step clauses cause errors + {zeroI, predII, stepIX, "loop predicate must match: (int,int)boolean != (int)boolean"}, + {zeroIB, predIX, stepIX, "loop initializer must match: (int,byte)int != ()int"}, + // bad body type + {zeroI, predII, tweak(stepII, -1, char.class), "body function must match: (int,int)char != (char,int,int)char"}, + {zeroI, predII, tweak(stepII, 0, char.class), "body function must match: (char,int)int != (int,char,int)int"}, + // bad pred type + {zeroI, tweak(predII, -1, char.class), stepII, "loop predicate must match: (int,int)char != (int,int)boolean"}, + {zeroI, tweak(predII, 0, char.class), stepII, "loop predicate must match: (char,int)boolean != (int,int)boolean"}, + // bad init type + {tweak(zeroI, -1, char.class), predII, stepII, "loop initializer must match: (int)char != (int)int"}, + {tweak(zeroI, 0, char.class), predII, stepII, "loop initializer must match: (char)int != (int)int"}, }; } @@ -323,53 +340,50 @@ public class LoopCombinatorTest { } @Test - public static void testWhileLoopNoIteration() throws Throwable { + public void testWhileLoopNoIteration() throws Throwable { // a while loop that never executes its body because the predicate evaluates to false immediately MethodHandle loop = MethodHandles.whileLoop(While.MH_initString, While.MH_predString, While.MH_stepString); assertEquals(While.MT_string, loop.type()); assertEquals("a", loop.invoke()); } - @Test(dataProvider = "whileLoopTestData") - public static void testDoWhileLoop(MethodHandle MH_zero, - MethodHandle MH_pred, - MethodHandle MH_step, - String messageOrNull) throws Throwable { + @ParameterizedTest + @MethodSource("whileLoopPassData") + public void testDoWhileLoopPass(MethodHandle MH_zero, + MethodHandle MH_pred, + MethodHandle MH_step) throws Throwable { // int i = 0; do { ++i; } while (i < limit); return i; => limit - try { - MethodHandle loop = MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred); - assert messageOrNull == null; - if (MH_step.type().equals(While.MH_step.type())) - assertEquals(While.MT_while, loop.type()); - assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type()); - while (loop.type().parameterCount() > 1) loop = snip(loop); - assertEquals(23, loop.invoke(23)); - } catch (IllegalArgumentException iae) { - assert messageOrNull != null; - if (!messageOrNull.equals(iae.getMessage())) { - // just issue a warning - System.out.println("*** "+messageOrNull+"\n != "+iae.getMessage()); - } - } + MethodHandle loop = MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred); + if (MH_step.type().equals(While.MH_step.type())) + assertEquals(While.MT_while, loop.type()); + assertEquals(MH_step.type().dropParameterTypes(0, 1), loop.type()); + while (loop.type().parameterCount() > 1) loop = snip(loop); + assertEquals(23, loop.invoke(23)); + } + + @ParameterizedTest + @MethodSource("whileLoopFailData") + public void testDoWhileLoopFail(MethodHandle MH_zero, + MethodHandle MH_pred, + MethodHandle MH_step, + String message) throws Throwable { + // int i = 0; do { ++i; } while (i < limit); return i; => limit + var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.doWhileLoop(MH_zero, MH_step, MH_pred)); + assertEqualsFIXME(message, iae.getMessage()); } @Test - public static void testDoWhileBadInit() throws Throwable { - boolean caught = false; - try { - While w = new While(); - MethodHandle loop = MethodHandles.doWhileLoop(MethodHandles.empty(methodType(char.class)), - While.MH_voidBody.bindTo(w), - While.MH_voidPred.bindTo(w)); - } catch (IllegalArgumentException iae) { - assertEquals("loop initializer must match: ()char != (int)void", iae.getMessage()); - caught = true; - } - assertTrue(caught); + public void testDoWhileBadInit() throws Throwable { + While w = new While(); + var iae = assertThrows(IllegalArgumentException.class, () -> + MethodHandles.doWhileLoop(MethodHandles.empty(methodType(char.class)), + While.MH_voidBody.bindTo(w), + While.MH_voidPred.bindTo(w))); + assertEquals("loop initializer must match: ()char != (int)void", iae.getMessage()); } @Test - public static void testWhileZip() throws Throwable { + public void testWhileZip() throws Throwable { MethodHandle loop = MethodHandles.doWhileLoop(While.MH_zipInitZip, While.MH_zipStep, While.MH_zipPred); assertEquals(While.MT_zip, loop.type()); List a = Arrays.asList("a", "b", "c", "d"); @@ -379,22 +393,17 @@ public class LoopCombinatorTest { } @Test - public static void testWhileBadInit() throws Throwable { - boolean caught = false; - try { - While w = new While(); - MethodHandle loop = MethodHandles.whileLoop(MethodHandles.empty(methodType(void.class, char.class)), - While.MH_voidPred.bindTo(w), - While.MH_voidBody.bindTo(w)); - } catch (IllegalArgumentException iae) { - assertEquals("loop initializer must match: (char)void != (int)void", iae.getMessage()); - caught = true; - } - assertTrue(caught); + public void testWhileBadInit() throws Throwable { + While w = new While(); + var iae = assertThrows(IllegalArgumentException.class, () -> + MethodHandles.whileLoop(MethodHandles.empty(methodType(void.class, char.class)), + While.MH_voidPred.bindTo(w), + While.MH_voidBody.bindTo(w))); + assertEquals("loop initializer must match: (char)void != (int)void", iae.getMessage()); } @Test - public static void testWhileVoidInit() throws Throwable { + public void testWhileVoidInit() throws Throwable { While w = new While(); int v = 5; MethodHandle loop = MethodHandles.whileLoop(While.MH_voidInit.bindTo(w), While.MH_voidPred.bindTo(w), @@ -405,7 +414,7 @@ public class LoopCombinatorTest { } @Test - public static void testDoWhileVoidInit() throws Throwable { + public void testDoWhileVoidInit() throws Throwable { While w = new While(); int v = 5; MethodHandle loop = MethodHandles.doWhileLoop(While.MH_voidInit.bindTo(w), While.MH_voidBody.bindTo(w), @@ -415,24 +424,25 @@ public class LoopCombinatorTest { assertEquals(v, w.i); } - @DataProvider static Object[][] nullArgs() { MethodHandle c = MethodHandles.constant(int.class, 1); return new Object[][]{{null, c}, {c, null}}; } - @Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class) - public static void testWhileNullArgs(MethodHandle pred, MethodHandle body) { - MethodHandles.whileLoop(null, pred, body); + @ParameterizedTest + @MethodSource("nullArgs") + public void testWhileNullArgs(MethodHandle pred, MethodHandle body) { + assertThrows(NullPointerException.class, () -> MethodHandles.whileLoop(null, pred, body)); } - @Test(dataProvider = "nullArgs", expectedExceptions = NullPointerException.class) - public static void testDoWhileNullArgs(MethodHandle body, MethodHandle pred) { - MethodHandles.whileLoop(null, body, pred); + @ParameterizedTest + @MethodSource("nullArgs") + public void testDoWhileNullArgs(MethodHandle body, MethodHandle pred) { + assertThrows(NullPointerException.class, () -> MethodHandles.whileLoop(null, body, pred)); } @Test - public static void testCountedLoop() throws Throwable { + public void testCountedLoop() throws Throwable { // String s = "Lambdaman!"; for (int i = 0; i < 13; ++i) { s = "na " + s; } return s; => a variation on a well known theme MethodHandle fit13 = MethodHandles.dropArguments(MethodHandles.constant(int.class, 13), 0, String.class); MethodHandle loop = MethodHandles.countedLoop(fit13, Counted.MH_start, Counted.MH_step); @@ -441,7 +451,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedLoopVoidInit() throws Throwable { + public void testCountedLoopVoidInit() throws Throwable { MethodHandle fit5 = MethodHandles.constant(int.class, 5); for (int i = 0; i < 8; i++) { MethodHandle zero = MethodHandles.zero(void.class); @@ -465,7 +475,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedArrayLoop() throws Throwable { + public void testCountedArrayLoop() throws Throwable { // int[] a = new int[]{0}; for (int i = 0; i < 13; ++i) { ++a[0]; } => a[0] == 13 MethodHandle fit13 = MethodHandles.dropArguments(MethodHandles.constant(int.class, 13), 0, int[].class); MethodHandle loop = MethodHandles.countedLoop(fit13, null, Counted.MH_stepUpdateArray); @@ -476,37 +486,30 @@ public class LoopCombinatorTest { } @Test - public static void testCountedPrintingLoop() throws Throwable { + public void testCountedPrintingLoop() throws Throwable { MethodHandle fit5 = MethodHandles.constant(int.class, 5); MethodHandle loop = MethodHandles.countedLoop(fit5, null, Counted.MH_printHello); assertEquals(Counted.MT_countedPrinting, loop.type()); loop.invoke(); } - @Test(expectedExceptions = NullPointerException.class) - public static void testCountedLoopNullBody() throws Throwable { + @Test + public void testCountedLoopNullBody() throws Throwable { MethodHandle h5 = MethodHandles.constant(int.class, 5); MethodHandle h13 = MethodHandles.constant(int.class, 13); - MethodHandle loop = MethodHandles.countedLoop(h5, h13, null); - assertEquals(methodType(int.class), loop.type()); - assertEquals(13, loop.invoke()); + assertThrows(NullPointerException.class, () -> MethodHandles.countedLoop(h5, h13, null)); } - @Test(expectedExceptions = NullPointerException.class) - public static void testCountedLoopNullIterations() throws Throwable { - MethodHandle loop = MethodHandles.countedLoop(null, null, null); - assertEquals(methodType(void.class), loop.type()); - loop.invoke(); + @Test + public void testCountedLoopNullIterations() throws Throwable { + assertThrows(NullPointerException.class, () -> MethodHandles.countedLoop(null, null, null)); } - @Test(expectedExceptions = NullPointerException.class) - public static void testCountedLoopNullInitAndBody() throws Throwable { - MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, null); - assertEquals(methodType(void.class), loop.type()); - loop.invoke(); + @Test + public void testCountedLoopNullInitAndBody() throws Throwable { + assertThrows(NullPointerException.class, () -> MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, null)); } - @DataProvider static Object[][] countedLoopBodyParameters() { Class V = String.class, I = int.class, A = List.class; // return types are of these forms: @@ -531,8 +534,9 @@ public class LoopCombinatorTest { }; } - @Test(dataProvider = "countedLoopBodyParameters") - public static void testCountedLoopBodyParameters(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable { + @ParameterizedTest + @MethodSource("countedLoopBodyParameters") + public void testCountedLoopBodyParameters(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable { MethodHandle loop = MethodHandles.countedLoop( MethodHandles.empty(countType), initType == null ? null : MethodHandles.empty(initType), @@ -546,13 +550,14 @@ public class LoopCombinatorTest { assertEquals(expectType, loop.type()); } - @Test(dataProvider = "countedLoopBodyParameters") - public static void testCountedLoopBodyParametersNullInit(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable { + @ParameterizedTest + @MethodSource("countedLoopBodyParameters") + public void testCountedLoopBodyParametersNullInit(MethodType countType, MethodType initType, MethodType bodyType) throws Throwable { testCountedLoopBodyParameters(countType, null, bodyType); } @Test - public static void testCountedLoopStateInitializedToNull() throws Throwable { + public void testCountedLoopStateInitializedToNull() throws Throwable { MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), MethodHandles.empty(methodType(String.class)), Counted.MH_stateBody); assertEquals(Counted.MT_bodyDeterminesState, loop.type()); @@ -560,7 +565,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedLoopArgsDefinedByIterations() throws Throwable { + public void testCountedLoopArgsDefinedByIterations() throws Throwable { MethodHandle iterations = MethodHandles.dropArguments(MethodHandles.constant(int.class, 3), 0, String.class); MethodHandle loop = MethodHandles.countedLoop(iterations, @@ -570,7 +575,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedRangeLoop() throws Throwable { + public void testCountedRangeLoop() throws Throwable { // String s = "Lambdaman!"; for (int i = -5; i < 8; ++i) { s = "na " + s; } return s; => a well known theme MethodHandle fitm5 = MethodHandles.dropArguments(Counted.MH_m5, 0, String.class); MethodHandle fit8 = MethodHandles.dropArguments(Counted.MH_8, 0, String.class); @@ -580,7 +585,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedLoopCounterInit() throws Throwable { + public void testCountedLoopCounterInit() throws Throwable { // int x = 0; for (int i = 0; i < 5; ++i) { x += i; } return x; => 10 // (only if counter's first value in body is 0) MethodHandle iter = MethodHandles.constant(int.class, 5); @@ -592,7 +597,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedLoopEmpty() throws Throwable { + public void testCountedLoopEmpty() throws Throwable { // for (int i = 0; i < 5; ++i) { /* empty */ } MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, 5), null, MethodHandles.empty(methodType(void.class, int.class))); @@ -601,7 +606,7 @@ public class LoopCombinatorTest { } @Test - public static void testCountedRangeLoopEmpty() throws Throwable { + public void testCountedRangeLoopEmpty() throws Throwable { // for (int i = -5; i < 5; ++i) { /* empty */ } MethodHandle loop = MethodHandles.countedLoop(MethodHandles.constant(int.class, -5), MethodHandles.constant(int.class, 5), null, MethodHandles.empty(methodType(void.class, int.class))); @@ -609,7 +614,6 @@ public class LoopCombinatorTest { loop.invoke(); } - @DataProvider static Object[][] countedLoopNegativeData() { MethodHandle dummy = MethodHandles.zero(void.class); MethodHandle one = MethodHandles.constant(int.class, 1); @@ -629,35 +633,30 @@ public class LoopCombinatorTest { }; } - @Test(dataProvider = "countedLoopNegativeData") - public static void testCountedLoopNegative(MethodHandle start, MethodHandle end, MethodHandle init, + @ParameterizedTest + @MethodSource("countedLoopNegativeData") + @Disabled //%%%FIXME%%%% + public void testCountedLoopNegative(MethodHandle start, MethodHandle end, MethodHandle init, MethodHandle body, String msg) { - if (true) return; //%%%FIXME%%%% - boolean caught = false; - try { - MethodHandles.countedLoop(start, end, init, body); - } catch (IllegalArgumentException iae) { - assertEquals(msg, iae.getMessage()); - caught = true; - } - assertTrue(caught); + var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.countedLoop(start, end, init, body)); + assertEquals(msg, iae.getMessage()); } @Test - public static void testIterateSum() throws Throwable { + public void testIterateSum() throws Throwable { // Integer[] a = new Integer[]{1,2,3,4,5,6}; int sum = 0; for (int e : a) { sum += e; } return sum; => 21 MethodHandle loop = MethodHandles.iteratedLoop(Iterate.MH_sumIterator, Iterate.MH_sumInit, Iterate.MH_sumStep); assertEquals(Iterate.MT_sum, loop.type()); assertEquals(21, loop.invoke(new Integer[]{1, 2, 3, 4, 5, 6})); } - @DataProvider static Object[][] iteratorInits() { return new Object[][]{{Iterate.MH_iteratorFromList}, {Iterate.MH_iteratorFromIterable}, {null}}; } - @Test(dataProvider = "iteratorInits") - public static void testIterateReverse(MethodHandle iterator) throws Throwable { + @ParameterizedTest + @MethodSource("iteratorInits") + public void testIterateReverse(MethodHandle iterator) throws Throwable { // this test uses List as its loop state type; don't try to change that if (iterator != null) iterator = iterator.asType(iterator.type().changeParameterType(0, List.class)); @@ -685,8 +684,9 @@ public class LoopCombinatorTest { } } - @Test(dataProvider = "iteratorInits") - public static void testIterateLength(MethodHandle iterator) throws Throwable { + @ParameterizedTest + @MethodSource("iteratorInits") + public void testIterateLength(MethodHandle iterator) throws Throwable { MethodHandle body = Iterate.MH_lengthStep; MethodHandle init = Iterate.MH_lengthInit; MethodType expectedType = Iterate.MT_length; @@ -708,8 +708,9 @@ public class LoopCombinatorTest { } } - @Test(dataProvider = "iteratorInits") - public static void testIterateMap(MethodHandle iterator) throws Throwable { + @ParameterizedTest + @MethodSource("iteratorInits") + public void testIterateMap(MethodHandle iterator) throws Throwable { MethodHandle body = Iterate.MH_mapStep; MethodHandle init = Iterate.MH_mapInit; MethodType expectedType = Iterate.MT_map; @@ -731,8 +732,9 @@ public class LoopCombinatorTest { } } - @Test(dataProvider = "iteratorInits") - public static void testIteratePrint(MethodHandle iterator) throws Throwable { + @ParameterizedTest + @MethodSource("iteratorInits") + public void testIteratePrint(MethodHandle iterator) throws Throwable { MethodHandle body = Iterate.MH_printStep; MethodType expectedType = Iterate.MT_print; int barity = body.type().parameterCount(); @@ -747,32 +749,28 @@ public class LoopCombinatorTest { loop.invoke(Arrays.asList("hello", "world")); } - @Test(expectedExceptions = NullPointerException.class) - public static void testIterateNullBody() { - MethodHandles.iteratedLoop(MethodHandles.empty(methodType(Iterator.class, int.class)), - MethodHandles.identity(int.class), null); + @Test + public void testIterateNullBody() { + assertThrows(NullPointerException.class, () -> + MethodHandles.iteratedLoop(MethodHandles.empty(methodType(Iterator.class, int.class)), + MethodHandles.identity(int.class), null)); } - @DataProvider static Object[][] wrongIteratorTypes() { return new Object[][]{{void.class}, {Object.class}, {Iterable.class}}; } - @Test(dataProvider = "wrongIteratorTypes") - public static void testIterateVoidIterator(Class it) { - boolean caught = false; + @ParameterizedTest + @MethodSource("wrongIteratorTypes") + public void testIterateVoidIterator(Class it) { MethodType v = methodType(it); - try { - MethodHandles.iteratedLoop(MethodHandles.empty(v), null, MethodHandles.empty(v)); - } catch(IllegalArgumentException iae) { - assertEqualsFIXME("iteratedLoop first argument must have Iterator return type", iae.getMessage()); - caught = true; - } - assertTrue(caught); + var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.iteratedLoop(MethodHandles.empty(v), null, MethodHandles.empty(v))); + assertEqualsFIXME("iteratedLoop first argument must have Iterator return type", iae.getMessage()); } - @Test(dataProvider = "iteratorInits") - public static void testIterateVoidInit(MethodHandle iterator) throws Throwable { + @ParameterizedTest + @MethodSource("iteratorInits") + public void testIterateVoidInit(MethodHandle iterator) throws Throwable { // this test uses List as its loop state type; don't try to change that if (iterator != null) iterator = iterator.asType(iterator.type().changeParameterType(0, List.class)); @@ -781,7 +779,6 @@ public class LoopCombinatorTest { loop.invoke(Arrays.asList("hello", "world")); } - @DataProvider static Object[][] iterateParameters() { MethodType i = methodType(int.class); MethodType sil_v = methodType(void.class, String.class, int.class, List.class); @@ -811,8 +808,9 @@ public class LoopCombinatorTest { }; } - @Test(dataProvider = "iterateParameters") - public static void testIterateParameters(MethodType it, MethodType in, MethodType bo, String msg) { + @ParameterizedTest + @MethodSource("iterateParameters") + public void testIterateParameters(MethodType it, MethodType in, MethodType bo, String msg) { boolean negative = !msg.isEmpty(); MethodHandle iterator = it == null ? null : MethodHandles.empty(it); MethodHandle init = in == null ? null : MethodHandles.empty(in); @@ -855,7 +853,7 @@ public class LoopCombinatorTest { } @Test - public static void testIteratorSubclass() throws Throwable { + public void testIteratorSubclass() throws Throwable { MethodHandle loop = MethodHandles.iteratedLoop(MethodHandles.empty(methodType(BogusIterator.class, List.class)), null, MethodHandles.empty(methodType(void.class, String.class, List.class))); assertEquals(methodType(void.class, List.class), loop.type()); diff --git a/test/jdk/java/lang/invoke/MethodHandleInvokeUOE.java b/test/jdk/java/lang/invoke/MethodHandleInvokeUOE.java index e728516fe03..510a65acabf 100644 --- a/test/jdk/java/lang/invoke/MethodHandleInvokeUOE.java +++ b/test/jdk/java/lang/invoke/MethodHandleInvokeUOE.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, 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 @@ -24,20 +24,18 @@ /* @test * @summary Test MethodHandle::invokeExact and MethodHandle::invoke throws * UnsupportedOperationException when called via Method::invoke - * @run testng test.java.lang.invoke.MethodHandleInvokeUOE + * @run junit test.java.lang.invoke.MethodHandleInvokeUOE */ package test.java.lang.invoke; -import org.testng.*; -import org.testng.annotations.*; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.Test; public class MethodHandleInvokeUOE { @Test diff --git a/test/jdk/java/lang/invoke/MethodHandleProxies/Driver.java b/test/jdk/java/lang/invoke/MethodHandleProxies/Driver.java index 0e9c708e8e9..2d99db46c2c 100644 --- a/test/jdk/java/lang/invoke/MethodHandleProxies/Driver.java +++ b/test/jdk/java/lang/invoke/MethodHandleProxies/Driver.java @@ -25,8 +25,8 @@ * @test * @bug 8280377 * @build m1/* m2/* Unnamed - * @run testng/othervm m1/p1.Main - * @run main/othervm Unnamed + * @run junit/othervm m1/p1.Main + * @run junit/othervm Unnamed * @summary Test MethodHandleProxies::asInterfaceInstance with a default * method with varargs */ diff --git a/test/jdk/java/lang/invoke/MethodHandleProxies/Unnamed.java b/test/jdk/java/lang/invoke/MethodHandleProxies/Unnamed.java index f60f36ca9de..8cd9a37cc2f 100644 --- a/test/jdk/java/lang/invoke/MethodHandleProxies/Unnamed.java +++ b/test/jdk/java/lang/invoke/MethodHandleProxies/Unnamed.java @@ -26,13 +26,16 @@ import java.lang.invoke.MethodHandleProxies; import java.lang.invoke.MethodHandles; import java.lang.reflect.Method; -import static org.testng.Assert.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /* * Test MethodHandleProxies::asInterfaceInstance with an inaccessible interface */ public class Unnamed { - public static void main(String... args) throws Throwable { + @Test + void testInaccessible() throws Throwable { MethodHandle target = MethodHandles.constant(String.class, "test"); Class intf = Class.forName("p2.TestIntf"); Object t = MethodHandleProxies.asInterfaceInstance(intf, target); diff --git a/test/jdk/java/lang/invoke/MethodHandleProxies/m1/module-info.java b/test/jdk/java/lang/invoke/MethodHandleProxies/m1/module-info.java index 1bdeddce28f..5e0174635fb 100644 --- a/test/jdk/java/lang/invoke/MethodHandleProxies/m1/module-info.java +++ b/test/jdk/java/lang/invoke/MethodHandleProxies/m1/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2025, 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 @@ -22,6 +22,6 @@ */ module m1 { requires m2; - requires org.testng; + requires org.junit.platform.console.standalone; exports p1; } diff --git a/test/jdk/java/lang/invoke/MethodHandleProxies/m1/p1/Main.java b/test/jdk/java/lang/invoke/MethodHandleProxies/m1/p1/Main.java index df71809996b..1e4ffcb4aac 100644 --- a/test/jdk/java/lang/invoke/MethodHandleProxies/m1/p1/Main.java +++ b/test/jdk/java/lang/invoke/MethodHandleProxies/m1/p1/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2025, 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 @@ -32,9 +32,8 @@ import java.util.stream.Collectors; import p2.TestIntf; -import org.testng.annotations.Test; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class Main { public interface A { @@ -57,24 +56,24 @@ public class Main { * Test the invocation of default methods with varargs */ @Test - public static void testVarargsMethods() throws Throwable { + public void testVarargsMethods() throws Throwable { MethodHandle target = MethodHandles.lookup().findStatic(Main.class, "concat", MethodType.methodType(String.class, Object[].class)); C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target); - assertEquals(proxy.c("a", "b", "c"), "abc"); - assertEquals(proxy.aConcat("a", "b", "c"), "[a, b, c]"); - assertEquals(proxy.aConcat(new Object[] { "a", "b", "c" }), "[a, b, c]"); - assertEquals(proxy.bConcat(new Object[] { "a", "b", "c" }), "[a, b, c]"); + assertEquals("abc", proxy.c("a", "b", "c")); + assertEquals("[a, b, c]", proxy.aConcat("a", "b", "c")); + assertEquals("[a, b, c]", proxy.aConcat(new Object[] { "a", "b", "c" })); + assertEquals("[a, b, c]", proxy.bConcat(new Object[] { "a", "b", "c" })); } /* * Test the invocation of a default method of an accessible interface */ @Test - public static void modulePrivateInterface() { + public void modulePrivateInterface() { MethodHandle target = MethodHandles.constant(String.class, "test"); TestIntf t = MethodHandleProxies.asInterfaceInstance(TestIntf.class, target); - assertEquals(t.test(), "test"); + assertEquals("test", t.test()); } } diff --git a/test/jdk/java/lang/invoke/MethodHandles/TestDropReturn.java b/test/jdk/java/lang/invoke/MethodHandles/TestDropReturn.java index ff31dd63f0b..1b8ef6331b3 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/TestDropReturn.java +++ b/test/jdk/java/lang/invoke/MethodHandles/TestDropReturn.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -24,33 +24,33 @@ /* * @test * @bug 8255398 - * @run testng TestDropReturn + * @run junit TestDropReturn */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import static java.lang.invoke.MethodType.methodType; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class TestDropReturn { - @Test(dataProvider = "dropReturnCases") + @ParameterizedTest + @MethodSource("dropReturnCases") public void testDropReturn(Class cls, Object testValue) throws Throwable { MethodHandle mh = MethodHandles.identity(cls); - assertEquals(mh.type(), methodType(cls, cls)); + assertEquals(methodType(cls, cls), mh.type()); Object x = mh.invoke(testValue); - assertEquals(x, testValue); + assertEquals(testValue, x); mh = MethodHandles.dropReturn(mh); - assertEquals(mh.type(), methodType(void.class, cls)); + assertEquals(methodType(void.class, cls), mh.type()); mh.invoke(testValue); // should at least work } - @DataProvider public static Object[][] dropReturnCases() { return new Object[][]{ { boolean.class, true }, diff --git a/test/jdk/java/lang/invoke/MethodHandles/TestTableSwitch.java b/test/jdk/java/lang/invoke/MethodHandles/TestTableSwitch.java index 4ff1a99cc28..960d98fb387 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/TestTableSwitch.java +++ b/test/jdk/java/lang/invoke/MethodHandles/TestTableSwitch.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, 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 @@ -23,13 +23,9 @@ /* * @test - * @run testng/othervm -Xverify:all TestTableSwitch + * @run junit/othervm -Xverify:all TestTableSwitch */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import javax.management.ObjectName; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -38,7 +34,11 @@ import java.util.List; import java.util.function.IntConsumer; import java.util.function.IntFunction; -import static org.testng.Assert.assertEquals; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.*; public class TestTableSwitch { @@ -111,7 +111,6 @@ public class TestTableSwitch { return args; } - @DataProvider public static Object[][] nonVoidCases() { List tests = new ArrayList<>(); @@ -126,10 +125,11 @@ public class TestTableSwitch { } private static void check(List testValues, Object[] collectedValues) { - assertEquals(collectedValues, testValues.toArray()); + assertArrayEquals(testValues.toArray(), collectedValues); } - @Test(dataProvider = "nonVoidCases") + @ParameterizedTest + @MethodSource("nonVoidCases") public void testNonVoidHandles(Class type, int numCases, List> additionalTypes) throws Throwable { MethodHandle collector = MH_check; List testArguments = new ArrayList<>(); @@ -158,19 +158,19 @@ public class TestTableSwitch { testArguments.add(testValue(additionalType)); } - assertEquals(mhSwitch.invokeWithArguments(testArguments(-1, testArguments)), defaultReturnValue); + assertEquals(defaultReturnValue, mhSwitch.invokeWithArguments(testArguments(-1, testArguments))); for (int i = 0; i < numCases; i++) { - assertEquals(mhSwitch.invokeWithArguments(testArguments(i, testArguments)), returnValues[i]); + assertEquals(returnValues[i], mhSwitch.invokeWithArguments(testArguments(i, testArguments))); } - assertEquals(mhSwitch.invokeWithArguments(testArguments(numCases, testArguments)), defaultReturnValue); + assertEquals(defaultReturnValue, mhSwitch.invokeWithArguments(testArguments(numCases, testArguments))); } @Test public void testVoidHandles() throws Throwable { IntFunction makeTestCase = expectedIndex -> { - IntConsumer test = actualIndex -> assertEquals(actualIndex, expectedIndex); + IntConsumer test = actualIndex -> assertEquals(expectedIndex, actualIndex); return MH_IntConsumer_accept.bindTo(test); }; @@ -187,48 +187,48 @@ public class TestTableSwitch { mhSwitch.invokeExact((int) 2); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testNullDefaultHandle() { - MethodHandles.tableSwitch(null, simpleTestCase("test")); + assertThrows(NullPointerException.class, () -> MethodHandles.tableSwitch(null, simpleTestCase("test"))); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testNullCases() { MethodHandle[] cases = null; - MethodHandles.tableSwitch(simpleTestCase("default"), cases); + assertThrows(NullPointerException.class, () -> + MethodHandles.tableSwitch(simpleTestCase("default"), cases)); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testNullCase() { - MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), null); + assertThrows(NullPointerException.class, () -> MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), null)); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Not enough cases.*") + @Test public void testNotEnoughCases() { - MethodHandles.tableSwitch(simpleTestCase("default")); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.tableSwitch(simpleTestCase("default"))); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Case actions must have int as leading parameter.*") + @Test public void testNotEnoughParameters() { MethodHandle empty = MethodHandles.empty(MethodType.methodType(void.class)); - MethodHandles.tableSwitch(empty, empty, empty); + assertThrows(IllegalArgumentException.class, () -> + MethodHandles.tableSwitch(empty, empty, empty)); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Case actions must have int as leading parameter.*") + @Test public void testNoLeadingIntParameter() { MethodHandle empty = MethodHandles.empty(MethodType.methodType(void.class, double.class)); - MethodHandles.tableSwitch(empty, empty, empty); + assertThrows(IllegalArgumentException.class, () -> + MethodHandles.tableSwitch(empty, empty, empty)); } - @Test(expectedExceptions = IllegalArgumentException.class, - expectedExceptionsMessageRegExp = ".*Case actions must have the same type.*") + @Test public void testWrongCaseType() { // doesn't return a String MethodHandle wrongType = MethodHandles.empty(MethodType.methodType(void.class, int.class)); - MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), wrongType); + assertThrows(IllegalArgumentException.class, () -> + MethodHandles.tableSwitch(simpleTestCase("default"), simpleTestCase("case"), wrongType)); } } diff --git a/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java b/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java index 5880761f925..f96a6f23162 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java +++ b/test/jdk/java/lang/invoke/MethodHandles/classData/ClassDataTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -25,7 +25,7 @@ * @test * @bug 8230501 * @library /test/lib - * @run testng/othervm ClassDataTest + * @run junit/othervm ClassDataTest */ import java.io.IOException; @@ -54,13 +54,14 @@ import java.util.Map; import java.util.function.Consumer; import java.util.stream.Stream; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.classfile.ClassFile.*; import static java.lang.constant.ConstantDescs.*; import static java.lang.invoke.MethodHandles.Lookup.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class ClassDataTest { private static final Lookup LOOKUP = MethodHandles.lookup(); @@ -72,10 +73,10 @@ public class ClassDataTest { assertTrue(lookup.hasFullPrivilegeAccess()); int value = MethodHandles.classData(lookup, "_", int.class); - assertEquals(value, 20); + assertEquals(20, value); Integer i = MethodHandles.classData(lookup, "_", Integer.class); - assertEquals(i.intValue(), 20); + assertEquals(20, i.intValue()); } /* @@ -86,8 +87,7 @@ public class ClassDataTest { assertNull(MethodHandles.classData(LOOKUP, "_", Object.class)); } - @DataProvider(name = "teleportedLookup") - private Object[][] teleportedLookup() throws ReflectiveOperationException { + private static Object[][] teleportedLookup() throws ReflectiveOperationException { Lookup lookup = hiddenClass(30); Class hc = lookup.lookupClass(); assertClassData(lookup, 30); @@ -100,32 +100,33 @@ public class ClassDataTest { }; } - @Test(dataProvider = "teleportedLookup", expectedExceptions = { IllegalAccessException.class }) + @ParameterizedTest + @MethodSource("teleportedLookup") public void illegalAccess(Lookup lookup, int access) throws IllegalAccessException { int lookupModes = lookup.lookupModes(); - assertTrue((lookupModes & ORIGINAL) == 0); - assertEquals(lookupModes, access); - MethodHandles.classData(lookup, "_", int.class); + assertEquals(0, lookupModes & ORIGINAL); + assertEquals(access, lookupModes); + assertThrows(IllegalAccessException.class, () -> MethodHandles.classData(lookup, "_", int.class)); } - @Test(expectedExceptions = { ClassCastException.class }) + @Test public void incorrectType() throws IllegalAccessException { Lookup lookup = hiddenClass(20); - MethodHandles.classData(lookup, "_", Long.class); + assertThrows(ClassCastException.class, () -> MethodHandles.classData(lookup, "_", Long.class)); } - @Test(expectedExceptions = { IndexOutOfBoundsException.class }) + @Test public void invalidIndex() throws IllegalAccessException { Lookup lookup = hiddenClass(List.of()); - MethodHandles.classDataAt(lookup, "_", Object.class, 0); + assertThrows(IndexOutOfBoundsException.class, () -> MethodHandles.classDataAt(lookup, "_", Object.class, 0)); } - @Test(expectedExceptions = { NullPointerException.class }) + @Test public void unboxNull() throws IllegalAccessException { List list = new ArrayList<>(); list.add(null); Lookup lookup = hiddenClass(list); - MethodHandles.classDataAt(lookup, "_", int.class, 0); + assertThrows(NullPointerException.class, () -> MethodHandles.classDataAt(lookup, "_", int.class, 0)); } @Test @@ -133,7 +134,7 @@ public class ClassDataTest { List list = new ArrayList<>(); list.add(null); Lookup lookup = hiddenClass(list); - assertTrue(MethodHandles.classDataAt(lookup, "_", Object.class, 0) == null); + assertNull(MethodHandles.classDataAt(lookup, "_", Object.class, 0)); } @Test @@ -142,7 +143,7 @@ public class ClassDataTest { byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, int.class).build(); Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, 100, true); int value = MethodHandles.classData(lookup, "_", int.class); - assertEquals(value, 100); + assertEquals(100, value); // call through condy assertClassData(lookup, 100); } @@ -153,7 +154,7 @@ public class ClassDataTest { byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, float.class).build(); Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, 0.1234f, true); float value = MethodHandles.classData(lookup, "_", float.class); - assertEquals(value, 0.1234f); + assertEquals(0.1234f, value); // call through condy assertClassData(lookup, 0.1234f); } @@ -165,7 +166,7 @@ public class ClassDataTest { byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, Class.class).build(); Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, hc, true); Class value = MethodHandles.classData(lookup, "_", Class.class); - assertEquals(value, hc); + assertEquals(hc, value); // call through condy assertClassData(lookup, hc); } @@ -181,7 +182,7 @@ public class ClassDataTest { colors[0] = "black"; // it will get back the modified class data String[] value = MethodHandles.classData(lookup, "_", String[].class); - assertEquals(value, colors); + assertArrayEquals(colors, value); // even call through condy as it's not a constant assertClassData(lookup, colors); } @@ -194,7 +195,7 @@ public class ClassDataTest { int expected = 102; // element at index=2 Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, cd, true); int value = MethodHandles.classDataAt(lookup, "_", int.class, 2); - assertEquals(value, expected); + assertEquals(expected, value); // call through condy assertClassData(lookup, expected); } @@ -208,7 +209,7 @@ public class ClassDataTest { int expected = 101; // element at index=1 Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, cd, true); int value = MethodHandles.classDataAt(lookup, "_", int.class, 1); - assertEquals(value, expected); + assertEquals(expected, value); // call through condy assertClassData(lookup, expected); } @@ -216,20 +217,12 @@ public class ClassDataTest { private static Lookup hiddenClass(int value) { ClassByteBuilder builder = new ClassByteBuilder("HC"); byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, int.class).build(); - try { - return LOOKUP.defineHiddenClassWithClassData(bytes, value, true); - } catch (Throwable e) { - throw new RuntimeException(e); - } + return assertDoesNotThrow(() -> LOOKUP.defineHiddenClassWithClassData(bytes, value, true)); } private static Lookup hiddenClass(List list) { ClassByteBuilder builder = new ClassByteBuilder("HC"); byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, List.class).build(); - try { - return LOOKUP.defineHiddenClassWithClassData(bytes, list, true); - } catch (Throwable e) { - throw new RuntimeException(e); - } + return assertDoesNotThrow(() -> LOOKUP.defineHiddenClassWithClassData(bytes, list, true)); } @Test @@ -242,7 +235,7 @@ public class ClassDataTest { Class hc = hcLookup.lookupClass(); Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, hc, true); Class value = MethodHandles.classData(lookup, "_", Class.class); - assertEquals(value, hc); + assertEquals(hc, value); // call through condy Class c = lookup.lookupClass(); assertClassData(lookup, c.newInstance(), hc); @@ -257,7 +250,7 @@ public class ClassDataTest { int expected = 102; // element at index=2 Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, cd, true); int value = MethodHandles.classDataAt(lookup, "_", int.class, 2); - assertEquals(value, expected); + assertEquals(expected, value); // call through condy Class c = lookup.lookupClass(); assertClassData(lookup, c.newInstance() ,expected); @@ -285,13 +278,13 @@ public class ClassDataTest { Class c = lookup.lookupClass(); assertClassData(lookup, c.newInstance(), mtype); // modify the class data - assertTrue(cd.remove(0) == mtype); + assertSame(mtype, cd.remove(0)); cd.add(0, MethodType.methodType(void.class)); MethodType newMType = cd.get(0); // loading the element using condy returns the original value assertClassData(lookup, c.newInstance(), mtype); // direct invocation of MethodHandles.classDataAt returns the modified value - assertEquals(MethodHandles.classDataAt(lookup, "_", MethodType.class, 0), newMType); + assertEquals(newMType, MethodHandles.classDataAt(lookup, "_", MethodType.class, 0)); } // helper method to extract from a class data map @@ -334,7 +327,7 @@ public class ClassDataTest { assertEquals(mh, v1); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void nonDefaultName() throws ReflectiveOperationException { ClassByteBuilder builder = new ClassByteBuilder("nonDefaultName"); byte[] bytes = builder.classData(ACC_PUBLIC|ACC_STATIC, Class.class) @@ -342,7 +335,7 @@ public class ClassDataTest { Lookup lookup = LOOKUP.defineHiddenClassWithClassData(bytes, ClassDataTest.class, true); assertClassData(lookup, ClassDataTest.class); // throw IAE - MethodHandles.classData(lookup, "non_default_name", Class.class); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.classData(lookup, "non_default_name", Class.class)); } static class ClassByteBuilder { @@ -428,7 +421,7 @@ public class ClassDataTest { * Load an int constant from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, int value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, int value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); int v = (int) m.invoke(null); @@ -439,7 +432,7 @@ public class ClassDataTest { * Load an int constant from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, Object o, int value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, Object o, int value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); int v = (int) m.invoke(o); @@ -450,7 +443,7 @@ public class ClassDataTest { * Load a float constant from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, float value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, float value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); float v = (float) m.invoke(null); @@ -461,7 +454,7 @@ public class ClassDataTest { * Load a Class constant from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, Class value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, Class value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); Class v = (Class)m.invoke(null); @@ -472,7 +465,7 @@ public class ClassDataTest { * Load a Class from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, Object o, Class value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, Object o, Class value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); Object v = m.invoke(o); @@ -483,18 +476,29 @@ public class ClassDataTest { * Load an Object from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, Object value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, Object value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); Object v = m.invoke(null); assertEquals(value, v); } + /* + * Load an Object array from class data via condy and + * verify it matches the given value in content. + */ + private static void assertClassData(Lookup lookup, Object[] value) throws ReflectiveOperationException { + Class c = lookup.lookupClass(); + Method m = c.getMethod("classData"); + Object v = m.invoke(null); + assertArrayEquals(value, (Object[]) v); + } + /* * Load an Object from class data via condy and * verify it matches the given value. */ - private void assertClassData(Lookup lookup, Object o, Object value) throws ReflectiveOperationException { + private static void assertClassData(Lookup lookup, Object o, Object value) throws ReflectiveOperationException { Class c = lookup.lookupClass(); Method m = c.getMethod("classData"); Object v = m.invoke(o); diff --git a/test/jdk/java/lang/invoke/MethodHandles/ensureInitialized/Main.java b/test/jdk/java/lang/invoke/MethodHandles/ensureInitialized/Main.java index 58146286da1..afb628d31ba 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/ensureInitialized/Main.java +++ b/test/jdk/java/lang/invoke/MethodHandles/ensureInitialized/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -24,16 +24,15 @@ import java.lang.invoke.MethodHandles; import java.lang.reflect.Method; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** * @test * @bug 8235521 * @summary Tests for Lookup::ensureClassInitialized * @build java.base/* m1/* m2/* Main - * @run testng/othervm --add-modules m1 Main + * @run junit/othervm --add-modules m1 Main */ public class Main { @@ -48,20 +47,20 @@ public class Main { } // access denied to package-private java.lang class - @Test(expectedExceptions = { IllegalAccessException.class }) + @Test public void testPackagePrivate() throws Exception { Class c = Class.forName("java.lang.DefaultInit", false, null); assertFalse(Helper.isInitialized(c)); // access denied - MethodHandles.lookup().ensureInitialized(c); + assertThrows(IllegalAccessException.class, () -> MethodHandles.lookup().ensureInitialized(c)); } // access denied to public class in a non-exported package - @Test(expectedExceptions = { IllegalAccessException.class }) + @Test public void testNonExportedPackage() throws Exception { Class c = Class.forName("jdk.internal.misc.VM", false, null); // access denied - MethodHandles.lookup().ensureInitialized(c); + assertThrows(IllegalAccessException.class, () -> MethodHandles.lookup().ensureInitialized(c)); } // invoke p1.Test::test to test module boundary access @@ -72,9 +71,9 @@ public class Main { m.invoke(null); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void testArrayType() throws Exception { Class arrayType = PublicInit.class.arrayType(); - MethodHandles.lookup().ensureInitialized(arrayType); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.lookup().ensureInitialized(arrayType)); } } diff --git a/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/Driver.java b/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/Driver.java index 810351bae3e..bf3f1f40913 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/Driver.java +++ b/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/Driver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -24,6 +24,6 @@ /** * @test * @build test/* m1/* m2/* m3/* Unnamed - * @run testng/othervm test/p.PrivateLookupInTests + * @run junit/othervm test/p.PrivateLookupInTests * @summary Unit tests for MethodHandles.privateLookupIn */ diff --git a/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/module-info.java b/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/module-info.java index da93c879ef1..f364c761aa3 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/module-info.java +++ b/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -22,6 +22,6 @@ */ module test { - requires org.testng; - exports p to org.testng; // TestNG invokes the public methods + requires org.junit.platform.console.standalone; + exports p to org.junit.platform.console.standalone; // JUnit invokes the public methods in PrivateLookupInTests } diff --git a/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java b/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java index b17204de013..068d2fb534e 100644 --- a/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java +++ b/test/jdk/java/lang/invoke/MethodHandles/privateLookupIn/test/p/PrivateLookupInTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -29,15 +29,14 @@ import java.lang.reflect.Modifier; import static java.lang.invoke.MethodHandles.Lookup.*; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** * Unit tests for MethodHandles.privateLookupIn */ -@Test public class PrivateLookupInTests { /** * A public and non-public types in the test module but in a different @@ -52,24 +51,25 @@ public class PrivateLookupInTests { * private static final Object obj = ... * } */ - private Class publicType; - private Class nonPublicType; + private static Class publicType; + private static Class nonPublicType; // initialize and sanity check publicType/nonPublicType - @BeforeTest - public void init() throws Exception { + @BeforeAll + public static void init() throws Exception { publicType = Class.forName("p.internal.PublicType"); - assertTrue(this.getClass().getModule() == publicType.getModule()); - assertNotEquals(this.getClass().getPackageName(), publicType.getPackageName()); + assertSame(PrivateLookupInTests.class.getModule(), publicType.getModule()); + assertNotEquals(publicType.getPackageName(), PrivateLookupInTests.class.getPackageName()); assertTrue(Modifier.isPublic(publicType.getModifiers())); nonPublicType = Class.forName("p.internal.NonPublicType"); - assertTrue(this.getClass().getModule() == nonPublicType.getModule()); - assertNotEquals(this.getClass().getPackageName(), nonPublicType.getPackageName()); + assertSame(PrivateLookupInTests.class.getModule(), nonPublicType.getModule()); + assertNotEquals(nonPublicType.getPackageName(), PrivateLookupInTests.class.getPackageName()); assertFalse(Modifier.isPublic(nonPublicType.getModifiers())); } // Invoke MethodHandles.privateLookupIn with a full-power caller + @Test public void testAllAccessCallerSameModule() throws Throwable { Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, MethodHandles.lookup()); assertTrue(lookup.lookupClass() == nonPublicType); @@ -82,29 +82,31 @@ public class PrivateLookupInTests { } // Invoke MethodHandles.privateLookupIn with a reduced-power caller - @Test(expectedExceptions = {IllegalAccessException.class}) + @Test public void testReducedAccessCallerSameModule() throws Throwable { Lookup caller = MethodHandles.lookup().dropLookupMode(PACKAGE); - assertTrue((caller.lookupModes() & PRIVATE) == 0); - assertTrue((caller.lookupModes() & PACKAGE) == 0); - assertTrue((caller.lookupModes() & MODULE) != 0); - assertTrue((caller.lookupModes() & ORIGINAL) == 0); - - Lookup lookup = MethodHandles.privateLookupIn(nonPublicType, caller); + assertEquals(0, caller.lookupModes() & PRIVATE); + assertEquals(0, caller.lookupModes() & PACKAGE); + assertNotEquals(0, caller.lookupModes() & MODULE); + assertEquals(0, caller.lookupModes() & ORIGINAL); + assertThrows(IllegalAccessException.class, () -> + MethodHandles.privateLookupIn(nonPublicType, caller)); } // Invoke MethodHandles.privateLookupIn with the public lookup as caller - @Test(expectedExceptions = {IllegalAccessException.class}) + @Test public void testPublicLookupSameModule() throws Exception { Lookup caller = MethodHandles.publicLookup(); - Lookup lookup = MethodHandles.privateLookupIn(publicType, caller); + assertThrows(IllegalAccessException.class, () -> + MethodHandles.privateLookupIn(publicType, caller)); } // test reads m1, open module m1 containing p1 + @Test public void testTargetClassInOpenModule() throws Throwable { // m1/p1.Type Class clazz = Class.forName("p1.Type"); - assertEquals(clazz.getModule().getName(), "m1"); + assertEquals("m1", clazz.getModule().getName()); // ensure that this module reads m1 Module thisModule = getClass().getModule(); @@ -113,9 +115,9 @@ public class PrivateLookupInTests { assertTrue(m1.isOpen("p1", thisModule)); Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); - assertTrue(lookup.lookupClass() == clazz); - assertTrue((lookup.lookupModes() & PRIVATE) == PRIVATE); - assertTrue((lookup.lookupModes() & MODULE) == 0); + assertSame(clazz, lookup.lookupClass()); + assertEquals(PRIVATE, lookup.lookupModes() & PRIVATE); + assertEquals(0, lookup.lookupModes() & MODULE); // get obj field MethodHandle mh = lookup.findStaticGetter(clazz, "obj", Object.class); @@ -123,6 +125,7 @@ public class PrivateLookupInTests { } // test target class in unnamed module + @Test public void testTargetClassInUnnamedModule() throws Throwable { Class clazz = Class.forName("Unnamed"); assertFalse(clazz.getModule().isNamed()); @@ -130,76 +133,72 @@ public class PrivateLookupInTests { // thisModule does not read the unnamed module Module thisModule = getClass().getModule(); assertFalse(thisModule.canRead(clazz.getModule())); - try { - MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); - assertTrue(false); - } catch (IllegalAccessException expected) { } + var baseLookup = MethodHandles.lookup(); + assertThrows(IllegalAccessException.class, () -> MethodHandles.privateLookupIn(clazz, baseLookup)); // thisModule reads the unnamed module thisModule.addReads(clazz.getModule()); - Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); - assertTrue(lookup.lookupClass() == clazz); - assertTrue((lookup.lookupModes() & PRIVATE) == PRIVATE); - assertTrue((lookup.lookupModes() & MODULE) == 0); + Lookup lookup = MethodHandles.privateLookupIn(clazz, baseLookup); + assertSame(clazz, lookup.lookupClass()); + assertEquals(PRIVATE, (lookup.lookupModes() & PRIVATE)); + assertEquals(0, (lookup.lookupModes() & MODULE)); } // test does not read m2, m2 opens p2 to test - @Test(expectedExceptions = {IllegalAccessException.class}) + @Test public void testCallerDoesNotRead() throws Throwable { // m2/p2.Type Class clazz = Class.forName("p2.Type"); - assertEquals(clazz.getModule().getName(), "m2"); - + assertEquals("m2", clazz.getModule().getName()); Module thisModule = getClass().getModule(); Module m2 = clazz.getModule(); assertFalse(thisModule.canRead(m2)); assertTrue(m2.isOpen("p2", thisModule)); - - Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); + assertThrows(IllegalAccessException.class, () -> + MethodHandles.privateLookupIn(clazz, MethodHandles.lookup())); } // test reads m3, m3 does not open p3 to test - @Test(expectedExceptions = {IllegalAccessException.class}) + @Test public void testNotOpenToCaller() throws Throwable { // m3/p2.Type Class clazz = Class.forName("p3.Type"); - assertEquals(clazz.getModule().getName(), "m3"); - + assertEquals("m3", clazz.getModule().getName()); Module thisModule = getClass().getModule(); Module m3 = clazz.getModule(); thisModule.addReads(clazz.getModule()); assertFalse(m3.isOpen("p3", thisModule)); - - Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup()); + assertThrows(IllegalAccessException.class, () -> + MethodHandles.privateLookupIn(clazz, MethodHandles.lookup())); } // Invoke MethodHandles.privateLookupIn with a primitive class - @Test(expectedExceptions = {IllegalArgumentException.class}) + @Test public void testPrimitiveClassAsTargetClass() throws Exception { - MethodHandles.privateLookupIn(int.class, MethodHandles.lookup()); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.privateLookupIn(int.class, MethodHandles.lookup())); } // Invoke MethodHandles.privateLookupIn with an array class - @Test(expectedExceptions = {IllegalArgumentException.class}) + @Test public void testArrayClassAsTargetClass() throws Exception { - MethodHandles.privateLookupIn(PrivateLookupInTests[].class, MethodHandles.lookup()); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.privateLookupIn(PrivateLookupInTests[].class, MethodHandles.lookup())); } // Invoke MethodHandles.privateLookupIn with a primitive array class - @Test(expectedExceptions = {IllegalArgumentException.class}) + @Test public void testPrimitiveArrayClassAsTargetClass() throws Exception { - MethodHandles.privateLookupIn(int[].class, MethodHandles.lookup()); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.privateLookupIn(int[].class, MethodHandles.lookup())); } // Invoke MethodHandles.privateLookupIn with null - @Test(expectedExceptions = {NullPointerException.class}) + @Test public void testNullTargetClass() throws Exception { - MethodHandles.privateLookupIn(null, MethodHandles.lookup()); + assertThrows(NullPointerException.class, () -> MethodHandles.privateLookupIn(null, MethodHandles.lookup())); } // Invoke MethodHandles.privateLookupIn with null - @Test(expectedExceptions = {NullPointerException.class}) + @Test public void testNullCaller() throws Exception { - MethodHandles.privateLookupIn(getClass(), null); + assertThrows(NullPointerException.class, () -> MethodHandles.privateLookupIn(getClass(), null)); } } diff --git a/test/jdk/java/lang/invoke/MethodHandlesCollectArgsTest.java b/test/jdk/java/lang/invoke/MethodHandlesCollectArgsTest.java index 5fc0083d5fb..20f03454d32 100644 --- a/test/jdk/java/lang/invoke/MethodHandlesCollectArgsTest.java +++ b/test/jdk/java/lang/invoke/MethodHandlesCollectArgsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -23,18 +23,17 @@ /* @test * @bug 8259922 - * @run testng/othervm MethodHandlesCollectArgsTest + * @run junit/othervm MethodHandlesCollectArgsTest */ -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import static java.lang.invoke.MethodType.methodType; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class MethodHandlesCollectArgsTest { @@ -43,7 +42,6 @@ public class MethodHandlesCollectArgsTest { private static final MethodHandle FILTER_INT = MethodHandles.empty(methodType(int.class, String.class)); private static final MethodHandle FILTER_VOID = MethodHandles.empty(methodType(void.class, String.class)); - @DataProvider(name = "illegalPos") public static Object[][] illegalPos() { return new Object[][] { {TARGET_II_I, 2, FILTER_INT}, @@ -57,7 +55,6 @@ public class MethodHandlesCollectArgsTest { }; } - @DataProvider(name = "validPos") public static Object[][] validPos() { return new Object[][] { {TARGET_II_I, 0, FILTER_INT, methodType(int.class, String.class, int.class)}, @@ -69,14 +66,16 @@ public class MethodHandlesCollectArgsTest { }; } - @Test(dataProvider="illegalPos", expectedExceptions = {IllegalArgumentException.class}) + @ParameterizedTest + @MethodSource("illegalPos") public void illegalPosition(MethodHandle target, int position, MethodHandle filter) { - MethodHandles.collectArguments(target, position, filter); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.collectArguments(target, position, filter)); } - @Test(dataProvider="validPos") + @ParameterizedTest + @MethodSource("validPos") public void legalPosition(MethodHandle target, int position, MethodHandle filter, MethodType expectedType) { MethodHandle result = MethodHandles.collectArguments(target, position, filter); - assertEquals(result.type(), expectedType); + assertEquals(expectedType, result.type()); } } diff --git a/test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java b/test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java index b60c35fc30b..588227fef15 100644 --- a/test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java +++ b/test/jdk/java/lang/invoke/MethodHandlesGeneralTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -60,6 +60,7 @@ import java.util.Map; import static java.lang.invoke.MethodType.methodType; import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; public class MethodHandlesGeneralTest extends MethodHandlesTest { @@ -398,7 +399,7 @@ public class MethodHandlesGeneralTest extends MethodHandlesTest { Object obj = target.invokeWithArguments(args); if (!(defc == Example.class && params.length < 2)) assertCalled(defc.getSimpleName()+".", args); - assertTrue("instance of "+defc.getName(), defc.isInstance(obj)); + assertInstanceOf(defc, obj); } @Test @@ -971,8 +972,7 @@ public class MethodHandlesGeneralTest extends MethodHandlesTest { arrayToMH = new SubIntExample[length]; else return; // can't make an ArrayStoreException test - assert(arrayType.isInstance(arrayToMH)) - : Arrays.asList(arrayType, arrayToMH.getClass(), testSetter, negTest); + assertInstanceOf(arrayType, arrayToMH, () -> Arrays.asList(testSetter, negTest).toString()); break; } countTest(positive); diff --git a/test/jdk/java/lang/invoke/MethodTypeTest.java b/test/jdk/java/lang/invoke/MethodTypeTest.java index 8ac03d1a7fd..dccc82fa348 100644 --- a/test/jdk/java/lang/invoke/MethodTypeTest.java +++ b/test/jdk/java/lang/invoke/MethodTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2026, 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 @@ -25,7 +25,7 @@ * @bug 8366028 * @summary unit tests for java.lang.invoke.MethodType * @compile MethodTypeTest.java - * @run testng/othervm test.java.lang.invoke.MethodTypeTest + * @run junit/othervm test.java.lang.invoke.MethodTypeTest */ package test.java.lang.invoke; @@ -35,11 +35,13 @@ import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.util.*; -import org.testng.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import static org.testng.Assert.assertThrows; -import static org.testng.AssertJUnit.*; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; /** * @@ -57,7 +59,7 @@ public class MethodTypeTest { private MethodType[] GALLERY; private Method compareTo; - @BeforeMethod + @BeforeEach public void setUp() throws Exception { rtype = void.class; ptypes = new Class[] { int.class, String.class }; @@ -98,7 +100,7 @@ public class MethodTypeTest { }; } - @AfterMethod + @AfterEach public void tearDown() throws Exception { } @@ -107,7 +109,7 @@ public class MethodTypeTest { public void testDistinct() { List gallery2 = new ArrayList<>(); for (MethodType mt : GALLERY) { - assertFalse(mt.toString(), gallery2.contains(mt)); + assertFalse(gallery2.contains(mt), mt.toString()); gallery2.add(mt); } // check self-equality also: @@ -198,9 +200,9 @@ public class MethodTypeTest { for (int i = 0; i < instances.length; i++) { MethodType instance = instances[i]; String result = instance.toMethodDescriptorString(); - assertEquals("#"+i, expResults[i], result); + assertEquals(expResults[i], result, "#"+i); MethodType parsed = MethodType.fromMethodDescriptorString(result, loader); - assertSame("--#"+i, instance, parsed); + assertSame(instance, parsed, "--#"+i); } } private static String concat(Object... parts) { @@ -221,8 +223,7 @@ public class MethodTypeTest { return sb.toString().replace('.', '/'); } - @DataProvider(name = "badMethodDescriptorStrings") - public String[] badMethodDescriptorStrings() { + public static String[] badMethodDescriptorStrings() { return new String[] { "(I)", "(V)V", @@ -239,9 +240,12 @@ public class MethodTypeTest { } // JDK-8366028 - @Test(dataProvider = "badMethodDescriptorStrings", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("badMethodDescriptorStrings") public void testFromMethodDescriptorStringNegatives(String desc) { - MethodType.fromMethodDescriptorString(desc, null); + assertThrows(IllegalArgumentException.class, () -> { + MethodType.fromMethodDescriptorString(desc, null); + }); } @Test @@ -251,7 +255,7 @@ public class MethodTypeTest { boolean[] expResults = {true, false, true, false, true, true, false, true}; for (int i = 0; i < instances.length; i++) { boolean result = instances[i].hasPrimitives(); - assertEquals("#"+i, expResults[i], result); + assertEquals(expResults[i], result, "#"+i); } } @@ -263,7 +267,7 @@ public class MethodTypeTest { for (int i = 0; i < instances.length; i++) { System.out.println(" hasWrappers "+instances[i]); boolean result = instances[i].hasWrappers(); - assertEquals("#"+i, expResults[i], result); + assertEquals(expResults[i], result, "#"+i); } } @@ -274,7 +278,7 @@ public class MethodTypeTest { MethodType[] expResults = {mt_viO, mt_OO2, mt_vv, mt_Ov, mt_iO2, mt_OOi, mt_OO2, mt_iOi}; for (int i = 0; i < instances.length; i++) { MethodType result = instances[i].erase(); - assertSame("#"+i, expResults[i], result); + assertSame(expResults[i], result, "#"+i); } } @@ -285,7 +289,7 @@ public class MethodTypeTest { MethodType[] expResults = {mt_OO2, mt_OO2, mt_Ov, mt_Ov, mt_OO2, mt_OO2, mt_OO2, mt_OO2}; for (int i = 0; i < instances.length; i++) { MethodType result = instances[i].generic(); - assertSame("#"+i, expResults[i], result); + assertSame(expResults[i], result, "#"+i); } } @@ -296,7 +300,7 @@ public class MethodTypeTest { MethodType[] expResults = {mt_VIS, mt_OO2, mt_Vv, mt_Ov, mt_ISI, mt_ISI, mt_ISI, mt_ISI}; for (int i = 0; i < instances.length; i++) { MethodType result = instances[i].wrap(); - assertSame("#"+i, expResults[i], result); + assertSame(expResults[i], result, "#"+i); } } @@ -307,7 +311,7 @@ public class MethodTypeTest { MethodType[] expResults = {mt_viS, mt_OO2, mt_vv, mt_Ov, mt_iSi, mt_iSi, mt_iSi, mt_iSi}; for (int i = 0; i < instances.length; i++) { MethodType result = instances[i].unwrap(); - assertSame("#"+i, expResults[i], result); + assertSame(expResults[i], result, "#"+i); } } @@ -436,7 +440,7 @@ public class MethodTypeTest { MethodType instance = instances[i]; String result = instance.toString(); System.out.println("#"+i+":"+result); - assertEquals("#"+i, expResults[i], result); + assertEquals(expResults[i], result, "#"+i); } } diff --git a/test/jdk/java/lang/invoke/PermuteArgsReturnVoidTest.java b/test/jdk/java/lang/invoke/PermuteArgsReturnVoidTest.java index b01a4aa2a99..6bd604dcd36 100644 --- a/test/jdk/java/lang/invoke/PermuteArgsReturnVoidTest.java +++ b/test/jdk/java/lang/invoke/PermuteArgsReturnVoidTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -24,21 +24,21 @@ /* @test * @bug 8184119 * @summary test permutation when return value is directly derived from an argument - * @run testng/othervm test.java.lang.invoke.PermuteArgsReturnVoidTest + * @run junit/othervm test.java.lang.invoke.PermuteArgsReturnVoidTest */ package test.java.lang.invoke; -import org.testng.Assert; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import static java.lang.invoke.MethodHandles.dropArguments; import static java.lang.invoke.MethodHandles.identity; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class PermuteArgsReturnVoidTest { @@ -65,8 +65,8 @@ public class PermuteArgsReturnVoidTest { MethodHandle p = MethodHandles.permuteArguments(f, MethodType.methodType(String.class, String.class, int.class, int.class), 0, 2, 1); String s = (String) p.invoke("IN", 0, 0); - Assert.assertEquals(s.getClass(), String.class); - Assert.assertEquals(s, "IN"); + assertEquals(String.class, s.getClass()); + assertEquals("IN", s); } @Test @@ -84,7 +84,7 @@ public class PermuteArgsReturnVoidTest { MethodHandle p = MethodHandles.permuteArguments(f, MethodType.methodType(String.class, String.class, int.class, int.class), 0, 2, 1); String s = (String) p.invoke("IN", 0, 0); - Assert.assertEquals(s.getClass(), String.class); - Assert.assertEquals(s, "IN"); + assertEquals(String.class, s.getClass()); + assertEquals("IN", s); } } diff --git a/test/jdk/java/lang/invoke/PermuteArgsTest.java b/test/jdk/java/lang/invoke/PermuteArgsTest.java index 3586dc9382f..77558714d11 100644 --- a/test/jdk/java/lang/invoke/PermuteArgsTest.java +++ b/test/jdk/java/lang/invoke/PermuteArgsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @summary unit tests for method handles which permute their arguments * @library /test/lib /java/lang/invoke/common - * @run testng/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -ea -esa -DPermuteArgsTest.MAX_ARITY=8 test.java.lang.invoke.PermuteArgsTest + * @run junit/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -ea -esa -DPermuteArgsTest.MAX_ARITY=8 test.java.lang.invoke.PermuteArgsTest */ /* Examples of manual runs: @@ -35,7 +35,6 @@ package test.java.lang.invoke; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.CodeCacheOverflowProcessor; import java.lang.invoke.MethodHandle; @@ -52,6 +51,10 @@ import static java.lang.invoke.MethodHandles.Lookup; import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.permuteArguments; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PermuteArgsTest { private static final Class CLASS = PermuteArgsTest.class; @@ -259,11 +262,11 @@ public class PermuteArgsTest { reverse(perm, 0, perm.length); } switch (perm.length) { - case 2: assert(testCases - testCases0 == 2); break; - case 3: assert(testCases - testCases0 == 6); break; - case 4: assert(testCases - testCases0 == 24); break; - case 5: assert(testCases - testCases0 == 120); break; - case 6: assert(testCases - testCases0 > 720/3); break; + case 2 -> assertEquals(2, testCases - testCases0); + case 3 -> assertEquals(6, testCases - testCases0); + case 4 -> assertEquals(24, testCases - testCases0); + case 5 -> assertEquals(120, testCases - testCases0); + case 6 -> assertTrue(testCases - testCases0 > 720/3); } } diff --git a/test/jdk/java/lang/invoke/SpreadCollectTest.java b/test/jdk/java/lang/invoke/SpreadCollectTest.java index bcddcd449f8..d58ebab3611 100644 --- a/test/jdk/java/lang/invoke/SpreadCollectTest.java +++ b/test/jdk/java/lang/invoke/SpreadCollectTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @bug 8139885 * @bug 8143798 - * @run testng/othervm -ea -esa test.java.lang.invoke.SpreadCollectTest + * @run junit/othervm -ea -esa test.java.lang.invoke.SpreadCollectTest */ package test.java.lang.invoke; @@ -39,9 +39,11 @@ import java.util.*; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; /** * Tests for the new asSpreader/asCollector API added in JEP 274. @@ -51,14 +53,14 @@ public class SpreadCollectTest { static final Lookup LOOKUP = MethodHandles.lookup(); @Test - public static void testAsSpreader() throws Throwable { + public void testAsSpreader() throws Throwable { MethodHandle spreader = SpreadCollect.MH_forSpreading.asSpreader(1, int[].class, 3); assertEquals(SpreadCollect.MT_spreader, spreader.type()); assertEquals("A456B", (String) spreader.invoke("A", new int[]{4, 5, 6}, "B")); } @Test - public static void testAsSpreaderExample() throws Throwable { + public void testAsSpreaderExample() throws Throwable { // test the JavaDoc asSpreader-with-pos example MethodHandle compare = LOOKUP.findStatic(Objects.class, "compare", methodType(int.class, Object.class, Object.class, Comparator.class)); MethodHandle compare2FromArray = compare.asSpreader(0, Object[].class, 2); @@ -66,49 +68,43 @@ public class SpreadCollectTest { Comparator cmp = (a, b) -> a - b; assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 0, 2), cmp) < 0); assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 1, 3), cmp) > 0); - assertTrue((int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 2, 4), cmp) == 0); + assertEquals(0, (int) compare2FromArray.invoke(Arrays.copyOfRange(ints, 2, 4), cmp)); } - @DataProvider static Object[][] asSpreaderIllegalPositions() { return new Object[][]{{-7}, {3}, {19}}; } - @Test(dataProvider = "asSpreaderIllegalPositions") - public static void testAsSpreaderIllegalPos(int p) throws Throwable { - boolean caught = false; - try { - SpreadCollect.MH_forSpreading.asSpreader(p, Object[].class, 3); - } catch (IllegalArgumentException iae) { - assertEquals("bad spread position", iae.getMessage()); - caught = true; - } - assertTrue(caught); - } - - @Test(expectedExceptions = {WrongMethodTypeException.class}) - public static void testAsSpreaderIllegalMethodType() { - MethodHandle h = MethodHandles.dropArguments(MethodHandles.constant(String.class, ""), 0, int.class, int.class); - MethodHandle s = h.asSpreader(String[].class, 1); - } - - @Test(expectedExceptions = {NullPointerException.class}) - public static void testAsSpreaderNullArrayType() { - SpreadCollect.MH_forSpreading.asSpreader(null, 0); - } - - @Test(expectedExceptions = {NullPointerException.class}) - public static void testAsSpreaderNullArrayNonZeroLength() { - SpreadCollect.MH_forSpreading.asSpreader(null, 1); - } - - @Test(expectedExceptions = {IllegalArgumentException.class}) - public static void testAsSpreaderTooManyParams() throws Throwable { - SpreadCollect.MH_forSpreading.asSpreader(1, int[].class, 6); + @ParameterizedTest + @MethodSource("asSpreaderIllegalPositions") + public void testAsSpreaderIllegalPos(int p) throws Throwable { + var iae = assertThrows(IllegalArgumentException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(p, Object[].class, 3)); + assertEquals("bad spread position", iae.getMessage()); } @Test - public static void testAsCollector() throws Throwable { + public void testAsSpreaderIllegalMethodType() { + MethodHandle h = MethodHandles.dropArguments(MethodHandles.constant(String.class, ""), 0, int.class, int.class); + assertThrows(WrongMethodTypeException.class, () -> h.asSpreader(String[].class, 1)); + } + + @Test + public void testAsSpreaderNullArrayType() { + assertThrows(NullPointerException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(null, 0)); + } + + @Test + public void testAsSpreaderNullArrayNonZeroLength() { + assertThrows(NullPointerException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(null, 1)); + } + + @Test + public void testAsSpreaderTooManyParams() throws Throwable { + assertThrows(IllegalArgumentException.class, () -> SpreadCollect.MH_forSpreading.asSpreader(1, int[].class, 6)); + } + + @Test + public void testAsCollector() throws Throwable { MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 1); assertEquals(SpreadCollect.MT_collector1, collector.type()); assertEquals("A4B", (String) collector.invoke("A", 4, "B")); @@ -121,7 +117,7 @@ public class SpreadCollectTest { } @Test - public static void testAsCollectorInvokeWithArguments() throws Throwable { + public void testAsCollectorInvokeWithArguments() throws Throwable { MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 1); assertEquals(SpreadCollect.MT_collector1, collector.type()); assertEquals("A4B", (String) collector.invokeWithArguments("A", 4, "B")); @@ -134,7 +130,7 @@ public class SpreadCollectTest { } @Test - public static void testAsCollectorLeading() throws Throwable { + public void testAsCollectorLeading() throws Throwable { MethodHandle collector = SpreadCollect.MH_forCollectingLeading.asCollector(0, int[].class, 1); assertEquals(SpreadCollect.MT_collectorLeading1, collector.type()); assertEquals("7Q", (String) collector.invoke(7, "Q")); @@ -147,7 +143,7 @@ public class SpreadCollectTest { } @Test - public static void testAsCollectorLeadingInvokeWithArguments() throws Throwable { + public void testAsCollectorLeadingInvokeWithArguments() throws Throwable { MethodHandle collector = SpreadCollect.MH_forCollectingLeading.asCollector(0, int[].class, 1); assertEquals(SpreadCollect.MT_collectorLeading1, collector.type()); assertEquals("7Q", (String) collector.invokeWithArguments(7, "Q")); @@ -160,31 +156,25 @@ public class SpreadCollectTest { } @Test - public static void testAsCollectorNone() throws Throwable { + public void testAsCollectorNone() throws Throwable { MethodHandle collector = SpreadCollect.MH_forCollecting.asCollector(1, int[].class, 0); assertEquals(SpreadCollect.MT_collector0, collector.type()); assertEquals("AB", (String) collector.invoke("A", "B")); } - @DataProvider static Object[][] asCollectorIllegalPositions() { return new Object[][]{{-1}, {17}}; } - @Test(dataProvider = "asCollectorIllegalPositions") - public static void testAsCollectorIllegalPos(int p) { - boolean caught = false; - try { - SpreadCollect.MH_forCollecting.asCollector(p, int[].class, 0); - } catch (IllegalArgumentException iae) { - assertEquals("bad collect position", iae.getMessage()); - caught = true; - } - assertTrue(caught); + @ParameterizedTest + @MethodSource("asCollectorIllegalPositions") + public void testAsCollectorIllegalPos(int p) { + var iae = assertThrows(IllegalArgumentException.class, () -> SpreadCollect.MH_forCollecting.asCollector(p, int[].class, 0)); + assertEquals("bad collect position", iae.getMessage()); } @Test - public static void testAsCollectorExample() throws Throwable { + public void testAsCollectorExample() throws Throwable { // test the JavaDoc asCollector-with-pos example StringWriter swr = new StringWriter(); MethodHandle swWrite = LOOKUP. diff --git a/test/jdk/java/lang/invoke/TestVHInvokerCaching.java b/test/jdk/java/lang/invoke/TestVHInvokerCaching.java index 0a1ae5914ca..e5c7d50daa7 100644 --- a/test/jdk/java/lang/invoke/TestVHInvokerCaching.java +++ b/test/jdk/java/lang/invoke/TestVHInvokerCaching.java @@ -23,12 +23,9 @@ /* @test * @bug 8265079 - * @run testng/othervm -Xverify:all TestVHInvokerCaching + * @run junit/othervm -Xverify:all TestVHInvokerCaching */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -37,12 +34,16 @@ import java.util.ArrayList; import java.util.List; import static java.lang.invoke.MethodHandles.lookup; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class TestVHInvokerCaching { - @Test(dataProvider = "testHandles") - public static void testVHIInvokerCaching(VarHandle testHandle) throws Throwable { + @ParameterizedTest + @MethodSource("testHandles") + public void testVHIInvokerCaching(VarHandle testHandle) throws Throwable { for (VarHandle.AccessMode mode : VarHandle.AccessMode.values()) { MethodHandle handle1 = MethodHandles.varHandleInvoker(mode, testHandle.accessModeType(mode)); MethodHandle handle2 = MethodHandles.varHandleInvoker(mode, testHandle.accessModeType(mode)); @@ -56,7 +57,6 @@ public class TestVHInvokerCaching { } } - @DataProvider public static Object[][] testHandles() throws NoSuchFieldException, IllegalAccessException { List testHandles = new ArrayList<>(); diff --git a/test/jdk/java/lang/invoke/ThrowExceptionsTest.java b/test/jdk/java/lang/invoke/ThrowExceptionsTest.java index e12bb7040c4..627a056faec 100644 --- a/test/jdk/java/lang/invoke/ThrowExceptionsTest.java +++ b/test/jdk/java/lang/invoke/ThrowExceptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, 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 @@ -23,14 +23,11 @@ /* @test * @summary unit tests for method handles which permute their arguments - * @run testng test.java.lang.invoke.ThrowExceptionsTest + * @run junit test.java.lang.invoke.ThrowExceptionsTest */ package test.java.lang.invoke; -import org.testng.*; -import org.testng.annotations.*; - import java.util.*; import java.lang.reflect.*; @@ -38,6 +35,10 @@ import java.lang.invoke.*; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class ThrowExceptionsTest { private static final Class CLASS = ThrowExceptionsTest.class; private static final Lookup LOOKUP = lookup(); @@ -51,7 +52,7 @@ public class ThrowExceptionsTest { // mostly call testWMTCallee, but sometimes call its void-returning variant MethodHandle mh = testWMTCallee(); MethodHandle mh1 = mh.asType(mh.type().changeReturnType(void.class)); - assert(mh1 != mh); + assertNotSame(mh, mh1); testWMT(mh, mh1, 1000); } @@ -108,7 +109,7 @@ public class ThrowExceptionsTest { MethodHandle[] cell = { null }; // recursion point MethodHandle getCell = insertArguments(arrayElementGetter(cell.getClass()), 0, cell, 0); MethodHandle invokeCell = foldArguments(exactInvoker(cellType), getCell); - assert(invokeCell.type() == cellType); + assertSame(cellType, invokeCell.type()); cell[0] = invokeCell; // make it conformable to any type: invokeCell = dropArguments(invokeCell, 0, Object[].class).asVarargsCollector(Object[].class); @@ -189,7 +190,6 @@ public class ThrowExceptionsTest { try { // FIXME: should not have to retype this n = (int) mh.invokeExact((Object)this, "x"); - assertEquals(n, i - catches); // Using the exact type for this causes endless deopt due to // 'non_cached_result' in SystemDictionary::find_method_handle_invoke. // The problem is that the compiler thread needs to access a cached @@ -198,7 +198,9 @@ public class ThrowExceptionsTest { } catch (Exception ex) { savedEx = ex; catches++; + continue; } + assertEquals(i - catches, n); } //VERBOSE: System.out.println("reps="+reps+" catches="+catches); return savedEx; @@ -220,9 +222,4 @@ public class ThrowExceptionsTest { } return savedEx; } - - private static void assertEquals(Object x, Object y) { - if (x == y || x != null && x.equals(y)) return; - throw new RuntimeException(x+" != "+y); - } } diff --git a/test/jdk/java/lang/invoke/TryFinallyTest.java b/test/jdk/java/lang/invoke/TryFinallyTest.java index 4a3c255201e..ebe276ede93 100644 --- a/test/jdk/java/lang/invoke/TryFinallyTest.java +++ b/test/jdk/java/lang/invoke/TryFinallyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -23,7 +23,7 @@ /* @test * @bug 8139885 8150824 8150825 8194238 8233920 - * @run testng/othervm -ea -esa -Xverify:all test.java.lang.invoke.TryFinallyTest + * @run junit/othervm -ea -esa -Xverify:all test.java.lang.invoke.TryFinallyTest */ package test.java.lang.invoke; @@ -35,9 +35,12 @@ import java.lang.invoke.MethodType; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Tests for the tryFinally method handle combinator introduced in JEP 274. @@ -47,13 +50,12 @@ public class TryFinallyTest { static final Lookup LOOKUP = MethodHandles.lookup(); @Test - public static void testTryFinally() throws Throwable { + public void testTryFinally() throws Throwable { MethodHandle hello = MethodHandles.tryFinally(TryFinally.MH_greet, TryFinally.MH_exclaim); assertEquals(TryFinally.MT_hello, hello.type()); assertEquals("Hello, world!", hello.invoke("world")); } - @DataProvider static Object[][] tryFinallyArgs() { return new Object[][] { { boolean.class, true }, @@ -68,8 +70,9 @@ public class TryFinallyTest { }; } - @Test(dataProvider = "tryFinallyArgs") - public static void testTryFinally(Class argType, Object arg) throws Throwable { + @ParameterizedTest + @MethodSource("tryFinallyArgs") + public void testTryFinally(Class argType, Object arg) throws Throwable { MethodHandle identity = MethodHandles.identity(argType); MethodHandle tryFinally = MethodHandles.tryFinally( identity, @@ -78,31 +81,31 @@ public class TryFinallyTest { assertEquals(arg, tryFinally.invoke(arg)); } - @Test(dataProvider = "tryFinallyArgs", expectedExceptions = TryFinally.T1.class) - public static void testTryFinallyException(Class argType, Object arg) throws Throwable { + @ParameterizedTest + @MethodSource("tryFinallyArgs") + public void testTryFinallyException(Class argType, Object arg) throws Throwable { MethodHandle identity = TryFinally.MH_throwingTargetIdentity.asType(methodType(argType, argType)); MethodHandle tryFinally = MethodHandles.tryFinally( identity, MethodHandles.dropArguments(identity, 0, TryFinally.T1.class)); assertEquals(methodType(argType, argType), tryFinally.type()); - tryFinally.invoke(arg); // should throw + assertThrows(TryFinally.T1.class, () -> tryFinally.invoke(arg)); } @Test - public static void testTryFinallyVoid() throws Throwable { + public void testTryFinallyVoid() throws Throwable { MethodHandle tfVoid = MethodHandles.tryFinally(TryFinally.MH_print, TryFinally.MH_printMore); assertEquals(TryFinally.MT_printHello, tfVoid.type()); tfVoid.invoke("world"); } @Test - public static void testTryFinallySublist() throws Throwable { + public void testTryFinallySublist() throws Throwable { MethodHandle helloMore = MethodHandles.tryFinally(TryFinally.MH_greetMore, TryFinally.MH_exclaimMore); assertEquals(TryFinally.MT_moreHello, helloMore.type()); assertEquals("Hello, world and universe (but world first)!", helloMore.invoke("world", "universe")); } - @DataProvider static Object[][] omitTrailingArguments() { MethodHandle c = TryFinally.MH_voidCleanup; return new Object[][]{ @@ -114,13 +117,13 @@ public class TryFinallyTest { }; } - @Test(dataProvider = "omitTrailingArguments") - public static void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable { + @ParameterizedTest + @MethodSource("omitTrailingArguments") + public void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable { MethodHandle tf = MethodHandles.tryFinally(TryFinally.MH_dummyTarget, cleanup); tf.invoke(1, 2L, "a", 23, 42L, "b"); } - @DataProvider static Object[][] negativeTestData() { MethodHandle intid = MethodHandles.identity(int.class); MethodHandle intco = MethodHandles.constant(int.class, 0); @@ -145,29 +148,18 @@ public class TryFinallyTest { }; } - @Test(dataProvider = "negativeTestData") - public static void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) { - boolean caught = false; - try { - MethodHandles.tryFinally(target, cleanup); - } catch (IllegalArgumentException iae) { - assertEquals(expectedMessage, iae.getMessage()); - caught = true; - } - assertTrue(caught); + @ParameterizedTest + @MethodSource("negativeTestData") + public void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) { + var iae = assertThrows(IllegalArgumentException.class, () -> MethodHandles.tryFinally(target, cleanup)); + assertEquals(expectedMessage, iae.getMessage()); } @Test - public static void testTryFinallyThrowableCheck() { + public void testTryFinallyThrowableCheck() { MethodHandle mh = MethodHandles.tryFinally(TryFinally.MH_throwingTarget, TryFinally.MH_catchingCleanup); - try { - mh.invoke(); - fail("ClassCastException expected"); - } catch (Throwable t) { - assertTrue("Throwable not assignable to ClassCastException: " + t, - ClassCastException.class.isAssignableFrom(t.getClass())); - } + assertThrows(ClassCastException.class, mh::invoke); } static class TryFinally { diff --git a/test/jdk/java/lang/invoke/VarArgsTest.java b/test/jdk/java/lang/invoke/VarArgsTest.java index bb17881b514..bcea9a0b54e 100644 --- a/test/jdk/java/lang/invoke/VarArgsTest.java +++ b/test/jdk/java/lang/invoke/VarArgsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -23,19 +23,18 @@ /* @test * @summary unit tests for java.lang.invoke.MethodHandles - * @run testng/othervm -ea -esa test.java.lang.invoke.VarArgsTest + * @run junit/othervm -ea -esa test.java.lang.invoke.VarArgsTest */ package test.java.lang.invoke; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.util.Arrays; import java.util.List; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; -import static org.testng.AssertJUnit.*; -import org.testng.annotations.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public class VarArgsTest { @@ -61,17 +60,17 @@ public class VarArgsTest { MethodHandle asList = publicLookup() .findStatic(Arrays.class, "asList", methodType(List.class, Object[].class)); MethodHandle asListWithVarargs = asList.withVarargs(asList.isVarargsCollector()); - assert(asListWithVarargs.isVarargsCollector()); + assertTrue(asListWithVarargs.isVarargsCollector()); assertEquals("[]", asListWithVarargs.invoke().toString()); assertEquals("[1]", asListWithVarargs.invoke(1).toString()); assertEquals("[two, too]", asListWithVarargs.invoke("two", "too").toString()); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void testWithVarargsIAE() throws Throwable { MethodHandle lenMH = publicLookup() - .findVirtual(String.class, "length", methodType(int.class)); - MethodHandle lenMHWithVarargs = lenMH.withVarargs(true); + .findVirtual(String.class, "length", methodType(int.class)); + assertThrows(IllegalArgumentException.class, () -> lenMH.withVarargs(true)); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java index f09ba518e48..c89fcc8289b 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseByteArrayTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -21,9 +21,6 @@ * questions. */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; - import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -32,6 +29,7 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.List; import java.util.function.Function; +import org.junit.jupiter.api.BeforeAll; public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest { @@ -338,7 +336,7 @@ public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest { bavss.add(dbb_offset_unaligned_ro); } - @BeforeClass + @BeforeAll public void setup() { setupByteSources(); vhss = setupVarHandleSources(true); @@ -346,13 +344,10 @@ public abstract class VarHandleBaseByteArrayTest extends VarHandleBaseTest { abstract List setupVarHandleSources(boolean same); - - @DataProvider public Object[][] varHandlesProvider() throws Exception { return vhss.stream().map(cvh -> new Object[]{cvh}).toArray(Object[][]::new); } - @DataProvider public Object[][] typesProvider() throws Exception { List> aepts = Arrays.asList(byte[].class, int.class); List> bbpts = Arrays.asList(ByteBuffer.class, int.class); diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseTest.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseTest.java index 0c9a7fd3953..0e029b8f5f7 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseTest.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleBaseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -36,7 +36,7 @@ import java.util.Map; import java.util.stream.Stream; import static java.util.stream.Collectors.toList; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; abstract class VarHandleBaseTest { static final int ITERS = Integer.getInteger("iters", 1); @@ -136,18 +136,7 @@ abstract class VarHandleBaseTest { static void checkWithThrowable(Class re, Object message, ThrowingRunnable r) { - Throwable _e = null; - try { - r.run(); - } - catch (Throwable e) { - _e = e; - } - message = message == null ? "" : message + ". "; - assertNotNull(_e, String.format("%sNo throwable thrown. Expected %s", message, re)); - if (!re.isInstance(_e)) { - fail(String.format("%sIncorrect throwable thrown, %s. Expected %s", message, _e, re), _e); - } + assertThrows(re, r::run, message == null ? null : message.toString()); } @@ -277,11 +266,11 @@ abstract class VarHandleBaseTest { } private static MethodHandle bind(VarHandle vh, MethodHandle mh, MethodType emt) { - assertEquals(mh.type(), emt.insertParameterTypes(0, VarHandle.class), + assertEquals(emt.insertParameterTypes(0, VarHandle.class), mh.type(), "MethodHandle type differs from access mode type"); MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); - assertEquals(info.getMethodType(), emt, + assertEquals(emt, info.getMethodType(), "MethodHandleInfo method type differs from access mode type"); return mh.bindTo(vh); @@ -472,39 +461,39 @@ abstract class VarHandleBaseTest { for (TestAccessMode accessMode : testAccessModes()) { MethodType amt = vh.accessModeType(accessMode.toAccessMode()); - assertEquals(amt.parameterList().subList(0, pts.size()), pts); + assertEquals(pts, amt.parameterList().subList(0, pts.size())); } for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET)) { MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); - assertEquals(mt.returnType(), vh.varType()); - assertEquals(mt.parameterList(), pts); + assertEquals(vh.varType(), mt.returnType()); + assertEquals(pts, mt.parameterList()); } for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.SET)) { MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); - assertEquals(mt.returnType(), void.class); - assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); + assertEquals(void.class, mt.returnType()); + assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1)); } for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); - assertEquals(mt.returnType(), boolean.class); - assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); - assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType()); + assertEquals(boolean.class, mt.returnType()); + assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1)); + assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 2)); } for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); - assertEquals(mt.returnType(), vh.varType()); - assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); - assertEquals(mt.parameterType(mt.parameterCount() - 2), vh.varType()); + assertEquals(vh.varType(), mt.returnType()); + assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1)); + assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 2)); } for (TestAccessMode testAccessMode : testAccessModesOfType(TestAccessType.GET_AND_SET, TestAccessType.GET_AND_ADD)) { MethodType mt = vh.accessModeType(testAccessMode.toAccessMode()); - assertEquals(mt.returnType(), vh.varType()); - assertEquals(mt.parameterType(mt.parameterCount() - 1), vh.varType()); + assertEquals(vh.varType(), mt.returnType()); + assertEquals(vh.varType(), mt.parameterType(mt.parameterCount() - 1)); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java index 02de5a3e186..23e46096073 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleMethodReferenceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -25,12 +25,12 @@ * @test * @bug 8195650 * @summary Test linking of method references to VarHandle access methods. - * @run testng VarHandleMethodReferenceTest + * @run junit VarHandleMethodReferenceTest */ -import org.testng.annotations.Test; import java.lang.invoke.*; +import org.junit.jupiter.api.Test; public class VarHandleMethodReferenceTest { diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java index a9cd5a61655..548e008b09e 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessBoolean + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessBoolean * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessBoolean - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessBoolean - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessBoolean + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessBoolean + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessBoolean + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessBoolean */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessBoolean extends VarHandleBaseTest { static final boolean static_final_v = true; @@ -108,7 +110,7 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessBoolean.class, "final_v", boolean.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(boolean[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessBoolean.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), boolean.class); + assertEquals(boolean.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { // Plain { boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "get boolean value"); + assertEquals(true, x, "get boolean value"); } // Volatile { boolean x = (boolean) vh.getVolatile(recv); - assertEquals(x, true, "getVolatile boolean value"); + assertEquals(true, x, "getVolatile boolean value"); } // Lazy { boolean x = (boolean) vh.getAcquire(recv); - assertEquals(x, true, "getRelease boolean value"); + assertEquals(true, x, "getRelease boolean value"); } // Opaque { boolean x = (boolean) vh.getOpaque(recv); - assertEquals(x, true, "getOpaque boolean value"); + assertEquals(true, x, "getOpaque boolean value"); } } @@ -357,26 +355,26 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { // Plain { boolean x = (boolean) vh.get(); - assertEquals(x, true, "get boolean value"); + assertEquals(true, x, "get boolean value"); } // Volatile { boolean x = (boolean) vh.getVolatile(); - assertEquals(x, true, "getVolatile boolean value"); + assertEquals(true, x, "getVolatile boolean value"); } // Lazy { boolean x = (boolean) vh.getAcquire(); - assertEquals(x, true, "getRelease boolean value"); + assertEquals(true, x, "getRelease boolean value"); } // Opaque { boolean x = (boolean) vh.getOpaque(); - assertEquals(x, true, "getOpaque boolean value"); + assertEquals(true, x, "getOpaque boolean value"); } } @@ -418,7 +416,7 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { { vh.set(recv, true); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "set boolean value"); + assertEquals(true, x, "set boolean value"); } @@ -426,21 +424,21 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { { vh.setVolatile(recv, false); boolean x = (boolean) vh.getVolatile(recv); - assertEquals(x, false, "setVolatile boolean value"); + assertEquals(false, x, "setVolatile boolean value"); } // Lazy { vh.setRelease(recv, true); boolean x = (boolean) vh.getAcquire(recv); - assertEquals(x, true, "setRelease boolean value"); + assertEquals(true, x, "setRelease boolean value"); } // Opaque { vh.setOpaque(recv, false); boolean x = (boolean) vh.getOpaque(recv); - assertEquals(x, false, "setOpaque boolean value"); + assertEquals(false, x, "setOpaque boolean value"); } vh.set(recv, true); @@ -450,56 +448,56 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, true, false); assertEquals(r, true, "success compareAndSet boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "success compareAndSet boolean value"); + assertEquals(false, x, "success compareAndSet boolean value"); } { boolean r = vh.compareAndSet(recv, true, false); assertEquals(r, false, "failing compareAndSet boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "failing compareAndSet boolean value"); + assertEquals(false, x, "failing compareAndSet boolean value"); } { boolean r = (boolean) vh.compareAndExchange(recv, false, true); assertEquals(r, false, "success compareAndExchange boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "success compareAndExchange boolean value"); + assertEquals(true, x, "success compareAndExchange boolean value"); } { boolean r = (boolean) vh.compareAndExchange(recv, false, false); assertEquals(r, true, "failing compareAndExchange boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "failing compareAndExchange boolean value"); + assertEquals(true, x, "failing compareAndExchange boolean value"); } { boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false); assertEquals(r, true, "success compareAndExchangeAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "success compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) vh.compareAndExchangeAcquire(recv, true, false); assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "failing compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) vh.compareAndExchangeRelease(recv, false, true); assertEquals(r, false, "success compareAndExchangeRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "success compareAndExchangeRelease boolean value"); + assertEquals(true, x, "success compareAndExchangeRelease boolean value"); } { boolean r = (boolean) vh.compareAndExchangeRelease(recv, false, false); assertEquals(r, true, "failing compareAndExchangeRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); + assertEquals(true, x, "failing compareAndExchangeRelease boolean value"); } { @@ -510,14 +508,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "success weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "success weakCompareAndSetPlain boolean value"); } { boolean success = vh.weakCompareAndSetPlain(recv, true, false); assertEquals(success, false, "failing weakCompareAndSetPlain boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "failing weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "failing weakCompareAndSetPlain boolean value"); } { @@ -528,14 +526,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "success weakCompareAndSetAcquire boolean"); + assertEquals(true, x, "success weakCompareAndSetAcquire boolean"); } { boolean success = vh.weakCompareAndSetAcquire(recv, false, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -546,14 +544,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "success weakCompareAndSetRelease boolean"); + assertEquals(false, x, "success weakCompareAndSetRelease boolean"); } { boolean success = vh.weakCompareAndSetRelease(recv, true, false); assertEquals(success, false, "failing weakCompareAndSetRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "failing weakCompareAndSetRelease boolean value"); + assertEquals(false, x, "failing weakCompareAndSetRelease boolean value"); } { @@ -564,14 +562,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "success weakCompareAndSet boolean value"); + assertEquals(true, x, "success weakCompareAndSet boolean value"); } { boolean success = vh.weakCompareAndSet(recv, false, false); assertEquals(success, false, "failing weakCompareAndSet boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, true, "failing weakCompareAndSet boolean value"); + assertEquals(true, x, "failing weakCompareAndSet boolean value"); } // Compare set and get @@ -579,27 +577,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(recv, true); boolean o = (boolean) vh.getAndSet(recv, false); - assertEquals(o, true, "getAndSet boolean"); + assertEquals(true, o, "getAndSet boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "getAndSet boolean value"); + assertEquals(false, x, "getAndSet boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndSetAcquire(recv, false); - assertEquals(o, true, "getAndSetAcquire boolean"); + assertEquals(true, o, "getAndSetAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "getAndSetAcquire boolean value"); + assertEquals(false, x, "getAndSetAcquire boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndSetRelease(recv, false); - assertEquals(o, true, "getAndSetRelease boolean"); + assertEquals(true, o, "getAndSetRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, false, "getAndSetRelease boolean value"); + assertEquals(false, x, "getAndSetRelease boolean value"); } @@ -608,27 +606,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseOr(recv, false); - assertEquals(o, true, "getAndBitwiseOr boolean"); + assertEquals(true, o, "getAndBitwiseOr boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseOrAcquire(recv, false); - assertEquals(o, true, "getAndBitwiseOrAcquire boolean"); + assertEquals(true, o, "getAndBitwiseOrAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseOrRelease(recv, false); - assertEquals(o, true, "getAndBitwiseOrRelease boolean"); + assertEquals(true, o, "getAndBitwiseOrRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value"); } // get and bitwise and @@ -636,27 +634,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseAnd(recv, false); - assertEquals(o, true, "getAndBitwiseAnd boolean"); + assertEquals(true, o, "getAndBitwiseAnd boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseAndAcquire(recv, false); - assertEquals(o, true, "getAndBitwiseAndAcquire boolean"); + assertEquals(true, o, "getAndBitwiseAndAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseAndRelease(recv, false); - assertEquals(o, true, "getAndBitwiseAndRelease boolean"); + assertEquals(true, o, "getAndBitwiseAndRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value"); } // get and bitwise xor @@ -664,27 +662,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseXor(recv, false); - assertEquals(o, true, "getAndBitwiseXor boolean"); + assertEquals(true, o, "getAndBitwiseXor boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseXorAcquire(recv, false); - assertEquals(o, true, "getAndBitwiseXorAcquire boolean"); + assertEquals(true, o, "getAndBitwiseXorAcquire boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value"); } { vh.set(recv, true); boolean o = (boolean) vh.getAndBitwiseXorRelease(recv, false); - assertEquals(o, true, "getAndBitwiseXorRelease boolean"); + assertEquals(true, o, "getAndBitwiseXorRelease boolean"); boolean x = (boolean) vh.get(recv); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value"); } } @@ -710,7 +708,7 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { { vh.set(true); boolean x = (boolean) vh.get(); - assertEquals(x, true, "set boolean value"); + assertEquals(true, x, "set boolean value"); } @@ -718,21 +716,21 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { { vh.setVolatile(false); boolean x = (boolean) vh.getVolatile(); - assertEquals(x, false, "setVolatile boolean value"); + assertEquals(false, x, "setVolatile boolean value"); } // Lazy { vh.setRelease(true); boolean x = (boolean) vh.getAcquire(); - assertEquals(x, true, "setRelease boolean value"); + assertEquals(true, x, "setRelease boolean value"); } // Opaque { vh.setOpaque(false); boolean x = (boolean) vh.getOpaque(); - assertEquals(x, false, "setOpaque boolean value"); + assertEquals(false, x, "setOpaque boolean value"); } vh.set(true); @@ -742,56 +740,56 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { boolean r = vh.compareAndSet(true, false); assertEquals(r, true, "success compareAndSet boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "success compareAndSet boolean value"); + assertEquals(false, x, "success compareAndSet boolean value"); } { boolean r = vh.compareAndSet(true, false); assertEquals(r, false, "failing compareAndSet boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "failing compareAndSet boolean value"); + assertEquals(false, x, "failing compareAndSet boolean value"); } { boolean r = (boolean) vh.compareAndExchange(false, true); assertEquals(r, false, "success compareAndExchange boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "success compareAndExchange boolean value"); + assertEquals(true, x, "success compareAndExchange boolean value"); } { boolean r = (boolean) vh.compareAndExchange(false, false); assertEquals(r, true, "failing compareAndExchange boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "failing compareAndExchange boolean value"); + assertEquals(true, x, "failing compareAndExchange boolean value"); } { boolean r = (boolean) vh.compareAndExchangeAcquire(true, false); assertEquals(r, true, "success compareAndExchangeAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "success compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) vh.compareAndExchangeAcquire(true, false); assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "failing compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) vh.compareAndExchangeRelease(false, true); assertEquals(r, false, "success compareAndExchangeRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "success compareAndExchangeRelease boolean value"); + assertEquals(true, x, "success compareAndExchangeRelease boolean value"); } { boolean r = (boolean) vh.compareAndExchangeRelease(false, false); assertEquals(r, true, "failing compareAndExchangeRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); + assertEquals(true, x, "failing compareAndExchangeRelease boolean value"); } { @@ -802,14 +800,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "success weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "success weakCompareAndSetPlain boolean value"); } { boolean success = vh.weakCompareAndSetPlain(true, false); assertEquals(success, false, "failing weakCompareAndSetPlain boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "failing weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "failing weakCompareAndSetPlain boolean value"); } { @@ -820,14 +818,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "success weakCompareAndSetAcquire boolean"); + assertEquals(true, x, "success weakCompareAndSetAcquire boolean"); } { boolean success = vh.weakCompareAndSetAcquire(false, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -838,14 +836,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "success weakCompareAndSetRelease boolean"); + assertEquals(false, x, "success weakCompareAndSetRelease boolean"); } { boolean success = vh.weakCompareAndSetRelease(true, false); assertEquals(success, false, "failing weakCompareAndSetRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "failing weakCompareAndSetRelease boolean value"); + assertEquals(false, x, "failing weakCompareAndSetRelease boolean value"); } { @@ -856,14 +854,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "success weakCompareAndSet boolean"); + assertEquals(true, x, "success weakCompareAndSet boolean"); } { boolean success = vh.weakCompareAndSet(false, false); assertEquals(success, false, "failing weakCompareAndSet boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, true, "failing weakCompareAndSet boolean value"); + assertEquals(true, x, "failing weakCompareAndSet boolean value"); } // Compare set and get @@ -871,27 +869,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(true); boolean o = (boolean) vh.getAndSet(false); - assertEquals(o, true, "getAndSet boolean"); + assertEquals(true, o, "getAndSet boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "getAndSet boolean value"); + assertEquals(false, x, "getAndSet boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndSetAcquire(false); - assertEquals(o, true, "getAndSetAcquire boolean"); + assertEquals(true, o, "getAndSetAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "getAndSetAcquire boolean value"); + assertEquals(false, x, "getAndSetAcquire boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndSetRelease(false); - assertEquals(o, true, "getAndSetRelease boolean"); + assertEquals(true, o, "getAndSetRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, false, "getAndSetRelease boolean value"); + assertEquals(false, x, "getAndSetRelease boolean value"); } @@ -900,27 +898,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(true); boolean o = (boolean) vh.getAndBitwiseOr(false); - assertEquals(o, true, "getAndBitwiseOr boolean"); + assertEquals(true, o, "getAndBitwiseOr boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndBitwiseOrAcquire(false); - assertEquals(o, true, "getAndBitwiseOrAcquire boolean"); + assertEquals(true, o, "getAndBitwiseOrAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndBitwiseOrRelease(false); - assertEquals(o, true, "getAndBitwiseOrRelease boolean"); + assertEquals(true, o, "getAndBitwiseOrRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value"); } // get and bitwise and @@ -928,27 +926,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(true); boolean o = (boolean) vh.getAndBitwiseAnd(false); - assertEquals(o, true, "getAndBitwiseAnd boolean"); + assertEquals(true, o, "getAndBitwiseAnd boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndBitwiseAndAcquire(false); - assertEquals(o, true, "getAndBitwiseAndAcquire boolean"); + assertEquals(true, o, "getAndBitwiseAndAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndBitwiseAndRelease(false); - assertEquals(o, true, "getAndBitwiseAndRelease boolean"); + assertEquals(true, o, "getAndBitwiseAndRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value"); } // get and bitwise xor @@ -956,27 +954,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(true); boolean o = (boolean) vh.getAndBitwiseXor(false); - assertEquals(o, true, "getAndBitwiseXor boolean"); + assertEquals(true, o, "getAndBitwiseXor boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndBitwiseXorAcquire(false); - assertEquals(o, true, "getAndBitwiseXorAcquire boolean"); + assertEquals(true, o, "getAndBitwiseXorAcquire boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value"); } { vh.set(true); boolean o = (boolean) vh.getAndBitwiseXorRelease(false); - assertEquals(o, true, "getAndBitwiseXorRelease boolean"); + assertEquals(true, o, "getAndBitwiseXorRelease boolean"); boolean x = (boolean) vh.get(); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value"); } } @@ -1005,7 +1003,7 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { { vh.set(array, i, true); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "get boolean value"); + assertEquals(true, x, "get boolean value"); } @@ -1013,21 +1011,21 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { { vh.setVolatile(array, i, false); boolean x = (boolean) vh.getVolatile(array, i); - assertEquals(x, false, "setVolatile boolean value"); + assertEquals(false, x, "setVolatile boolean value"); } // Lazy { vh.setRelease(array, i, true); boolean x = (boolean) vh.getAcquire(array, i); - assertEquals(x, true, "setRelease boolean value"); + assertEquals(true, x, "setRelease boolean value"); } // Opaque { vh.setOpaque(array, i, false); boolean x = (boolean) vh.getOpaque(array, i); - assertEquals(x, false, "setOpaque boolean value"); + assertEquals(false, x, "setOpaque boolean value"); } vh.set(array, i, true); @@ -1037,56 +1035,56 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, true, false); assertEquals(r, true, "success compareAndSet boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "success compareAndSet boolean value"); + assertEquals(false, x, "success compareAndSet boolean value"); } { boolean r = vh.compareAndSet(array, i, true, false); assertEquals(r, false, "failing compareAndSet boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "failing compareAndSet boolean value"); + assertEquals(false, x, "failing compareAndSet boolean value"); } { boolean r = (boolean) vh.compareAndExchange(array, i, false, true); assertEquals(r, false, "success compareAndExchange boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "success compareAndExchange boolean value"); + assertEquals(true, x, "success compareAndExchange boolean value"); } { boolean r = (boolean) vh.compareAndExchange(array, i, false, false); assertEquals(r, true, "failing compareAndExchange boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "failing compareAndExchange boolean value"); + assertEquals(true, x, "failing compareAndExchange boolean value"); } { boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false); assertEquals(r, true, "success compareAndExchangeAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "success compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) vh.compareAndExchangeAcquire(array, i, true, false); assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "failing compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) vh.compareAndExchangeRelease(array, i, false, true); assertEquals(r, false, "success compareAndExchangeRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "success compareAndExchangeRelease boolean value"); + assertEquals(true, x, "success compareAndExchangeRelease boolean value"); } { boolean r = (boolean) vh.compareAndExchangeRelease(array, i, false, false); assertEquals(r, true, "failing compareAndExchangeRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); + assertEquals(true, x, "failing compareAndExchangeRelease boolean value"); } { @@ -1097,14 +1095,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "success weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "success weakCompareAndSetPlain boolean value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, true, false); assertEquals(success, false, "failing weakCompareAndSetPlain boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "failing weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "failing weakCompareAndSetPlain boolean value"); } { @@ -1115,14 +1113,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "success weakCompareAndSetAcquire boolean"); + assertEquals(true, x, "success weakCompareAndSetAcquire boolean"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, false, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -1133,14 +1131,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "success weakCompareAndSetRelease boolean"); + assertEquals(false, x, "success weakCompareAndSetRelease boolean"); } { boolean success = vh.weakCompareAndSetRelease(array, i, true, false); assertEquals(success, false, "failing weakCompareAndSetRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "failing weakCompareAndSetRelease boolean value"); + assertEquals(false, x, "failing weakCompareAndSetRelease boolean value"); } { @@ -1151,14 +1149,14 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "success weakCompareAndSet boolean"); + assertEquals(true, x, "success weakCompareAndSet boolean"); } { boolean success = vh.weakCompareAndSet(array, i, false, false); assertEquals(success, false, "failing weakCompareAndSet boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, true, "failing weakCompareAndSet boolean value"); + assertEquals(true, x, "failing weakCompareAndSet boolean value"); } // Compare set and get @@ -1166,27 +1164,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(array, i, true); boolean o = (boolean) vh.getAndSet(array, i, false); - assertEquals(o, true, "getAndSet boolean"); + assertEquals(true, o, "getAndSet boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "getAndSet boolean value"); + assertEquals(false, x, "getAndSet boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndSetAcquire(array, i, false); - assertEquals(o, true, "getAndSetAcquire boolean"); + assertEquals(true, o, "getAndSetAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "getAndSetAcquire boolean value"); + assertEquals(false, x, "getAndSetAcquire boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndSetRelease(array, i, false); - assertEquals(o, true, "getAndSetRelease boolean"); + assertEquals(true, o, "getAndSetRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, false, "getAndSetRelease boolean value"); + assertEquals(false, x, "getAndSetRelease boolean value"); } @@ -1195,27 +1193,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseOr(array, i, false); - assertEquals(o, true, "getAndBitwiseOr boolean"); + assertEquals(true, o, "getAndBitwiseOr boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseOrAcquire(array, i, false); - assertEquals(o, true, "getAndBitwiseOrAcquire boolean"); + assertEquals(true, o, "getAndBitwiseOrAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseOrRelease(array, i, false); - assertEquals(o, true, "getAndBitwiseOrRelease boolean"); + assertEquals(true, o, "getAndBitwiseOrRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value"); } // get and bitwise and @@ -1223,27 +1221,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseAnd(array, i, false); - assertEquals(o, true, "getAndBitwiseAnd boolean"); + assertEquals(true, o, "getAndBitwiseAnd boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseAndAcquire(array, i, false); - assertEquals(o, true, "getAndBitwiseAndAcquire boolean"); + assertEquals(true, o, "getAndBitwiseAndAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseAndRelease(array, i, false); - assertEquals(o, true, "getAndBitwiseAndRelease boolean"); + assertEquals(true, o, "getAndBitwiseAndRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value"); } // get and bitwise xor @@ -1251,27 +1249,27 @@ public class VarHandleTestAccessBoolean extends VarHandleBaseTest { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseXor(array, i, false); - assertEquals(o, true, "getAndBitwiseXor boolean"); + assertEquals(true, o, "getAndBitwiseXor boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseXorAcquire(array, i, false); - assertEquals(o, true, "getAndBitwiseXorAcquire boolean"); + assertEquals(true, o, "getAndBitwiseXorAcquire boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value"); } { vh.set(array, i, true); boolean o = (boolean) vh.getAndBitwiseXorRelease(array, i, false); - assertEquals(o, true, "getAndBitwiseXorRelease boolean"); + assertEquals(true, o, "getAndBitwiseXorRelease boolean"); boolean x = (boolean) vh.get(array, i); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java index 5dc4bf2d1d5..42c465af75e 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessByte + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessByte * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessByte - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessByte - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessByte + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessByte + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessByte + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessByte */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessByte extends VarHandleBaseTest { static final byte static_final_v = (byte)0x01; @@ -108,7 +110,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessByte.class, "final_v", byte.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(byte[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessByte.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), byte.class); + assertEquals(byte.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { // Plain { byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "get byte value"); + assertEquals((byte)0x01, x, "get byte value"); } // Volatile { byte x = (byte) vh.getVolatile(recv); - assertEquals(x, (byte)0x01, "getVolatile byte value"); + assertEquals((byte)0x01, x, "getVolatile byte value"); } // Lazy { byte x = (byte) vh.getAcquire(recv); - assertEquals(x, (byte)0x01, "getRelease byte value"); + assertEquals((byte)0x01, x, "getRelease byte value"); } // Opaque { byte x = (byte) vh.getOpaque(recv); - assertEquals(x, (byte)0x01, "getOpaque byte value"); + assertEquals((byte)0x01, x, "getOpaque byte value"); } } @@ -346,26 +344,26 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { // Plain { byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "get byte value"); + assertEquals((byte)0x01, x, "get byte value"); } // Volatile { byte x = (byte) vh.getVolatile(); - assertEquals(x, (byte)0x01, "getVolatile byte value"); + assertEquals((byte)0x01, x, "getVolatile byte value"); } // Lazy { byte x = (byte) vh.getAcquire(); - assertEquals(x, (byte)0x01, "getRelease byte value"); + assertEquals((byte)0x01, x, "getRelease byte value"); } // Opaque { byte x = (byte) vh.getOpaque(); - assertEquals(x, (byte)0x01, "getOpaque byte value"); + assertEquals((byte)0x01, x, "getOpaque byte value"); } } @@ -396,7 +394,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { { vh.set(recv, (byte)0x01); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "set byte value"); + assertEquals((byte)0x01, x, "set byte value"); } @@ -404,21 +402,21 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { { vh.setVolatile(recv, (byte)0x23); byte x = (byte) vh.getVolatile(recv); - assertEquals(x, (byte)0x23, "setVolatile byte value"); + assertEquals((byte)0x23, x, "setVolatile byte value"); } // Lazy { vh.setRelease(recv, (byte)0x01); byte x = (byte) vh.getAcquire(recv); - assertEquals(x, (byte)0x01, "setRelease byte value"); + assertEquals((byte)0x01, x, "setRelease byte value"); } // Opaque { vh.setOpaque(recv, (byte)0x23); byte x = (byte) vh.getOpaque(recv); - assertEquals(x, (byte)0x23, "setOpaque byte value"); + assertEquals((byte)0x23, x, "setOpaque byte value"); } vh.set(recv, (byte)0x01); @@ -428,56 +426,56 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x23); assertEquals(r, true, "success compareAndSet byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "success compareAndSet byte value"); + assertEquals((byte)0x23, x, "success compareAndSet byte value"); } { boolean r = vh.compareAndSet(recv, (byte)0x01, (byte)0x45); assertEquals(r, false, "failing compareAndSet byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); + assertEquals((byte)0x23, x, "failing compareAndSet byte value"); } { byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchange byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); + assertEquals((byte)0x01, x, "success compareAndExchange byte value"); } { byte r = (byte) vh.compareAndExchange(recv, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchange byte value"); } { byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x23); assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "success compareAndExchangeAcquire byte value"); } { byte r = (byte) vh.compareAndExchangeAcquire(recv, (byte)0x01, (byte)0x45); assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "failing compareAndExchangeAcquire byte value"); } { byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "success compareAndExchangeRelease byte value"); } { byte r = (byte) vh.compareAndExchangeRelease(recv, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchangeRelease byte value"); } { @@ -488,14 +486,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "success weakCompareAndSetPlain byte value"); } { boolean success = vh.weakCompareAndSetPlain(recv, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetPlain byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetPlain byte value"); } { @@ -506,14 +504,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSetAcquire byte"); } { boolean success = vh.weakCompareAndSetAcquire(recv, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -524,14 +522,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte"); + assertEquals((byte)0x23, x, "success weakCompareAndSetRelease byte"); } { boolean success = vh.weakCompareAndSetRelease(recv, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetRelease byte value"); } { @@ -542,14 +540,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "success weakCompareAndSet byte value"); + assertEquals((byte)0x01, x, "success weakCompareAndSet byte value"); } { boolean success = vh.weakCompareAndSet(recv, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSet byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSet byte value"); } // Compare set and get @@ -557,27 +555,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndSet(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSet byte"); + assertEquals((byte)0x01, o, "getAndSet byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "getAndSet byte value"); + assertEquals((byte)0x23, x, "getAndSet byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndSetAcquire(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); + assertEquals((byte)0x01, o, "getAndSetAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); + assertEquals((byte)0x23, x, "getAndSetAcquire byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndSetRelease(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetRelease byte"); + assertEquals((byte)0x01, o, "getAndSetRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); + assertEquals((byte)0x23, x, "getAndSetRelease byte value"); } // get and add, add and get @@ -585,27 +583,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndAdd(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAdd byte"); + assertEquals((byte)0x01, o, "getAndAdd byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAdd byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndAddAcquire(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); + assertEquals((byte)0x01, o, "getAndAddAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddAcquire byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndAddRelease(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddReleasebyte"); + assertEquals((byte)0x01, o, "getAndAddReleasebyte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddRelease byte value"); } // get and bitwise or @@ -613,27 +611,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseOr(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOr byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOr byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseOrAcquire(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrAcquire byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseOrRelease(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrRelease byte value"); } // get and bitwise and @@ -641,27 +639,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseAnd(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAnd byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAnd byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseAndAcquire(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndAcquire byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseAndRelease(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndRelease byte value"); } // get and bitwise xor @@ -669,27 +667,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseXor(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXor byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXor byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseXorAcquire(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorAcquire byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorAcquire byte value"); } { vh.set(recv, (byte)0x01); byte o = (byte) vh.getAndBitwiseXorRelease(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorRelease byte"); byte x = (byte) vh.get(recv); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorRelease byte value"); } } @@ -704,7 +702,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { { vh.set((byte)0x01); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "set byte value"); + assertEquals((byte)0x01, x, "set byte value"); } @@ -712,21 +710,21 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { { vh.setVolatile((byte)0x23); byte x = (byte) vh.getVolatile(); - assertEquals(x, (byte)0x23, "setVolatile byte value"); + assertEquals((byte)0x23, x, "setVolatile byte value"); } // Lazy { vh.setRelease((byte)0x01); byte x = (byte) vh.getAcquire(); - assertEquals(x, (byte)0x01, "setRelease byte value"); + assertEquals((byte)0x01, x, "setRelease byte value"); } // Opaque { vh.setOpaque((byte)0x23); byte x = (byte) vh.getOpaque(); - assertEquals(x, (byte)0x23, "setOpaque byte value"); + assertEquals((byte)0x23, x, "setOpaque byte value"); } vh.set((byte)0x01); @@ -736,56 +734,56 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { boolean r = vh.compareAndSet((byte)0x01, (byte)0x23); assertEquals(r, true, "success compareAndSet byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "success compareAndSet byte value"); + assertEquals((byte)0x23, x, "success compareAndSet byte value"); } { boolean r = vh.compareAndSet((byte)0x01, (byte)0x45); assertEquals(r, false, "failing compareAndSet byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); + assertEquals((byte)0x23, x, "failing compareAndSet byte value"); } { byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchange byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); + assertEquals((byte)0x01, x, "success compareAndExchange byte value"); } { byte r = (byte) vh.compareAndExchange((byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchange byte value"); } { byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x23); assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "success compareAndExchangeAcquire byte value"); } { byte r = (byte) vh.compareAndExchangeAcquire((byte)0x01, (byte)0x45); assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "failing compareAndExchangeAcquire byte value"); } { byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "success compareAndExchangeRelease byte value"); } { byte r = (byte) vh.compareAndExchangeRelease((byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchangeRelease byte value"); } { @@ -796,14 +794,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "success weakCompareAndSetPlain byte value"); } { boolean success = vh.weakCompareAndSetPlain((byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetPlain byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetPlain byte value"); } { @@ -814,14 +812,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSetAcquire byte"); } { boolean success = vh.weakCompareAndSetAcquire((byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -832,14 +830,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte"); + assertEquals((byte)0x23, x, "success weakCompareAndSetRelease byte"); } { boolean success = vh.weakCompareAndSetRelease((byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetRelease byte value"); } { @@ -850,14 +848,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "success weakCompareAndSet byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSet byte"); } { boolean success = vh.weakCompareAndSet((byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSet byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSet byte value"); } // Compare set and get @@ -865,27 +863,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set((byte)0x01); byte o = (byte) vh.getAndSet((byte)0x23); - assertEquals(o, (byte)0x01, "getAndSet byte"); + assertEquals((byte)0x01, o, "getAndSet byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "getAndSet byte value"); + assertEquals((byte)0x23, x, "getAndSet byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndSetAcquire((byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); + assertEquals((byte)0x01, o, "getAndSetAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); + assertEquals((byte)0x23, x, "getAndSetAcquire byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndSetRelease((byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetRelease byte"); + assertEquals((byte)0x01, o, "getAndSetRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); + assertEquals((byte)0x23, x, "getAndSetRelease byte value"); } // get and add, add and get @@ -893,27 +891,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set((byte)0x01); byte o = (byte) vh.getAndAdd((byte)0x23); - assertEquals(o, (byte)0x01, "getAndAdd byte"); + assertEquals((byte)0x01, o, "getAndAdd byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAdd byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndAddAcquire((byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); + assertEquals((byte)0x01, o, "getAndAddAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddAcquire byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndAddRelease((byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddReleasebyte"); + assertEquals((byte)0x01, o, "getAndAddReleasebyte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddRelease byte value"); } // get and bitwise or @@ -921,27 +919,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseOr((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOr byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOr byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseOrAcquire((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrAcquire byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseOrRelease((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrRelease byte value"); } // get and bitwise and @@ -949,27 +947,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseAnd((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAnd byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAnd byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseAndAcquire((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndAcquire byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseAndRelease((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndRelease byte value"); } // get and bitwise xor @@ -977,27 +975,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseXor((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXor byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXor byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseXorAcquire((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorAcquire byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorAcquire byte value"); } { vh.set((byte)0x01); byte o = (byte) vh.getAndBitwiseXorRelease((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorRelease byte"); byte x = (byte) vh.get(); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorRelease byte value"); } } @@ -1015,7 +1013,7 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { { vh.set(array, i, (byte)0x01); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "get byte value"); + assertEquals((byte)0x01, x, "get byte value"); } @@ -1023,21 +1021,21 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { { vh.setVolatile(array, i, (byte)0x23); byte x = (byte) vh.getVolatile(array, i); - assertEquals(x, (byte)0x23, "setVolatile byte value"); + assertEquals((byte)0x23, x, "setVolatile byte value"); } // Lazy { vh.setRelease(array, i, (byte)0x01); byte x = (byte) vh.getAcquire(array, i); - assertEquals(x, (byte)0x01, "setRelease byte value"); + assertEquals((byte)0x01, x, "setRelease byte value"); } // Opaque { vh.setOpaque(array, i, (byte)0x23); byte x = (byte) vh.getOpaque(array, i); - assertEquals(x, (byte)0x23, "setOpaque byte value"); + assertEquals((byte)0x23, x, "setOpaque byte value"); } vh.set(array, i, (byte)0x01); @@ -1047,56 +1045,56 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x23); assertEquals(r, true, "success compareAndSet byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "success compareAndSet byte value"); + assertEquals((byte)0x23, x, "success compareAndSet byte value"); } { boolean r = vh.compareAndSet(array, i, (byte)0x01, (byte)0x45); assertEquals(r, false, "failing compareAndSet byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); + assertEquals((byte)0x23, x, "failing compareAndSet byte value"); } { byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchange byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); + assertEquals((byte)0x01, x, "success compareAndExchange byte value"); } { byte r = (byte) vh.compareAndExchange(array, i, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchange byte value"); } { byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x23); assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "success compareAndExchangeAcquire byte value"); } { byte r = (byte) vh.compareAndExchangeAcquire(array, i, (byte)0x01, (byte)0x45); assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "failing compareAndExchangeAcquire byte value"); } { byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "success compareAndExchangeRelease byte value"); } { byte r = (byte) vh.compareAndExchangeRelease(array, i, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchangeRelease byte value"); } { @@ -1107,14 +1105,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "success weakCompareAndSetPlain byte value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetPlain byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetPlain byte value"); } { @@ -1125,14 +1123,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSetAcquire byte"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -1143,14 +1141,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte"); + assertEquals((byte)0x23, x, "success weakCompareAndSetRelease byte"); } { boolean success = vh.weakCompareAndSetRelease(array, i, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetRelease byte value"); } { @@ -1161,14 +1159,14 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "success weakCompareAndSet byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSet byte"); } { boolean success = vh.weakCompareAndSet(array, i, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSet byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSet byte value"); } // Compare set and get @@ -1176,27 +1174,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndSet(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSet byte"); + assertEquals((byte)0x01, o, "getAndSet byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "getAndSet byte value"); + assertEquals((byte)0x23, x, "getAndSet byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndSetAcquire(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); + assertEquals((byte)0x01, o, "getAndSetAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); + assertEquals((byte)0x23, x, "getAndSetAcquire byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndSetRelease(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetRelease byte"); + assertEquals((byte)0x01, o, "getAndSetRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); + assertEquals((byte)0x23, x, "getAndSetRelease byte value"); } // get and add, add and get @@ -1204,27 +1202,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndAdd(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAdd byte"); + assertEquals((byte)0x01, o, "getAndAdd byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAdd byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndAddAcquire(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); + assertEquals((byte)0x01, o, "getAndAddAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddAcquire byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndAddRelease(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddReleasebyte"); + assertEquals((byte)0x01, o, "getAndAddReleasebyte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddRelease byte value"); } // get and bitwise or @@ -1232,27 +1230,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseOr(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOr byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOr byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseOrAcquire(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrAcquire byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseOrRelease(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrRelease byte value"); } // get and bitwise and @@ -1260,27 +1258,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseAnd(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAnd byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAnd byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseAndAcquire(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndAcquire byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseAndRelease(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndRelease byte value"); } // get and bitwise xor @@ -1288,27 +1286,27 @@ public class VarHandleTestAccessByte extends VarHandleBaseTest { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseXor(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXor byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXor byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseXorAcquire(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorAcquire byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorAcquire byte value"); } { vh.set(array, i, (byte)0x01); byte o = (byte) vh.getAndBitwiseXorRelease(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorRelease byte"); byte x = (byte) vh.get(array, i); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorRelease byte value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java index bafde057167..e17e7616609 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessChar + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessChar * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessChar - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessChar + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessChar + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessChar + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessChar */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessChar extends VarHandleBaseTest { static final char static_final_v = '\u0123'; @@ -108,7 +110,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessChar.class, "final_v", char.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(char[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessChar.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), char.class); + assertEquals(char.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { // Plain { char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "get char value"); + assertEquals('\u0123', x, "get char value"); } // Volatile { char x = (char) vh.getVolatile(recv); - assertEquals(x, '\u0123', "getVolatile char value"); + assertEquals('\u0123', x, "getVolatile char value"); } // Lazy { char x = (char) vh.getAcquire(recv); - assertEquals(x, '\u0123', "getRelease char value"); + assertEquals('\u0123', x, "getRelease char value"); } // Opaque { char x = (char) vh.getOpaque(recv); - assertEquals(x, '\u0123', "getOpaque char value"); + assertEquals('\u0123', x, "getOpaque char value"); } } @@ -346,26 +344,26 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { // Plain { char x = (char) vh.get(); - assertEquals(x, '\u0123', "get char value"); + assertEquals('\u0123', x, "get char value"); } // Volatile { char x = (char) vh.getVolatile(); - assertEquals(x, '\u0123', "getVolatile char value"); + assertEquals('\u0123', x, "getVolatile char value"); } // Lazy { char x = (char) vh.getAcquire(); - assertEquals(x, '\u0123', "getRelease char value"); + assertEquals('\u0123', x, "getRelease char value"); } // Opaque { char x = (char) vh.getOpaque(); - assertEquals(x, '\u0123', "getOpaque char value"); + assertEquals('\u0123', x, "getOpaque char value"); } } @@ -396,7 +394,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { { vh.set(recv, '\u0123'); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "set char value"); + assertEquals('\u0123', x, "set char value"); } @@ -404,21 +402,21 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { { vh.setVolatile(recv, '\u4567'); char x = (char) vh.getVolatile(recv); - assertEquals(x, '\u4567', "setVolatile char value"); + assertEquals('\u4567', x, "setVolatile char value"); } // Lazy { vh.setRelease(recv, '\u0123'); char x = (char) vh.getAcquire(recv); - assertEquals(x, '\u0123', "setRelease char value"); + assertEquals('\u0123', x, "setRelease char value"); } // Opaque { vh.setOpaque(recv, '\u4567'); char x = (char) vh.getOpaque(recv); - assertEquals(x, '\u4567', "setOpaque char value"); + assertEquals('\u4567', x, "setOpaque char value"); } vh.set(recv, '\u0123'); @@ -428,56 +426,56 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, '\u0123', '\u4567'); assertEquals(r, true, "success compareAndSet char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "success compareAndSet char value"); + assertEquals('\u4567', x, "success compareAndSet char value"); } { boolean r = vh.compareAndSet(recv, '\u0123', '\u89AB'); assertEquals(r, false, "failing compareAndSet char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "failing compareAndSet char value"); + assertEquals('\u4567', x, "failing compareAndSet char value"); } { char r = (char) vh.compareAndExchange(recv, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchange char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "success compareAndExchange char value"); + assertEquals('\u0123', x, "success compareAndExchange char value"); } { char r = (char) vh.compareAndExchange(recv, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchange char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "failing compareAndExchange char value"); + assertEquals('\u0123', x, "failing compareAndExchange char value"); } { char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u4567'); assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "success compareAndExchangeAcquire char value"); } { char r = (char) vh.compareAndExchangeAcquire(recv, '\u0123', '\u89AB'); assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "failing compareAndExchangeAcquire char value"); } { char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "success compareAndExchangeRelease char value"); } { char r = (char) vh.compareAndExchangeRelease(recv, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "failing compareAndExchangeRelease char value"); } { @@ -488,14 +486,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "success weakCompareAndSetPlain char value"); } { boolean success = vh.weakCompareAndSetPlain(recv, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetPlain char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetPlain char value"); } { @@ -506,14 +504,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); + assertEquals('\u0123', x, "success weakCompareAndSetAcquire char"); } { boolean success = vh.weakCompareAndSetAcquire(recv, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetAcquire char value"); } { @@ -524,14 +522,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); + assertEquals('\u4567', x, "success weakCompareAndSetRelease char"); } { boolean success = vh.weakCompareAndSetRelease(recv, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetRelease char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetRelease char value"); } { @@ -542,14 +540,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "success weakCompareAndSet char value"); + assertEquals('\u0123', x, "success weakCompareAndSet char value"); } { boolean success = vh.weakCompareAndSet(recv, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSet char"); char x = (char) vh.get(recv); - assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); + assertEquals('\u0123', x, "failing weakCompareAndSet char value"); } // Compare set and get @@ -557,27 +555,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(recv, '\u0123'); char o = (char) vh.getAndSet(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndSet char"); + assertEquals('\u0123', o, "getAndSet char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "getAndSet char value"); + assertEquals('\u4567', x, "getAndSet char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndSetAcquire(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndSetAcquire char"); + assertEquals('\u0123', o, "getAndSetAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "getAndSetAcquire char value"); + assertEquals('\u4567', x, "getAndSetAcquire char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndSetRelease(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndSetRelease char"); + assertEquals('\u0123', o, "getAndSetRelease char"); char x = (char) vh.get(recv); - assertEquals(x, '\u4567', "getAndSetRelease char value"); + assertEquals('\u4567', x, "getAndSetRelease char value"); } // get and add, add and get @@ -585,27 +583,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(recv, '\u0123'); char o = (char) vh.getAndAdd(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndAdd char"); + assertEquals('\u0123', o, "getAndAdd char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAdd char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndAddAcquire(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndAddAcquire char"); + assertEquals('\u0123', o, "getAndAddAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddAcquire char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndAddRelease(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndAddReleasechar"); + assertEquals('\u0123', o, "getAndAddReleasechar"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddRelease char value"); } // get and bitwise or @@ -613,27 +611,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseOr(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOr char"); + assertEquals('\u0123', o, "getAndBitwiseOr char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOr char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseOrAcquire(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseOrAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrAcquire char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseOrRelease(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); + assertEquals('\u0123', o, "getAndBitwiseOrRelease char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrRelease char value"); } // get and bitwise and @@ -641,27 +639,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseAnd(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAnd char"); + assertEquals('\u0123', o, "getAndBitwiseAnd char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAnd char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseAndAcquire(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseAndAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndAcquire char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseAndRelease(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); + assertEquals('\u0123', o, "getAndBitwiseAndRelease char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndRelease char value"); } // get and bitwise xor @@ -669,27 +667,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseXor(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXor char"); + assertEquals('\u0123', o, "getAndBitwiseXor char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXor char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseXorAcquire(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseXorAcquire char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorAcquire char value"); } { vh.set(recv, '\u0123'); char o = (char) vh.getAndBitwiseXorRelease(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); + assertEquals('\u0123', o, "getAndBitwiseXorRelease char"); char x = (char) vh.get(recv); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorRelease char value"); } } @@ -704,7 +702,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { { vh.set('\u0123'); char x = (char) vh.get(); - assertEquals(x, '\u0123', "set char value"); + assertEquals('\u0123', x, "set char value"); } @@ -712,21 +710,21 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { { vh.setVolatile('\u4567'); char x = (char) vh.getVolatile(); - assertEquals(x, '\u4567', "setVolatile char value"); + assertEquals('\u4567', x, "setVolatile char value"); } // Lazy { vh.setRelease('\u0123'); char x = (char) vh.getAcquire(); - assertEquals(x, '\u0123', "setRelease char value"); + assertEquals('\u0123', x, "setRelease char value"); } // Opaque { vh.setOpaque('\u4567'); char x = (char) vh.getOpaque(); - assertEquals(x, '\u4567', "setOpaque char value"); + assertEquals('\u4567', x, "setOpaque char value"); } vh.set('\u0123'); @@ -736,56 +734,56 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { boolean r = vh.compareAndSet('\u0123', '\u4567'); assertEquals(r, true, "success compareAndSet char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "success compareAndSet char value"); + assertEquals('\u4567', x, "success compareAndSet char value"); } { boolean r = vh.compareAndSet('\u0123', '\u89AB'); assertEquals(r, false, "failing compareAndSet char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "failing compareAndSet char value"); + assertEquals('\u4567', x, "failing compareAndSet char value"); } { char r = (char) vh.compareAndExchange('\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchange char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "success compareAndExchange char value"); + assertEquals('\u0123', x, "success compareAndExchange char value"); } { char r = (char) vh.compareAndExchange('\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchange char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "failing compareAndExchange char value"); + assertEquals('\u0123', x, "failing compareAndExchange char value"); } { char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u4567'); assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "success compareAndExchangeAcquire char value"); } { char r = (char) vh.compareAndExchangeAcquire('\u0123', '\u89AB'); assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "failing compareAndExchangeAcquire char value"); } { char r = (char) vh.compareAndExchangeRelease('\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "success compareAndExchangeRelease char value"); } { char r = (char) vh.compareAndExchangeRelease('\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "failing compareAndExchangeRelease char value"); } { @@ -796,14 +794,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "success weakCompareAndSetPlain char value"); } { boolean success = vh.weakCompareAndSetPlain('\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetPlain char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetPlain char value"); } { @@ -814,14 +812,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); + assertEquals('\u0123', x, "success weakCompareAndSetAcquire char"); } { boolean success = vh.weakCompareAndSetAcquire('\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetAcquire char value"); } { @@ -832,14 +830,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); + assertEquals('\u4567', x, "success weakCompareAndSetRelease char"); } { boolean success = vh.weakCompareAndSetRelease('\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetRelease char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetRelease char value"); } { @@ -850,14 +848,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "success weakCompareAndSet char"); + assertEquals('\u0123', x, "success weakCompareAndSet char"); } { boolean success = vh.weakCompareAndSet('\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSet char"); char x = (char) vh.get(); - assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); + assertEquals('\u0123', x, "failing weakCompareAndSet char value"); } // Compare set and get @@ -865,27 +863,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set('\u0123'); char o = (char) vh.getAndSet('\u4567'); - assertEquals(o, '\u0123', "getAndSet char"); + assertEquals('\u0123', o, "getAndSet char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "getAndSet char value"); + assertEquals('\u4567', x, "getAndSet char value"); } { vh.set('\u0123'); char o = (char) vh.getAndSetAcquire('\u4567'); - assertEquals(o, '\u0123', "getAndSetAcquire char"); + assertEquals('\u0123', o, "getAndSetAcquire char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "getAndSetAcquire char value"); + assertEquals('\u4567', x, "getAndSetAcquire char value"); } { vh.set('\u0123'); char o = (char) vh.getAndSetRelease('\u4567'); - assertEquals(o, '\u0123', "getAndSetRelease char"); + assertEquals('\u0123', o, "getAndSetRelease char"); char x = (char) vh.get(); - assertEquals(x, '\u4567', "getAndSetRelease char value"); + assertEquals('\u4567', x, "getAndSetRelease char value"); } // get and add, add and get @@ -893,27 +891,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set('\u0123'); char o = (char) vh.getAndAdd('\u4567'); - assertEquals(o, '\u0123', "getAndAdd char"); + assertEquals('\u0123', o, "getAndAdd char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAdd char value"); } { vh.set('\u0123'); char o = (char) vh.getAndAddAcquire('\u4567'); - assertEquals(o, '\u0123', "getAndAddAcquire char"); + assertEquals('\u0123', o, "getAndAddAcquire char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddAcquire char value"); } { vh.set('\u0123'); char o = (char) vh.getAndAddRelease('\u4567'); - assertEquals(o, '\u0123', "getAndAddReleasechar"); + assertEquals('\u0123', o, "getAndAddReleasechar"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddRelease char value"); } // get and bitwise or @@ -921,27 +919,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set('\u0123'); char o = (char) vh.getAndBitwiseOr('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOr char"); + assertEquals('\u0123', o, "getAndBitwiseOr char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOr char value"); } { vh.set('\u0123'); char o = (char) vh.getAndBitwiseOrAcquire('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseOrAcquire char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrAcquire char value"); } { vh.set('\u0123'); char o = (char) vh.getAndBitwiseOrRelease('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); + assertEquals('\u0123', o, "getAndBitwiseOrRelease char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrRelease char value"); } // get and bitwise and @@ -949,27 +947,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set('\u0123'); char o = (char) vh.getAndBitwiseAnd('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAnd char"); + assertEquals('\u0123', o, "getAndBitwiseAnd char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAnd char value"); } { vh.set('\u0123'); char o = (char) vh.getAndBitwiseAndAcquire('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseAndAcquire char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndAcquire char value"); } { vh.set('\u0123'); char o = (char) vh.getAndBitwiseAndRelease('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); + assertEquals('\u0123', o, "getAndBitwiseAndRelease char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndRelease char value"); } // get and bitwise xor @@ -977,27 +975,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set('\u0123'); char o = (char) vh.getAndBitwiseXor('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXor char"); + assertEquals('\u0123', o, "getAndBitwiseXor char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXor char value"); } { vh.set('\u0123'); char o = (char) vh.getAndBitwiseXorAcquire('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseXorAcquire char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorAcquire char value"); } { vh.set('\u0123'); char o = (char) vh.getAndBitwiseXorRelease('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); + assertEquals('\u0123', o, "getAndBitwiseXorRelease char"); char x = (char) vh.get(); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorRelease char value"); } } @@ -1015,7 +1013,7 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { { vh.set(array, i, '\u0123'); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "get char value"); + assertEquals('\u0123', x, "get char value"); } @@ -1023,21 +1021,21 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { { vh.setVolatile(array, i, '\u4567'); char x = (char) vh.getVolatile(array, i); - assertEquals(x, '\u4567', "setVolatile char value"); + assertEquals('\u4567', x, "setVolatile char value"); } // Lazy { vh.setRelease(array, i, '\u0123'); char x = (char) vh.getAcquire(array, i); - assertEquals(x, '\u0123', "setRelease char value"); + assertEquals('\u0123', x, "setRelease char value"); } // Opaque { vh.setOpaque(array, i, '\u4567'); char x = (char) vh.getOpaque(array, i); - assertEquals(x, '\u4567', "setOpaque char value"); + assertEquals('\u4567', x, "setOpaque char value"); } vh.set(array, i, '\u0123'); @@ -1047,56 +1045,56 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, '\u0123', '\u4567'); assertEquals(r, true, "success compareAndSet char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "success compareAndSet char value"); + assertEquals('\u4567', x, "success compareAndSet char value"); } { boolean r = vh.compareAndSet(array, i, '\u0123', '\u89AB'); assertEquals(r, false, "failing compareAndSet char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "failing compareAndSet char value"); + assertEquals('\u4567', x, "failing compareAndSet char value"); } { char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchange char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "success compareAndExchange char value"); + assertEquals('\u0123', x, "success compareAndExchange char value"); } { char r = (char) vh.compareAndExchange(array, i, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchange char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "failing compareAndExchange char value"); + assertEquals('\u0123', x, "failing compareAndExchange char value"); } { char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u4567'); assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "success compareAndExchangeAcquire char value"); } { char r = (char) vh.compareAndExchangeAcquire(array, i, '\u0123', '\u89AB'); assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "failing compareAndExchangeAcquire char value"); } { char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "success compareAndExchangeRelease char value"); } { char r = (char) vh.compareAndExchangeRelease(array, i, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "failing compareAndExchangeRelease char value"); } { @@ -1107,14 +1105,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "success weakCompareAndSetPlain char value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetPlain char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetPlain char value"); } { @@ -1125,14 +1123,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); + assertEquals('\u0123', x, "success weakCompareAndSetAcquire char"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetAcquire char value"); } { @@ -1143,14 +1141,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); + assertEquals('\u4567', x, "success weakCompareAndSetRelease char"); } { boolean success = vh.weakCompareAndSetRelease(array, i, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetRelease char value"); } { @@ -1161,14 +1159,14 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "success weakCompareAndSet char"); + assertEquals('\u0123', x, "success weakCompareAndSet char"); } { boolean success = vh.weakCompareAndSet(array, i, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSet char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); + assertEquals('\u0123', x, "failing weakCompareAndSet char value"); } // Compare set and get @@ -1176,27 +1174,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(array, i, '\u0123'); char o = (char) vh.getAndSet(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndSet char"); + assertEquals('\u0123', o, "getAndSet char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "getAndSet char value"); + assertEquals('\u4567', x, "getAndSet char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndSetAcquire(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndSetAcquire char"); + assertEquals('\u0123', o, "getAndSetAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "getAndSetAcquire char value"); + assertEquals('\u4567', x, "getAndSetAcquire char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndSetRelease(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndSetRelease char"); + assertEquals('\u0123', o, "getAndSetRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, '\u4567', "getAndSetRelease char value"); + assertEquals('\u4567', x, "getAndSetRelease char value"); } // get and add, add and get @@ -1204,27 +1202,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(array, i, '\u0123'); char o = (char) vh.getAndAdd(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndAdd char"); + assertEquals('\u0123', o, "getAndAdd char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAdd char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndAddAcquire(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndAddAcquire char"); + assertEquals('\u0123', o, "getAndAddAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddAcquire char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndAddRelease(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndAddReleasechar"); + assertEquals('\u0123', o, "getAndAddReleasechar"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddRelease char value"); } // get and bitwise or @@ -1232,27 +1230,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseOr(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOr char"); + assertEquals('\u0123', o, "getAndBitwiseOr char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOr char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseOrAcquire(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseOrAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrAcquire char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseOrRelease(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); + assertEquals('\u0123', o, "getAndBitwiseOrRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrRelease char value"); } // get and bitwise and @@ -1260,27 +1258,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseAnd(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAnd char"); + assertEquals('\u0123', o, "getAndBitwiseAnd char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAnd char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseAndAcquire(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseAndAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndAcquire char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseAndRelease(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); + assertEquals('\u0123', o, "getAndBitwiseAndRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndRelease char value"); } // get and bitwise xor @@ -1288,27 +1286,27 @@ public class VarHandleTestAccessChar extends VarHandleBaseTest { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseXor(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXor char"); + assertEquals('\u0123', o, "getAndBitwiseXor char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXor char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseXorAcquire(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseXorAcquire char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorAcquire char value"); } { vh.set(array, i, '\u0123'); char o = (char) vh.getAndBitwiseXorRelease(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); + assertEquals('\u0123', o, "getAndBitwiseXorRelease char"); char x = (char) vh.get(array, i); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorRelease char value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java index 0edb196076c..29fa6c2886d 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessDouble + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessDouble * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessDouble - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessDouble - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessDouble + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessDouble + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessDouble + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessDouble */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessDouble extends VarHandleBaseTest { static final double static_final_v = 1.0d; @@ -108,7 +110,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessDouble.class, "final_v", double.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(double[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessDouble.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), double.class); + assertEquals(double.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { // Plain { double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "get double value"); + assertEquals(1.0d, x, "get double value"); } // Volatile { double x = (double) vh.getVolatile(recv); - assertEquals(x, 1.0d, "getVolatile double value"); + assertEquals(1.0d, x, "getVolatile double value"); } // Lazy { double x = (double) vh.getAcquire(recv); - assertEquals(x, 1.0d, "getRelease double value"); + assertEquals(1.0d, x, "getRelease double value"); } // Opaque { double x = (double) vh.getOpaque(recv); - assertEquals(x, 1.0d, "getOpaque double value"); + assertEquals(1.0d, x, "getOpaque double value"); } } @@ -381,26 +379,26 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { // Plain { double x = (double) vh.get(); - assertEquals(x, 1.0d, "get double value"); + assertEquals(1.0d, x, "get double value"); } // Volatile { double x = (double) vh.getVolatile(); - assertEquals(x, 1.0d, "getVolatile double value"); + assertEquals(1.0d, x, "getVolatile double value"); } // Lazy { double x = (double) vh.getAcquire(); - assertEquals(x, 1.0d, "getRelease double value"); + assertEquals(1.0d, x, "getRelease double value"); } // Opaque { double x = (double) vh.getOpaque(); - assertEquals(x, 1.0d, "getOpaque double value"); + assertEquals(1.0d, x, "getOpaque double value"); } } @@ -466,7 +464,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { { vh.set(recv, 1.0d); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "set double value"); + assertEquals(1.0d, x, "set double value"); } @@ -474,21 +472,21 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { { vh.setVolatile(recv, 2.0d); double x = (double) vh.getVolatile(recv); - assertEquals(x, 2.0d, "setVolatile double value"); + assertEquals(2.0d, x, "setVolatile double value"); } // Lazy { vh.setRelease(recv, 1.0d); double x = (double) vh.getAcquire(recv); - assertEquals(x, 1.0d, "setRelease double value"); + assertEquals(1.0d, x, "setRelease double value"); } // Opaque { vh.setOpaque(recv, 2.0d); double x = (double) vh.getOpaque(recv); - assertEquals(x, 2.0d, "setOpaque double value"); + assertEquals(2.0d, x, "setOpaque double value"); } vh.set(recv, 1.0d); @@ -498,56 +496,56 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, 1.0d, 2.0d); assertEquals(r, true, "success compareAndSet double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "success compareAndSet double value"); + assertEquals(2.0d, x, "success compareAndSet double value"); } { boolean r = vh.compareAndSet(recv, 1.0d, 3.0d); assertEquals(r, false, "failing compareAndSet double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "failing compareAndSet double value"); + assertEquals(2.0d, x, "failing compareAndSet double value"); } { double r = (double) vh.compareAndExchange(recv, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchange double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "success compareAndExchange double value"); + assertEquals(1.0d, x, "success compareAndExchange double value"); } { double r = (double) vh.compareAndExchange(recv, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchange double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "failing compareAndExchange double value"); + assertEquals(1.0d, x, "failing compareAndExchange double value"); } { double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 2.0d); assertEquals(r, 1.0d, "success compareAndExchangeAcquire double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "success compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeAcquire(recv, 1.0d, 3.0d); assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchangeRelease double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "success compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "success compareAndExchangeRelease double value"); } { double r = (double) vh.compareAndExchangeRelease(recv, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchangeRelease double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "failing compareAndExchangeRelease double value"); } { @@ -558,14 +556,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "success weakCompareAndSetPlain double value"); } { boolean success = vh.weakCompareAndSetPlain(recv, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value"); } { @@ -576,14 +574,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double"); + assertEquals(1.0d, x, "success weakCompareAndSetAcquire double"); } { boolean success = vh.weakCompareAndSetAcquire(recv, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -594,14 +592,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "success weakCompareAndSetRelease double"); + assertEquals(2.0d, x, "success weakCompareAndSetRelease double"); } { boolean success = vh.weakCompareAndSetRelease(recv, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetRelease double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value"); } { @@ -612,14 +610,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "success weakCompareAndSet double value"); + assertEquals(1.0d, x, "success weakCompareAndSet double value"); } { boolean success = vh.weakCompareAndSet(recv, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) vh.get(recv); - assertEquals(x, 1.0d, "failing weakCompareAndSet double value"); + assertEquals(1.0d, x, "failing weakCompareAndSet double value"); } // Compare set and get @@ -627,27 +625,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vh.set(recv, 1.0d); double o = (double) vh.getAndSet(recv, 2.0d); - assertEquals(o, 1.0d, "getAndSet double"); + assertEquals(1.0d, o, "getAndSet double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "getAndSet double value"); + assertEquals(2.0d, x, "getAndSet double value"); } { vh.set(recv, 1.0d); double o = (double) vh.getAndSetAcquire(recv, 2.0d); - assertEquals(o, 1.0d, "getAndSetAcquire double"); + assertEquals(1.0d, o, "getAndSetAcquire double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "getAndSetAcquire double value"); + assertEquals(2.0d, x, "getAndSetAcquire double value"); } { vh.set(recv, 1.0d); double o = (double) vh.getAndSetRelease(recv, 2.0d); - assertEquals(o, 1.0d, "getAndSetRelease double"); + assertEquals(1.0d, o, "getAndSetRelease double"); double x = (double) vh.get(recv); - assertEquals(x, 2.0d, "getAndSetRelease double value"); + assertEquals(2.0d, x, "getAndSetRelease double value"); } // get and add, add and get @@ -655,27 +653,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vh.set(recv, 1.0d); double o = (double) vh.getAndAdd(recv, 2.0d); - assertEquals(o, 1.0d, "getAndAdd double"); + assertEquals(1.0d, o, "getAndAdd double"); double x = (double) vh.get(recv); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value"); } { vh.set(recv, 1.0d); double o = (double) vh.getAndAddAcquire(recv, 2.0d); - assertEquals(o, 1.0d, "getAndAddAcquire double"); + assertEquals(1.0d, o, "getAndAddAcquire double"); double x = (double) vh.get(recv); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value"); } { vh.set(recv, 1.0d); double o = (double) vh.getAndAddRelease(recv, 2.0d); - assertEquals(o, 1.0d, "getAndAddReleasedouble"); + assertEquals(1.0d, o, "getAndAddReleasedouble"); double x = (double) vh.get(recv); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value"); } } @@ -726,7 +724,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { { vh.set(1.0d); double x = (double) vh.get(); - assertEquals(x, 1.0d, "set double value"); + assertEquals(1.0d, x, "set double value"); } @@ -734,21 +732,21 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { { vh.setVolatile(2.0d); double x = (double) vh.getVolatile(); - assertEquals(x, 2.0d, "setVolatile double value"); + assertEquals(2.0d, x, "setVolatile double value"); } // Lazy { vh.setRelease(1.0d); double x = (double) vh.getAcquire(); - assertEquals(x, 1.0d, "setRelease double value"); + assertEquals(1.0d, x, "setRelease double value"); } // Opaque { vh.setOpaque(2.0d); double x = (double) vh.getOpaque(); - assertEquals(x, 2.0d, "setOpaque double value"); + assertEquals(2.0d, x, "setOpaque double value"); } vh.set(1.0d); @@ -758,56 +756,56 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { boolean r = vh.compareAndSet(1.0d, 2.0d); assertEquals(r, true, "success compareAndSet double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "success compareAndSet double value"); + assertEquals(2.0d, x, "success compareAndSet double value"); } { boolean r = vh.compareAndSet(1.0d, 3.0d); assertEquals(r, false, "failing compareAndSet double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "failing compareAndSet double value"); + assertEquals(2.0d, x, "failing compareAndSet double value"); } { double r = (double) vh.compareAndExchange(2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchange double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "success compareAndExchange double value"); + assertEquals(1.0d, x, "success compareAndExchange double value"); } { double r = (double) vh.compareAndExchange(2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchange double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "failing compareAndExchange double value"); + assertEquals(1.0d, x, "failing compareAndExchange double value"); } { double r = (double) vh.compareAndExchangeAcquire(1.0d, 2.0d); assertEquals(r, 1.0d, "success compareAndExchangeAcquire double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "success compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeAcquire(1.0d, 3.0d); assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeRelease(2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchangeRelease double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "success compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "success compareAndExchangeRelease double value"); } { double r = (double) vh.compareAndExchangeRelease(2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchangeRelease double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "failing compareAndExchangeRelease double value"); } { @@ -818,14 +816,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "success weakCompareAndSetPlain double value"); } { boolean success = vh.weakCompareAndSetPlain(1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value"); } { @@ -836,14 +834,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double"); + assertEquals(1.0d, x, "success weakCompareAndSetAcquire double"); } { boolean success = vh.weakCompareAndSetAcquire(2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -854,14 +852,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "success weakCompareAndSetRelease double"); + assertEquals(2.0d, x, "success weakCompareAndSetRelease double"); } { boolean success = vh.weakCompareAndSetRelease(1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetRelease double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value"); } { @@ -872,14 +870,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "success weakCompareAndSet double"); + assertEquals(1.0d, x, "success weakCompareAndSet double"); } { boolean success = vh.weakCompareAndSet(2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) vh.get(); - assertEquals(x, 1.0d, "failing weakCompareAndSet double value"); + assertEquals(1.0d, x, "failing weakCompareAndSet double value"); } // Compare set and get @@ -887,27 +885,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vh.set(1.0d); double o = (double) vh.getAndSet(2.0d); - assertEquals(o, 1.0d, "getAndSet double"); + assertEquals(1.0d, o, "getAndSet double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "getAndSet double value"); + assertEquals(2.0d, x, "getAndSet double value"); } { vh.set(1.0d); double o = (double) vh.getAndSetAcquire(2.0d); - assertEquals(o, 1.0d, "getAndSetAcquire double"); + assertEquals(1.0d, o, "getAndSetAcquire double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "getAndSetAcquire double value"); + assertEquals(2.0d, x, "getAndSetAcquire double value"); } { vh.set(1.0d); double o = (double) vh.getAndSetRelease(2.0d); - assertEquals(o, 1.0d, "getAndSetRelease double"); + assertEquals(1.0d, o, "getAndSetRelease double"); double x = (double) vh.get(); - assertEquals(x, 2.0d, "getAndSetRelease double value"); + assertEquals(2.0d, x, "getAndSetRelease double value"); } // get and add, add and get @@ -915,27 +913,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vh.set(1.0d); double o = (double) vh.getAndAdd(2.0d); - assertEquals(o, 1.0d, "getAndAdd double"); + assertEquals(1.0d, o, "getAndAdd double"); double x = (double) vh.get(); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value"); } { vh.set(1.0d); double o = (double) vh.getAndAddAcquire(2.0d); - assertEquals(o, 1.0d, "getAndAddAcquire double"); + assertEquals(1.0d, o, "getAndAddAcquire double"); double x = (double) vh.get(); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value"); } { vh.set(1.0d); double o = (double) vh.getAndAddRelease(2.0d); - assertEquals(o, 1.0d, "getAndAddReleasedouble"); + assertEquals(1.0d, o, "getAndAddReleasedouble"); double x = (double) vh.get(); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value"); } } @@ -989,7 +987,7 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { { vh.set(array, i, 1.0d); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "get double value"); + assertEquals(1.0d, x, "get double value"); } @@ -997,21 +995,21 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { { vh.setVolatile(array, i, 2.0d); double x = (double) vh.getVolatile(array, i); - assertEquals(x, 2.0d, "setVolatile double value"); + assertEquals(2.0d, x, "setVolatile double value"); } // Lazy { vh.setRelease(array, i, 1.0d); double x = (double) vh.getAcquire(array, i); - assertEquals(x, 1.0d, "setRelease double value"); + assertEquals(1.0d, x, "setRelease double value"); } // Opaque { vh.setOpaque(array, i, 2.0d); double x = (double) vh.getOpaque(array, i); - assertEquals(x, 2.0d, "setOpaque double value"); + assertEquals(2.0d, x, "setOpaque double value"); } vh.set(array, i, 1.0d); @@ -1021,56 +1019,56 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, 1.0d, 2.0d); assertEquals(r, true, "success compareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "success compareAndSet double value"); + assertEquals(2.0d, x, "success compareAndSet double value"); } { boolean r = vh.compareAndSet(array, i, 1.0d, 3.0d); assertEquals(r, false, "failing compareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "failing compareAndSet double value"); + assertEquals(2.0d, x, "failing compareAndSet double value"); } { double r = (double) vh.compareAndExchange(array, i, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchange double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "success compareAndExchange double value"); + assertEquals(1.0d, x, "success compareAndExchange double value"); } { double r = (double) vh.compareAndExchange(array, i, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchange double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "failing compareAndExchange double value"); + assertEquals(1.0d, x, "failing compareAndExchange double value"); } { double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 2.0d); assertEquals(r, 1.0d, "success compareAndExchangeAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "success compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeAcquire(array, i, 1.0d, 3.0d); assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchangeRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "success compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "success compareAndExchangeRelease double value"); } { double r = (double) vh.compareAndExchangeRelease(array, i, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchangeRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "failing compareAndExchangeRelease double value"); } { @@ -1081,14 +1079,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "success weakCompareAndSetPlain double value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value"); } { @@ -1099,14 +1097,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double"); + assertEquals(1.0d, x, "success weakCompareAndSetAcquire double"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -1117,14 +1115,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "success weakCompareAndSetRelease double"); + assertEquals(2.0d, x, "success weakCompareAndSetRelease double"); } { boolean success = vh.weakCompareAndSetRelease(array, i, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value"); } { @@ -1135,14 +1133,14 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "success weakCompareAndSet double"); + assertEquals(1.0d, x, "success weakCompareAndSet double"); } { boolean success = vh.weakCompareAndSet(array, i, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, 1.0d, "failing weakCompareAndSet double value"); + assertEquals(1.0d, x, "failing weakCompareAndSet double value"); } // Compare set and get @@ -1150,27 +1148,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vh.set(array, i, 1.0d); double o = (double) vh.getAndSet(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndSet double"); + assertEquals(1.0d, o, "getAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "getAndSet double value"); + assertEquals(2.0d, x, "getAndSet double value"); } { vh.set(array, i, 1.0d); double o = (double) vh.getAndSetAcquire(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndSetAcquire double"); + assertEquals(1.0d, o, "getAndSetAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "getAndSetAcquire double value"); + assertEquals(2.0d, x, "getAndSetAcquire double value"); } { vh.set(array, i, 1.0d); double o = (double) vh.getAndSetRelease(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndSetRelease double"); + assertEquals(1.0d, o, "getAndSetRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, 2.0d, "getAndSetRelease double value"); + assertEquals(2.0d, x, "getAndSetRelease double value"); } // get and add, add and get @@ -1178,27 +1176,27 @@ public class VarHandleTestAccessDouble extends VarHandleBaseTest { vh.set(array, i, 1.0d); double o = (double) vh.getAndAdd(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndAdd double"); + assertEquals(1.0d, o, "getAndAdd double"); double x = (double) vh.get(array, i); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value"); } { vh.set(array, i, 1.0d); double o = (double) vh.getAndAddAcquire(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndAddAcquire double"); + assertEquals(1.0d, o, "getAndAddAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value"); } { vh.set(array, i, 1.0d); double o = (double) vh.getAndAddRelease(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndAddReleasedouble"); + assertEquals(1.0d, o, "getAndAddReleasedouble"); double x = (double) vh.get(array, i); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value"); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java index c77a8d68008..750a1bbc408 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessFloat + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessFloat * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessFloat - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessFloat - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessFloat + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessFloat + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessFloat + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessFloat */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessFloat extends VarHandleBaseTest { static final float static_final_v = 1.0f; @@ -108,7 +110,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessFloat.class, "final_v", float.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(float[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessFloat.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), float.class); + assertEquals(float.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { // Plain { float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "get float value"); + assertEquals(1.0f, x, "get float value"); } // Volatile { float x = (float) vh.getVolatile(recv); - assertEquals(x, 1.0f, "getVolatile float value"); + assertEquals(1.0f, x, "getVolatile float value"); } // Lazy { float x = (float) vh.getAcquire(recv); - assertEquals(x, 1.0f, "getRelease float value"); + assertEquals(1.0f, x, "getRelease float value"); } // Opaque { float x = (float) vh.getOpaque(recv); - assertEquals(x, 1.0f, "getOpaque float value"); + assertEquals(1.0f, x, "getOpaque float value"); } } @@ -381,26 +379,26 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { // Plain { float x = (float) vh.get(); - assertEquals(x, 1.0f, "get float value"); + assertEquals(1.0f, x, "get float value"); } // Volatile { float x = (float) vh.getVolatile(); - assertEquals(x, 1.0f, "getVolatile float value"); + assertEquals(1.0f, x, "getVolatile float value"); } // Lazy { float x = (float) vh.getAcquire(); - assertEquals(x, 1.0f, "getRelease float value"); + assertEquals(1.0f, x, "getRelease float value"); } // Opaque { float x = (float) vh.getOpaque(); - assertEquals(x, 1.0f, "getOpaque float value"); + assertEquals(1.0f, x, "getOpaque float value"); } } @@ -466,7 +464,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { { vh.set(recv, 1.0f); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "set float value"); + assertEquals(1.0f, x, "set float value"); } @@ -474,21 +472,21 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { { vh.setVolatile(recv, 2.0f); float x = (float) vh.getVolatile(recv); - assertEquals(x, 2.0f, "setVolatile float value"); + assertEquals(2.0f, x, "setVolatile float value"); } // Lazy { vh.setRelease(recv, 1.0f); float x = (float) vh.getAcquire(recv); - assertEquals(x, 1.0f, "setRelease float value"); + assertEquals(1.0f, x, "setRelease float value"); } // Opaque { vh.setOpaque(recv, 2.0f); float x = (float) vh.getOpaque(recv); - assertEquals(x, 2.0f, "setOpaque float value"); + assertEquals(2.0f, x, "setOpaque float value"); } vh.set(recv, 1.0f); @@ -498,56 +496,56 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, 1.0f, 2.0f); assertEquals(r, true, "success compareAndSet float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "success compareAndSet float value"); + assertEquals(2.0f, x, "success compareAndSet float value"); } { boolean r = vh.compareAndSet(recv, 1.0f, 3.0f); assertEquals(r, false, "failing compareAndSet float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "failing compareAndSet float value"); + assertEquals(2.0f, x, "failing compareAndSet float value"); } { float r = (float) vh.compareAndExchange(recv, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchange float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "success compareAndExchange float value"); + assertEquals(1.0f, x, "success compareAndExchange float value"); } { float r = (float) vh.compareAndExchange(recv, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchange float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "failing compareAndExchange float value"); + assertEquals(1.0f, x, "failing compareAndExchange float value"); } { float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 2.0f); assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "success compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeAcquire(recv, 1.0f, 3.0f); assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "success compareAndExchangeRelease float value"); } { float r = (float) vh.compareAndExchangeRelease(recv, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "failing compareAndExchangeRelease float value"); } { @@ -558,14 +556,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "success weakCompareAndSetPlain float value"); } { boolean success = vh.weakCompareAndSetPlain(recv, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value"); } { @@ -576,14 +574,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float"); + assertEquals(1.0f, x, "success weakCompareAndSetAcquire float"); } { boolean success = vh.weakCompareAndSetAcquire(recv, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -594,14 +592,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "success weakCompareAndSetRelease float"); + assertEquals(2.0f, x, "success weakCompareAndSetRelease float"); } { boolean success = vh.weakCompareAndSetRelease(recv, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetRelease float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value"); } { @@ -612,14 +610,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "success weakCompareAndSet float value"); + assertEquals(1.0f, x, "success weakCompareAndSet float value"); } { boolean success = vh.weakCompareAndSet(recv, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) vh.get(recv); - assertEquals(x, 1.0f, "failing weakCompareAndSet float value"); + assertEquals(1.0f, x, "failing weakCompareAndSet float value"); } // Compare set and get @@ -627,27 +625,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vh.set(recv, 1.0f); float o = (float) vh.getAndSet(recv, 2.0f); - assertEquals(o, 1.0f, "getAndSet float"); + assertEquals(1.0f, o, "getAndSet float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "getAndSet float value"); + assertEquals(2.0f, x, "getAndSet float value"); } { vh.set(recv, 1.0f); float o = (float) vh.getAndSetAcquire(recv, 2.0f); - assertEquals(o, 1.0f, "getAndSetAcquire float"); + assertEquals(1.0f, o, "getAndSetAcquire float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "getAndSetAcquire float value"); + assertEquals(2.0f, x, "getAndSetAcquire float value"); } { vh.set(recv, 1.0f); float o = (float) vh.getAndSetRelease(recv, 2.0f); - assertEquals(o, 1.0f, "getAndSetRelease float"); + assertEquals(1.0f, o, "getAndSetRelease float"); float x = (float) vh.get(recv); - assertEquals(x, 2.0f, "getAndSetRelease float value"); + assertEquals(2.0f, x, "getAndSetRelease float value"); } // get and add, add and get @@ -655,27 +653,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vh.set(recv, 1.0f); float o = (float) vh.getAndAdd(recv, 2.0f); - assertEquals(o, 1.0f, "getAndAdd float"); + assertEquals(1.0f, o, "getAndAdd float"); float x = (float) vh.get(recv); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value"); } { vh.set(recv, 1.0f); float o = (float) vh.getAndAddAcquire(recv, 2.0f); - assertEquals(o, 1.0f, "getAndAddAcquire float"); + assertEquals(1.0f, o, "getAndAddAcquire float"); float x = (float) vh.get(recv); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value"); } { vh.set(recv, 1.0f); float o = (float) vh.getAndAddRelease(recv, 2.0f); - assertEquals(o, 1.0f, "getAndAddReleasefloat"); + assertEquals(1.0f, o, "getAndAddReleasefloat"); float x = (float) vh.get(recv); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value"); } } @@ -726,7 +724,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { { vh.set(1.0f); float x = (float) vh.get(); - assertEquals(x, 1.0f, "set float value"); + assertEquals(1.0f, x, "set float value"); } @@ -734,21 +732,21 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { { vh.setVolatile(2.0f); float x = (float) vh.getVolatile(); - assertEquals(x, 2.0f, "setVolatile float value"); + assertEquals(2.0f, x, "setVolatile float value"); } // Lazy { vh.setRelease(1.0f); float x = (float) vh.getAcquire(); - assertEquals(x, 1.0f, "setRelease float value"); + assertEquals(1.0f, x, "setRelease float value"); } // Opaque { vh.setOpaque(2.0f); float x = (float) vh.getOpaque(); - assertEquals(x, 2.0f, "setOpaque float value"); + assertEquals(2.0f, x, "setOpaque float value"); } vh.set(1.0f); @@ -758,56 +756,56 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { boolean r = vh.compareAndSet(1.0f, 2.0f); assertEquals(r, true, "success compareAndSet float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "success compareAndSet float value"); + assertEquals(2.0f, x, "success compareAndSet float value"); } { boolean r = vh.compareAndSet(1.0f, 3.0f); assertEquals(r, false, "failing compareAndSet float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "failing compareAndSet float value"); + assertEquals(2.0f, x, "failing compareAndSet float value"); } { float r = (float) vh.compareAndExchange(2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchange float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "success compareAndExchange float value"); + assertEquals(1.0f, x, "success compareAndExchange float value"); } { float r = (float) vh.compareAndExchange(2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchange float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "failing compareAndExchange float value"); + assertEquals(1.0f, x, "failing compareAndExchange float value"); } { float r = (float) vh.compareAndExchangeAcquire(1.0f, 2.0f); assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "success compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeAcquire(1.0f, 3.0f); assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeRelease(2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "success compareAndExchangeRelease float value"); } { float r = (float) vh.compareAndExchangeRelease(2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "failing compareAndExchangeRelease float value"); } { @@ -818,14 +816,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "success weakCompareAndSetPlain float value"); } { boolean success = vh.weakCompareAndSetPlain(1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value"); } { @@ -836,14 +834,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float"); + assertEquals(1.0f, x, "success weakCompareAndSetAcquire float"); } { boolean success = vh.weakCompareAndSetAcquire(2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -854,14 +852,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "success weakCompareAndSetRelease float"); + assertEquals(2.0f, x, "success weakCompareAndSetRelease float"); } { boolean success = vh.weakCompareAndSetRelease(1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetRelease float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value"); } { @@ -872,14 +870,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "success weakCompareAndSet float"); + assertEquals(1.0f, x, "success weakCompareAndSet float"); } { boolean success = vh.weakCompareAndSet(2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) vh.get(); - assertEquals(x, 1.0f, "failing weakCompareAndSet float value"); + assertEquals(1.0f, x, "failing weakCompareAndSet float value"); } // Compare set and get @@ -887,27 +885,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vh.set(1.0f); float o = (float) vh.getAndSet(2.0f); - assertEquals(o, 1.0f, "getAndSet float"); + assertEquals(1.0f, o, "getAndSet float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "getAndSet float value"); + assertEquals(2.0f, x, "getAndSet float value"); } { vh.set(1.0f); float o = (float) vh.getAndSetAcquire(2.0f); - assertEquals(o, 1.0f, "getAndSetAcquire float"); + assertEquals(1.0f, o, "getAndSetAcquire float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "getAndSetAcquire float value"); + assertEquals(2.0f, x, "getAndSetAcquire float value"); } { vh.set(1.0f); float o = (float) vh.getAndSetRelease(2.0f); - assertEquals(o, 1.0f, "getAndSetRelease float"); + assertEquals(1.0f, o, "getAndSetRelease float"); float x = (float) vh.get(); - assertEquals(x, 2.0f, "getAndSetRelease float value"); + assertEquals(2.0f, x, "getAndSetRelease float value"); } // get and add, add and get @@ -915,27 +913,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vh.set(1.0f); float o = (float) vh.getAndAdd(2.0f); - assertEquals(o, 1.0f, "getAndAdd float"); + assertEquals(1.0f, o, "getAndAdd float"); float x = (float) vh.get(); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value"); } { vh.set(1.0f); float o = (float) vh.getAndAddAcquire(2.0f); - assertEquals(o, 1.0f, "getAndAddAcquire float"); + assertEquals(1.0f, o, "getAndAddAcquire float"); float x = (float) vh.get(); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value"); } { vh.set(1.0f); float o = (float) vh.getAndAddRelease(2.0f); - assertEquals(o, 1.0f, "getAndAddReleasefloat"); + assertEquals(1.0f, o, "getAndAddReleasefloat"); float x = (float) vh.get(); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value"); } } @@ -989,7 +987,7 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { { vh.set(array, i, 1.0f); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "get float value"); + assertEquals(1.0f, x, "get float value"); } @@ -997,21 +995,21 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { { vh.setVolatile(array, i, 2.0f); float x = (float) vh.getVolatile(array, i); - assertEquals(x, 2.0f, "setVolatile float value"); + assertEquals(2.0f, x, "setVolatile float value"); } // Lazy { vh.setRelease(array, i, 1.0f); float x = (float) vh.getAcquire(array, i); - assertEquals(x, 1.0f, "setRelease float value"); + assertEquals(1.0f, x, "setRelease float value"); } // Opaque { vh.setOpaque(array, i, 2.0f); float x = (float) vh.getOpaque(array, i); - assertEquals(x, 2.0f, "setOpaque float value"); + assertEquals(2.0f, x, "setOpaque float value"); } vh.set(array, i, 1.0f); @@ -1021,56 +1019,56 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, 1.0f, 2.0f); assertEquals(r, true, "success compareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "success compareAndSet float value"); + assertEquals(2.0f, x, "success compareAndSet float value"); } { boolean r = vh.compareAndSet(array, i, 1.0f, 3.0f); assertEquals(r, false, "failing compareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "failing compareAndSet float value"); + assertEquals(2.0f, x, "failing compareAndSet float value"); } { float r = (float) vh.compareAndExchange(array, i, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchange float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "success compareAndExchange float value"); + assertEquals(1.0f, x, "success compareAndExchange float value"); } { float r = (float) vh.compareAndExchange(array, i, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchange float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "failing compareAndExchange float value"); + assertEquals(1.0f, x, "failing compareAndExchange float value"); } { float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 2.0f); assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "success compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeAcquire(array, i, 1.0f, 3.0f); assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "success compareAndExchangeRelease float value"); } { float r = (float) vh.compareAndExchangeRelease(array, i, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "failing compareAndExchangeRelease float value"); } { @@ -1081,14 +1079,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "success weakCompareAndSetPlain float value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value"); } { @@ -1099,14 +1097,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float"); + assertEquals(1.0f, x, "success weakCompareAndSetAcquire float"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -1117,14 +1115,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "success weakCompareAndSetRelease float"); + assertEquals(2.0f, x, "success weakCompareAndSetRelease float"); } { boolean success = vh.weakCompareAndSetRelease(array, i, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value"); } { @@ -1135,14 +1133,14 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "success weakCompareAndSet float"); + assertEquals(1.0f, x, "success weakCompareAndSet float"); } { boolean success = vh.weakCompareAndSet(array, i, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, 1.0f, "failing weakCompareAndSet float value"); + assertEquals(1.0f, x, "failing weakCompareAndSet float value"); } // Compare set and get @@ -1150,27 +1148,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vh.set(array, i, 1.0f); float o = (float) vh.getAndSet(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndSet float"); + assertEquals(1.0f, o, "getAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "getAndSet float value"); + assertEquals(2.0f, x, "getAndSet float value"); } { vh.set(array, i, 1.0f); float o = (float) vh.getAndSetAcquire(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndSetAcquire float"); + assertEquals(1.0f, o, "getAndSetAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "getAndSetAcquire float value"); + assertEquals(2.0f, x, "getAndSetAcquire float value"); } { vh.set(array, i, 1.0f); float o = (float) vh.getAndSetRelease(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndSetRelease float"); + assertEquals(1.0f, o, "getAndSetRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, 2.0f, "getAndSetRelease float value"); + assertEquals(2.0f, x, "getAndSetRelease float value"); } // get and add, add and get @@ -1178,27 +1176,27 @@ public class VarHandleTestAccessFloat extends VarHandleBaseTest { vh.set(array, i, 1.0f); float o = (float) vh.getAndAdd(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndAdd float"); + assertEquals(1.0f, o, "getAndAdd float"); float x = (float) vh.get(array, i); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value"); } { vh.set(array, i, 1.0f); float o = (float) vh.getAndAddAcquire(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndAddAcquire float"); + assertEquals(1.0f, o, "getAndAddAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value"); } { vh.set(array, i, 1.0f); float o = (float) vh.getAndAddRelease(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndAddReleasefloat"); + assertEquals(1.0f, o, "getAndAddReleasefloat"); float x = (float) vh.get(array, i); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value"); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java index d5dfaa4e1c6..4748d699555 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessInt + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessInt * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessInt - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessInt - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessInt + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessInt + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessInt + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessInt */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessInt extends VarHandleBaseTest { static final int static_final_v = 0x01234567; @@ -108,7 +110,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessInt.class, "final_v", int.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(int[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessInt.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), int.class); + assertEquals(int.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { // Plain { int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "get int value"); + assertEquals(0x01234567, x, "get int value"); } // Volatile { int x = (int) vh.getVolatile(recv); - assertEquals(x, 0x01234567, "getVolatile int value"); + assertEquals(0x01234567, x, "getVolatile int value"); } // Lazy { int x = (int) vh.getAcquire(recv); - assertEquals(x, 0x01234567, "getRelease int value"); + assertEquals(0x01234567, x, "getRelease int value"); } // Opaque { int x = (int) vh.getOpaque(recv); - assertEquals(x, 0x01234567, "getOpaque int value"); + assertEquals(0x01234567, x, "getOpaque int value"); } } @@ -346,26 +344,26 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { // Plain { int x = (int) vh.get(); - assertEquals(x, 0x01234567, "get int value"); + assertEquals(0x01234567, x, "get int value"); } // Volatile { int x = (int) vh.getVolatile(); - assertEquals(x, 0x01234567, "getVolatile int value"); + assertEquals(0x01234567, x, "getVolatile int value"); } // Lazy { int x = (int) vh.getAcquire(); - assertEquals(x, 0x01234567, "getRelease int value"); + assertEquals(0x01234567, x, "getRelease int value"); } // Opaque { int x = (int) vh.getOpaque(); - assertEquals(x, 0x01234567, "getOpaque int value"); + assertEquals(0x01234567, x, "getOpaque int value"); } } @@ -396,7 +394,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { { vh.set(recv, 0x01234567); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "set int value"); + assertEquals(0x01234567, x, "set int value"); } @@ -404,21 +402,21 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { { vh.setVolatile(recv, 0x89ABCDEF); int x = (int) vh.getVolatile(recv); - assertEquals(x, 0x89ABCDEF, "setVolatile int value"); + assertEquals(0x89ABCDEF, x, "setVolatile int value"); } // Lazy { vh.setRelease(recv, 0x01234567); int x = (int) vh.getAcquire(recv); - assertEquals(x, 0x01234567, "setRelease int value"); + assertEquals(0x01234567, x, "setRelease int value"); } // Opaque { vh.setOpaque(recv, 0x89ABCDEF); int x = (int) vh.getOpaque(recv); - assertEquals(x, 0x89ABCDEF, "setOpaque int value"); + assertEquals(0x89ABCDEF, x, "setOpaque int value"); } vh.set(recv, 0x01234567); @@ -428,56 +426,56 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, 0x01234567, 0x89ABCDEF); assertEquals(r, true, "success compareAndSet int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "success compareAndSet int value"); } { boolean r = vh.compareAndSet(recv, 0x01234567, 0xCAFEBABE); assertEquals(r, false, "failing compareAndSet int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndSet int value"); } { int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "success compareAndExchange int value"); + assertEquals(0x01234567, x, "success compareAndExchange int value"); } { int r = (int) vh.compareAndExchange(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchange int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "failing compareAndExchange int value"); + assertEquals(0x01234567, x, "failing compareAndExchange int value"); } { int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0x89ABCDEF); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "success compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeAcquire(recv, 0x01234567, 0xCAFEBABE); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "success compareAndExchangeRelease int value"); } { int r = (int) vh.compareAndExchangeRelease(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "failing compareAndExchangeRelease int value"); } { @@ -488,14 +486,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetPlain int value"); } { boolean success = vh.weakCompareAndSetPlain(recv, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetPlain int value"); } { @@ -506,14 +504,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "success weakCompareAndSetAcquire int"); + assertEquals(0x01234567, x, "success weakCompareAndSetAcquire int"); } { boolean success = vh.weakCompareAndSetAcquire(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetAcquire int value"); } { @@ -524,14 +522,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetRelease int"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetRelease int"); } { boolean success = vh.weakCompareAndSetRelease(recv, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetRelease int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetRelease int value"); } { @@ -542,14 +540,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "success weakCompareAndSet int value"); + assertEquals(0x01234567, x, "success weakCompareAndSet int value"); } { boolean success = vh.weakCompareAndSet(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) vh.get(recv); - assertEquals(x, 0x01234567, "failing weakCompareAndSet int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSet int value"); } // Compare set and get @@ -557,27 +555,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(recv, 0x01234567); int o = (int) vh.getAndSet(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSet int"); + assertEquals(0x01234567, o, "getAndSet int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "getAndSet int value"); + assertEquals(0x89ABCDEF, x, "getAndSet int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndSetAcquire(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetAcquire int"); + assertEquals(0x01234567, o, "getAndSetAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); + assertEquals(0x89ABCDEF, x, "getAndSetAcquire int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndSetRelease(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetRelease int"); + assertEquals(0x01234567, o, "getAndSetRelease int"); int x = (int) vh.get(recv); - assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "getAndSetRelease int value"); } // get and add, add and get @@ -585,27 +583,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(recv, 0x01234567); int o = (int) vh.getAndAdd(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAdd int"); + assertEquals(0x01234567, o, "getAndAdd int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAdd int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndAddAcquire(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddAcquire int"); + assertEquals(0x01234567, o, "getAndAddAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddAcquire int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndAddRelease(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddReleaseint"); + assertEquals(0x01234567, o, "getAndAddReleaseint"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddRelease int value"); } // get and bitwise or @@ -613,27 +611,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseOr(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOr int"); + assertEquals(0x01234567, o, "getAndBitwiseOr int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOr int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseOrAcquire(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseOrAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrAcquire int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseOrRelease(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseOrRelease int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -641,27 +639,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseAnd(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); + assertEquals(0x01234567, o, "getAndBitwiseAnd int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAnd int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseAndAcquire(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseAndAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndAcquire int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseAndRelease(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseAndRelease int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -669,27 +667,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseXor(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXor int"); + assertEquals(0x01234567, o, "getAndBitwiseXor int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXor int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseXorAcquire(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseXorAcquire int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorAcquire int value"); } { vh.set(recv, 0x01234567); int o = (int) vh.getAndBitwiseXorRelease(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseXorRelease int"); int x = (int) vh.get(recv); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorRelease int value"); } } @@ -704,7 +702,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { { vh.set(0x01234567); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "set int value"); + assertEquals(0x01234567, x, "set int value"); } @@ -712,21 +710,21 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { { vh.setVolatile(0x89ABCDEF); int x = (int) vh.getVolatile(); - assertEquals(x, 0x89ABCDEF, "setVolatile int value"); + assertEquals(0x89ABCDEF, x, "setVolatile int value"); } // Lazy { vh.setRelease(0x01234567); int x = (int) vh.getAcquire(); - assertEquals(x, 0x01234567, "setRelease int value"); + assertEquals(0x01234567, x, "setRelease int value"); } // Opaque { vh.setOpaque(0x89ABCDEF); int x = (int) vh.getOpaque(); - assertEquals(x, 0x89ABCDEF, "setOpaque int value"); + assertEquals(0x89ABCDEF, x, "setOpaque int value"); } vh.set(0x01234567); @@ -736,56 +734,56 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { boolean r = vh.compareAndSet(0x01234567, 0x89ABCDEF); assertEquals(r, true, "success compareAndSet int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "success compareAndSet int value"); } { boolean r = vh.compareAndSet(0x01234567, 0xCAFEBABE); assertEquals(r, false, "failing compareAndSet int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndSet int value"); } { int r = (int) vh.compareAndExchange(0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "success compareAndExchange int value"); + assertEquals(0x01234567, x, "success compareAndExchange int value"); } { int r = (int) vh.compareAndExchange(0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchange int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "failing compareAndExchange int value"); + assertEquals(0x01234567, x, "failing compareAndExchange int value"); } { int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0x89ABCDEF); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "success compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeAcquire(0x01234567, 0xCAFEBABE); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "success compareAndExchangeRelease int value"); } { int r = (int) vh.compareAndExchangeRelease(0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "failing compareAndExchangeRelease int value"); } { @@ -796,14 +794,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetPlain int value"); } { boolean success = vh.weakCompareAndSetPlain(0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetPlain int value"); } { @@ -814,14 +812,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "success weakCompareAndSetAcquire int"); + assertEquals(0x01234567, x, "success weakCompareAndSetAcquire int"); } { boolean success = vh.weakCompareAndSetAcquire(0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetAcquire int value"); } { @@ -832,14 +830,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetRelease int"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetRelease int"); } { boolean success = vh.weakCompareAndSetRelease(0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetRelease int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetRelease int value"); } { @@ -850,14 +848,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "success weakCompareAndSet int"); + assertEquals(0x01234567, x, "success weakCompareAndSet int"); } { boolean success = vh.weakCompareAndSet(0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) vh.get(); - assertEquals(x, 0x01234567, "failing weakCompareAndSet int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSet int value"); } // Compare set and get @@ -865,27 +863,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(0x01234567); int o = (int) vh.getAndSet(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSet int"); + assertEquals(0x01234567, o, "getAndSet int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "getAndSet int value"); + assertEquals(0x89ABCDEF, x, "getAndSet int value"); } { vh.set(0x01234567); int o = (int) vh.getAndSetAcquire(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetAcquire int"); + assertEquals(0x01234567, o, "getAndSetAcquire int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); + assertEquals(0x89ABCDEF, x, "getAndSetAcquire int value"); } { vh.set(0x01234567); int o = (int) vh.getAndSetRelease(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetRelease int"); + assertEquals(0x01234567, o, "getAndSetRelease int"); int x = (int) vh.get(); - assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "getAndSetRelease int value"); } // get and add, add and get @@ -893,27 +891,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(0x01234567); int o = (int) vh.getAndAdd(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAdd int"); + assertEquals(0x01234567, o, "getAndAdd int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAdd int value"); } { vh.set(0x01234567); int o = (int) vh.getAndAddAcquire(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddAcquire int"); + assertEquals(0x01234567, o, "getAndAddAcquire int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddAcquire int value"); } { vh.set(0x01234567); int o = (int) vh.getAndAddRelease(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddReleaseint"); + assertEquals(0x01234567, o, "getAndAddReleaseint"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddRelease int value"); } // get and bitwise or @@ -921,27 +919,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(0x01234567); int o = (int) vh.getAndBitwiseOr(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOr int"); + assertEquals(0x01234567, o, "getAndBitwiseOr int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOr int value"); } { vh.set(0x01234567); int o = (int) vh.getAndBitwiseOrAcquire(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseOrAcquire int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrAcquire int value"); } { vh.set(0x01234567); int o = (int) vh.getAndBitwiseOrRelease(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseOrRelease int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -949,27 +947,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(0x01234567); int o = (int) vh.getAndBitwiseAnd(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); + assertEquals(0x01234567, o, "getAndBitwiseAnd int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAnd int value"); } { vh.set(0x01234567); int o = (int) vh.getAndBitwiseAndAcquire(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseAndAcquire int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndAcquire int value"); } { vh.set(0x01234567); int o = (int) vh.getAndBitwiseAndRelease(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseAndRelease int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -977,27 +975,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(0x01234567); int o = (int) vh.getAndBitwiseXor(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXor int"); + assertEquals(0x01234567, o, "getAndBitwiseXor int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXor int value"); } { vh.set(0x01234567); int o = (int) vh.getAndBitwiseXorAcquire(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseXorAcquire int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorAcquire int value"); } { vh.set(0x01234567); int o = (int) vh.getAndBitwiseXorRelease(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseXorRelease int"); int x = (int) vh.get(); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorRelease int value"); } } @@ -1015,7 +1013,7 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { { vh.set(array, i, 0x01234567); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "get int value"); + assertEquals(0x01234567, x, "get int value"); } @@ -1023,21 +1021,21 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { { vh.setVolatile(array, i, 0x89ABCDEF); int x = (int) vh.getVolatile(array, i); - assertEquals(x, 0x89ABCDEF, "setVolatile int value"); + assertEquals(0x89ABCDEF, x, "setVolatile int value"); } // Lazy { vh.setRelease(array, i, 0x01234567); int x = (int) vh.getAcquire(array, i); - assertEquals(x, 0x01234567, "setRelease int value"); + assertEquals(0x01234567, x, "setRelease int value"); } // Opaque { vh.setOpaque(array, i, 0x89ABCDEF); int x = (int) vh.getOpaque(array, i); - assertEquals(x, 0x89ABCDEF, "setOpaque int value"); + assertEquals(0x89ABCDEF, x, "setOpaque int value"); } vh.set(array, i, 0x01234567); @@ -1047,56 +1045,56 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, 0x01234567, 0x89ABCDEF); assertEquals(r, true, "success compareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "success compareAndSet int value"); } { boolean r = vh.compareAndSet(array, i, 0x01234567, 0xCAFEBABE); assertEquals(r, false, "failing compareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndSet int value"); } { int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "success compareAndExchange int value"); + assertEquals(0x01234567, x, "success compareAndExchange int value"); } { int r = (int) vh.compareAndExchange(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchange int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "failing compareAndExchange int value"); + assertEquals(0x01234567, x, "failing compareAndExchange int value"); } { int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0x89ABCDEF); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "success compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeAcquire(array, i, 0x01234567, 0xCAFEBABE); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "success compareAndExchangeRelease int value"); } { int r = (int) vh.compareAndExchangeRelease(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "failing compareAndExchangeRelease int value"); } { @@ -1107,14 +1105,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetPlain int value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetPlain int value"); } { @@ -1125,14 +1123,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "success weakCompareAndSetAcquire int"); + assertEquals(0x01234567, x, "success weakCompareAndSetAcquire int"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetAcquire int value"); } { @@ -1143,14 +1141,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetRelease int"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetRelease int"); } { boolean success = vh.weakCompareAndSetRelease(array, i, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetRelease int value"); } { @@ -1161,14 +1159,14 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "success weakCompareAndSet int"); + assertEquals(0x01234567, x, "success weakCompareAndSet int"); } { boolean success = vh.weakCompareAndSet(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x01234567, "failing weakCompareAndSet int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSet int value"); } // Compare set and get @@ -1176,27 +1174,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(array, i, 0x01234567); int o = (int) vh.getAndSet(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSet int"); + assertEquals(0x01234567, o, "getAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "getAndSet int value"); + assertEquals(0x89ABCDEF, x, "getAndSet int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndSetAcquire(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetAcquire int"); + assertEquals(0x01234567, o, "getAndSetAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); + assertEquals(0x89ABCDEF, x, "getAndSetAcquire int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndSetRelease(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetRelease int"); + assertEquals(0x01234567, o, "getAndSetRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "getAndSetRelease int value"); } // get and add, add and get @@ -1204,27 +1202,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(array, i, 0x01234567); int o = (int) vh.getAndAdd(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAdd int"); + assertEquals(0x01234567, o, "getAndAdd int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAdd int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndAddAcquire(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddAcquire int"); + assertEquals(0x01234567, o, "getAndAddAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddAcquire int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndAddRelease(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddReleaseint"); + assertEquals(0x01234567, o, "getAndAddReleaseint"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddRelease int value"); } // get and bitwise or @@ -1232,27 +1230,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseOr(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOr int"); + assertEquals(0x01234567, o, "getAndBitwiseOr int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOr int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseOrAcquire(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseOrAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrAcquire int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseOrRelease(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseOrRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -1260,27 +1258,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseAnd(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); + assertEquals(0x01234567, o, "getAndBitwiseAnd int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAnd int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseAndAcquire(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseAndAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndAcquire int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseAndRelease(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseAndRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -1288,27 +1286,27 @@ public class VarHandleTestAccessInt extends VarHandleBaseTest { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseXor(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXor int"); + assertEquals(0x01234567, o, "getAndBitwiseXor int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXor int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseXorAcquire(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseXorAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorAcquire int value"); } { vh.set(array, i, 0x01234567); int o = (int) vh.getAndBitwiseXorRelease(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseXorRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorRelease int value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java index e40256a8bd5..8bf997bb9a6 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessLong + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessLong * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessLong - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessLong - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessLong + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessLong + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessLong + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessLong */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessLong extends VarHandleBaseTest { static final long static_final_v = 0x0123456789ABCDEFL; @@ -108,7 +110,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessLong.class, "final_v", long.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(long[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessLong.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), long.class); + assertEquals(long.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { // Plain { long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "get long value"); + assertEquals(0x0123456789ABCDEFL, x, "get long value"); } // Volatile { long x = (long) vh.getVolatile(recv); - assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value"); + assertEquals(0x0123456789ABCDEFL, x, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(recv); - assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(recv); - assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value"); + assertEquals(0x0123456789ABCDEFL, x, "getOpaque long value"); } } @@ -346,26 +344,26 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { // Plain { long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "get long value"); + assertEquals(0x0123456789ABCDEFL, x, "get long value"); } // Volatile { long x = (long) vh.getVolatile(); - assertEquals(x, 0x0123456789ABCDEFL, "getVolatile long value"); + assertEquals(0x0123456789ABCDEFL, x, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(); - assertEquals(x, 0x0123456789ABCDEFL, "getRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(); - assertEquals(x, 0x0123456789ABCDEFL, "getOpaque long value"); + assertEquals(0x0123456789ABCDEFL, x, "getOpaque long value"); } } @@ -396,7 +394,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { { vh.set(recv, 0x0123456789ABCDEFL); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "set long value"); + assertEquals(0x0123456789ABCDEFL, x, "set long value"); } @@ -404,21 +402,21 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { { vh.setVolatile(recv, 0xCAFEBABECAFEBABEL); long x = (long) vh.getVolatile(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setVolatile long value"); } // Lazy { vh.setRelease(recv, 0x0123456789ABCDEFL); long x = (long) vh.getAcquire(recv); - assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "setRelease long value"); } // Opaque { vh.setOpaque(recv, 0xCAFEBABECAFEBABEL); long x = (long) vh.getOpaque(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setOpaque long value"); } vh.set(recv, 0x0123456789ABCDEFL); @@ -428,56 +426,56 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndSet long value"); } { boolean r = vh.compareAndSet(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndSet long value"); } { long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchange long value"); } { long r = (long) vh.compareAndExchange(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchange long value"); } { long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeAcquire(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchangeRelease long value"); } { long r = (long) vh.compareAndExchangeRelease(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchangeRelease long value"); } { @@ -488,14 +486,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetPlain long value"); } { boolean success = vh.weakCompareAndSetPlain(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetPlain long value"); } { @@ -506,14 +504,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSetAcquire long"); } { boolean success = vh.weakCompareAndSetAcquire(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -524,14 +522,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetRelease long"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetRelease long"); } { boolean success = vh.weakCompareAndSetRelease(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetRelease long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetRelease long value"); } { @@ -542,14 +540,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSet long value"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSet long value"); } { boolean success = vh.weakCompareAndSet(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) vh.get(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSet long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSet long value"); } // Compare set and get @@ -557,27 +555,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndSet(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSet long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSet long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndSetAcquire(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetAcquire long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndSetRelease(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetRelease long"); long x = (long) vh.get(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetRelease long value"); } // get and add, add and get @@ -585,27 +583,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndAdd(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAdd long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAdd long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndAddAcquire(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddAcquire long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndAddRelease(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddReleaselong"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddRelease long value"); } // get and bitwise or @@ -613,27 +611,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOr(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOr long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOr long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOrAcquire(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrAcquire long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOrRelease(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrRelease long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -641,27 +639,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAnd(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAnd long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAnd long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAndAcquire(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndAcquire long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAndRelease(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndRelease long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -669,27 +667,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXor(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXor long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXor long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXorAcquire(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorAcquire long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorAcquire long value"); } { vh.set(recv, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXorRelease(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorRelease long"); long x = (long) vh.get(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorRelease long value"); } } @@ -704,7 +702,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { { vh.set(0x0123456789ABCDEFL); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "set long value"); + assertEquals(0x0123456789ABCDEFL, x, "set long value"); } @@ -712,21 +710,21 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { { vh.setVolatile(0xCAFEBABECAFEBABEL); long x = (long) vh.getVolatile(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setVolatile long value"); } // Lazy { vh.setRelease(0x0123456789ABCDEFL); long x = (long) vh.getAcquire(); - assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "setRelease long value"); } // Opaque { vh.setOpaque(0xCAFEBABECAFEBABEL); long x = (long) vh.getOpaque(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setOpaque long value"); } vh.set(0x0123456789ABCDEFL); @@ -736,56 +734,56 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndSet long value"); } { boolean r = vh.compareAndSet(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndSet long value"); } { long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchange long value"); } { long r = (long) vh.compareAndExchange(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchange long value"); } { long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeAcquire(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchangeRelease long value"); } { long r = (long) vh.compareAndExchangeRelease(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchangeRelease long value"); } { @@ -796,14 +794,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetPlain long value"); } { boolean success = vh.weakCompareAndSetPlain(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetPlain long value"); } { @@ -814,14 +812,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSetAcquire long"); } { boolean success = vh.weakCompareAndSetAcquire(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -832,14 +830,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetRelease long"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetRelease long"); } { boolean success = vh.weakCompareAndSetRelease(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetRelease long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetRelease long value"); } { @@ -850,14 +848,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSet long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSet long"); } { boolean success = vh.weakCompareAndSet(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) vh.get(); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSet long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSet long value"); } // Compare set and get @@ -865,27 +863,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndSet(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSet long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSet long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndSetAcquire(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetAcquire long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetAcquire long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndSetRelease(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetRelease long"); long x = (long) vh.get(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetRelease long value"); } // get and add, add and get @@ -893,27 +891,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndAdd(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAdd long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAdd long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndAddAcquire(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddAcquire long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddAcquire long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndAddRelease(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddReleaselong"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddRelease long value"); } // get and bitwise or @@ -921,27 +919,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOr(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOr long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOr long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOrAcquire(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrAcquire long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrAcquire long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOrRelease(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrRelease long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -949,27 +947,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAnd(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAnd long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAnd long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAndAcquire(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndAcquire long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndAcquire long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAndRelease(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndRelease long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -977,27 +975,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXor(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXor long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXor long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXorAcquire(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorAcquire long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorAcquire long value"); } { vh.set(0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXorRelease(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorRelease long"); long x = (long) vh.get(); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorRelease long value"); } } @@ -1015,7 +1013,7 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { { vh.set(array, i, 0x0123456789ABCDEFL); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "get long value"); + assertEquals(0x0123456789ABCDEFL, x, "get long value"); } @@ -1023,21 +1021,21 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { { vh.setVolatile(array, i, 0xCAFEBABECAFEBABEL); long x = (long) vh.getVolatile(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setVolatile long value"); } // Lazy { vh.setRelease(array, i, 0x0123456789ABCDEFL); long x = (long) vh.getAcquire(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "setRelease long value"); } // Opaque { vh.setOpaque(array, i, 0xCAFEBABECAFEBABEL); long x = (long) vh.getOpaque(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setOpaque long value"); } vh.set(array, i, 0x0123456789ABCDEFL); @@ -1047,56 +1045,56 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndSet long value"); } { boolean r = vh.compareAndSet(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndSet long value"); } { long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchange long value"); } { long r = (long) vh.compareAndExchange(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchange long value"); } { long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeAcquire(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchangeRelease long value"); } { long r = (long) vh.compareAndExchangeRelease(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchangeRelease long value"); } { @@ -1107,14 +1105,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetPlain long value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetPlain long value"); } { @@ -1125,14 +1123,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSetAcquire long"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -1143,14 +1141,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetRelease long"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetRelease long"); } { boolean success = vh.weakCompareAndSetRelease(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetRelease long value"); } { @@ -1161,14 +1159,14 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSet long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSet long"); } { boolean success = vh.weakCompareAndSet(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSet long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSet long value"); } // Compare set and get @@ -1176,27 +1174,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndSet(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSet long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndSetAcquire(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetAcquire long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndSetRelease(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetRelease long value"); } // get and add, add and get @@ -1204,27 +1202,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndAdd(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAdd long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAdd long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndAddAcquire(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddAcquire long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndAddRelease(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddReleaselong"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddReleaselong"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddRelease long value"); } // get and bitwise or @@ -1232,27 +1230,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOr(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOr long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOr long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOrAcquire(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrAcquire long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseOrRelease(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -1260,27 +1258,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAnd(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAnd long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAnd long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAndAcquire(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndAcquire long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseAndRelease(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -1288,27 +1286,27 @@ public class VarHandleTestAccessLong extends VarHandleBaseTest { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXor(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXor long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXor long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXorAcquire(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorAcquire long value"); } { vh.set(array, i, 0x0123456789ABCDEFL); long o = (long) vh.getAndBitwiseXorRelease(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorRelease long value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java index 3365bd923bc..61fc8a53fd0 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessModeMethodNames.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, 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 @@ -23,32 +23,34 @@ /* * @test - * @run testng VarHandleTestAccessModeMethodNames + * @run junit VarHandleTestAccessModeMethodNames * @modules java.base/java.lang.invoke:open */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.VarHandle; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.stream.Stream; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessModeMethodNames { - @DataProvider public static Object[][] accessModesProvider() { return Stream.of(VarHandle.AccessMode.values()). map(am -> new Object[]{am}). toArray(Object[][]::new); } - @Test(dataProvider = "accessModesProvider") + @ParameterizedTest + @MethodSource("accessModesProvider") public void testMethodName(VarHandle.AccessMode am) { - assertEquals(am.methodName(), toMethodName(am.name())); + assertEquals(toMethodName(am.name()), am.methodName()); } private static String toMethodName(String name) { @@ -62,9 +64,10 @@ public class VarHandleTestAccessModeMethodNames { } - @Test(dataProvider = "accessModesProvider") + @ParameterizedTest + @MethodSource("accessModesProvider") public void testReturnType(VarHandle.AccessMode am) throws Exception { - assertEquals(getReturnType(am.methodName()), getAccessModeReturnType(am)); + assertEquals(getAccessModeReturnType(am), getReturnType(am.methodName())); } private static Class getReturnType(String name) throws Exception { diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java index b9daf4880a0..552672c7372 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessShort + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessShort * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessShort - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessShort - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessShort + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessShort + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessShort + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessShort */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessShort extends VarHandleBaseTest { static final short static_final_v = (short)0x0123; @@ -108,7 +110,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessShort.class, "final_v", short.class); @@ -125,8 +127,6 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(short[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -156,7 +156,8 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -194,8 +195,6 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessShort.class)}); @@ -205,16 +204,16 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), short.class); + assertEquals(short.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -241,8 +240,6 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -284,7 +281,8 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -297,26 +295,26 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { // Plain { short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "get short value"); + assertEquals((short)0x0123, x, "get short value"); } // Volatile { short x = (short) vh.getVolatile(recv); - assertEquals(x, (short)0x0123, "getVolatile short value"); + assertEquals((short)0x0123, x, "getVolatile short value"); } // Lazy { short x = (short) vh.getAcquire(recv); - assertEquals(x, (short)0x0123, "getRelease short value"); + assertEquals((short)0x0123, x, "getRelease short value"); } // Opaque { short x = (short) vh.getOpaque(recv); - assertEquals(x, (short)0x0123, "getOpaque short value"); + assertEquals((short)0x0123, x, "getOpaque short value"); } } @@ -346,26 +344,26 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { // Plain { short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "get short value"); + assertEquals((short)0x0123, x, "get short value"); } // Volatile { short x = (short) vh.getVolatile(); - assertEquals(x, (short)0x0123, "getVolatile short value"); + assertEquals((short)0x0123, x, "getVolatile short value"); } // Lazy { short x = (short) vh.getAcquire(); - assertEquals(x, (short)0x0123, "getRelease short value"); + assertEquals((short)0x0123, x, "getRelease short value"); } // Opaque { short x = (short) vh.getOpaque(); - assertEquals(x, (short)0x0123, "getOpaque short value"); + assertEquals((short)0x0123, x, "getOpaque short value"); } } @@ -396,7 +394,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { { vh.set(recv, (short)0x0123); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "set short value"); + assertEquals((short)0x0123, x, "set short value"); } @@ -404,21 +402,21 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { { vh.setVolatile(recv, (short)0x4567); short x = (short) vh.getVolatile(recv); - assertEquals(x, (short)0x4567, "setVolatile short value"); + assertEquals((short)0x4567, x, "setVolatile short value"); } // Lazy { vh.setRelease(recv, (short)0x0123); short x = (short) vh.getAcquire(recv); - assertEquals(x, (short)0x0123, "setRelease short value"); + assertEquals((short)0x0123, x, "setRelease short value"); } // Opaque { vh.setOpaque(recv, (short)0x4567); short x = (short) vh.getOpaque(recv); - assertEquals(x, (short)0x4567, "setOpaque short value"); + assertEquals((short)0x4567, x, "setOpaque short value"); } vh.set(recv, (short)0x0123); @@ -428,56 +426,56 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x4567); assertEquals(r, true, "success compareAndSet short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "success compareAndSet short value"); + assertEquals((short)0x4567, x, "success compareAndSet short value"); } { boolean r = vh.compareAndSet(recv, (short)0x0123, (short)0x89AB); assertEquals(r, false, "failing compareAndSet short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "failing compareAndSet short value"); + assertEquals((short)0x4567, x, "failing compareAndSet short value"); } { short r = (short) vh.compareAndExchange(recv, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchange short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "success compareAndExchange short value"); + assertEquals((short)0x0123, x, "success compareAndExchange short value"); } { short r = (short) vh.compareAndExchange(recv, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchange short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); + assertEquals((short)0x0123, x, "failing compareAndExchange short value"); } { short r = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x4567); assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "success compareAndExchangeAcquire short value"); } { short r = (short) vh.compareAndExchangeAcquire(recv, (short)0x0123, (short)0x89AB); assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "failing compareAndExchangeAcquire short value"); } { short r = (short) vh.compareAndExchangeRelease(recv, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "success compareAndExchangeRelease short value"); } { short r = (short) vh.compareAndExchangeRelease(recv, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "failing compareAndExchangeRelease short value"); } { @@ -488,14 +486,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "success weakCompareAndSetPlain short value"); } { boolean success = vh.weakCompareAndSetPlain(recv, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetPlain short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetPlain short value"); } { @@ -506,14 +504,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); + assertEquals((short)0x0123, x, "success weakCompareAndSetAcquire short"); } { boolean success = vh.weakCompareAndSetAcquire(recv, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetAcquire short value"); } { @@ -524,14 +522,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); + assertEquals((short)0x4567, x, "success weakCompareAndSetRelease short"); } { boolean success = vh.weakCompareAndSetRelease(recv, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetRelease short value"); } { @@ -542,14 +540,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "success weakCompareAndSet short value"); + assertEquals((short)0x0123, x, "success weakCompareAndSet short value"); } { boolean success = vh.weakCompareAndSet(recv, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSet short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSet short value"); } // Compare set and get @@ -557,27 +555,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(recv, (short)0x0123); short o = (short) vh.getAndSet(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSet short"); + assertEquals((short)0x0123, o, "getAndSet short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "getAndSet short value"); + assertEquals((short)0x4567, x, "getAndSet short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndSetAcquire(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetAcquire short"); + assertEquals((short)0x0123, o, "getAndSetAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); + assertEquals((short)0x4567, x, "getAndSetAcquire short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndSetRelease(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetRelease short"); + assertEquals((short)0x0123, o, "getAndSetRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)0x4567, "getAndSetRelease short value"); + assertEquals((short)0x4567, x, "getAndSetRelease short value"); } // get and add, add and get @@ -585,27 +583,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(recv, (short)0x0123); short o = (short) vh.getAndAdd(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAdd short"); + assertEquals((short)0x0123, o, "getAndAdd short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAdd short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndAddAcquire(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddAcquire short"); + assertEquals((short)0x0123, o, "getAndAddAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddAcquire short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndAddRelease(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddReleaseshort"); + assertEquals((short)0x0123, o, "getAndAddReleaseshort"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddRelease short value"); } // get and bitwise or @@ -613,27 +611,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseOr(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); + assertEquals((short)0x0123, o, "getAndBitwiseOr short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOr short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseOrAcquire(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrAcquire short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseOrRelease(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrRelease short value"); } // get and bitwise and @@ -641,27 +639,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseAnd(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); + assertEquals((short)0x0123, o, "getAndBitwiseAnd short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAnd short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseAndAcquire(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndAcquire short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseAndRelease(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndRelease short value"); } // get and bitwise xor @@ -669,27 +667,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseXor(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); + assertEquals((short)0x0123, o, "getAndBitwiseXor short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXor short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseXorAcquire(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorAcquire short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorAcquire short value"); } { vh.set(recv, (short)0x0123); short o = (short) vh.getAndBitwiseXorRelease(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorRelease short"); short x = (short) vh.get(recv); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorRelease short value"); } } @@ -704,7 +702,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { { vh.set((short)0x0123); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "set short value"); + assertEquals((short)0x0123, x, "set short value"); } @@ -712,21 +710,21 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { { vh.setVolatile((short)0x4567); short x = (short) vh.getVolatile(); - assertEquals(x, (short)0x4567, "setVolatile short value"); + assertEquals((short)0x4567, x, "setVolatile short value"); } // Lazy { vh.setRelease((short)0x0123); short x = (short) vh.getAcquire(); - assertEquals(x, (short)0x0123, "setRelease short value"); + assertEquals((short)0x0123, x, "setRelease short value"); } // Opaque { vh.setOpaque((short)0x4567); short x = (short) vh.getOpaque(); - assertEquals(x, (short)0x4567, "setOpaque short value"); + assertEquals((short)0x4567, x, "setOpaque short value"); } vh.set((short)0x0123); @@ -736,56 +734,56 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { boolean r = vh.compareAndSet((short)0x0123, (short)0x4567); assertEquals(r, true, "success compareAndSet short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "success compareAndSet short value"); + assertEquals((short)0x4567, x, "success compareAndSet short value"); } { boolean r = vh.compareAndSet((short)0x0123, (short)0x89AB); assertEquals(r, false, "failing compareAndSet short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "failing compareAndSet short value"); + assertEquals((short)0x4567, x, "failing compareAndSet short value"); } { short r = (short) vh.compareAndExchange((short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchange short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "success compareAndExchange short value"); + assertEquals((short)0x0123, x, "success compareAndExchange short value"); } { short r = (short) vh.compareAndExchange((short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchange short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); + assertEquals((short)0x0123, x, "failing compareAndExchange short value"); } { short r = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x4567); assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "success compareAndExchangeAcquire short value"); } { short r = (short) vh.compareAndExchangeAcquire((short)0x0123, (short)0x89AB); assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "failing compareAndExchangeAcquire short value"); } { short r = (short) vh.compareAndExchangeRelease((short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "success compareAndExchangeRelease short value"); } { short r = (short) vh.compareAndExchangeRelease((short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "failing compareAndExchangeRelease short value"); } { @@ -796,14 +794,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "success weakCompareAndSetPlain short value"); } { boolean success = vh.weakCompareAndSetPlain((short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetPlain short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetPlain short value"); } { @@ -814,14 +812,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); + assertEquals((short)0x0123, x, "success weakCompareAndSetAcquire short"); } { boolean success = vh.weakCompareAndSetAcquire((short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetAcquire short value"); } { @@ -832,14 +830,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); + assertEquals((short)0x4567, x, "success weakCompareAndSetRelease short"); } { boolean success = vh.weakCompareAndSetRelease((short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetRelease short value"); } { @@ -850,14 +848,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); + assertEquals((short)0x0123, x, "success weakCompareAndSet short"); } { boolean success = vh.weakCompareAndSet((short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSet short"); short x = (short) vh.get(); - assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSet short value"); } // Compare set and get @@ -865,27 +863,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set((short)0x0123); short o = (short) vh.getAndSet((short)0x4567); - assertEquals(o, (short)0x0123, "getAndSet short"); + assertEquals((short)0x0123, o, "getAndSet short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "getAndSet short value"); + assertEquals((short)0x4567, x, "getAndSet short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndSetAcquire((short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetAcquire short"); + assertEquals((short)0x0123, o, "getAndSetAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); + assertEquals((short)0x4567, x, "getAndSetAcquire short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndSetRelease((short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetRelease short"); + assertEquals((short)0x0123, o, "getAndSetRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)0x4567, "getAndSetRelease short value"); + assertEquals((short)0x4567, x, "getAndSetRelease short value"); } // get and add, add and get @@ -893,27 +891,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set((short)0x0123); short o = (short) vh.getAndAdd((short)0x4567); - assertEquals(o, (short)0x0123, "getAndAdd short"); + assertEquals((short)0x0123, o, "getAndAdd short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAdd short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndAddAcquire((short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddAcquire short"); + assertEquals((short)0x0123, o, "getAndAddAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddAcquire short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndAddRelease((short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddReleaseshort"); + assertEquals((short)0x0123, o, "getAndAddReleaseshort"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddRelease short value"); } // get and bitwise or @@ -921,27 +919,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseOr((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); + assertEquals((short)0x0123, o, "getAndBitwiseOr short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOr short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseOrAcquire((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrAcquire short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseOrRelease((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrRelease short value"); } // get and bitwise and @@ -949,27 +947,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseAnd((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); + assertEquals((short)0x0123, o, "getAndBitwiseAnd short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAnd short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseAndAcquire((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndAcquire short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseAndRelease((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndRelease short value"); } // get and bitwise xor @@ -977,27 +975,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseXor((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); + assertEquals((short)0x0123, o, "getAndBitwiseXor short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXor short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseXorAcquire((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorAcquire short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorAcquire short value"); } { vh.set((short)0x0123); short o = (short) vh.getAndBitwiseXorRelease((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorRelease short"); short x = (short) vh.get(); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorRelease short value"); } } @@ -1015,7 +1013,7 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { { vh.set(array, i, (short)0x0123); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "get short value"); + assertEquals((short)0x0123, x, "get short value"); } @@ -1023,21 +1021,21 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { { vh.setVolatile(array, i, (short)0x4567); short x = (short) vh.getVolatile(array, i); - assertEquals(x, (short)0x4567, "setVolatile short value"); + assertEquals((short)0x4567, x, "setVolatile short value"); } // Lazy { vh.setRelease(array, i, (short)0x0123); short x = (short) vh.getAcquire(array, i); - assertEquals(x, (short)0x0123, "setRelease short value"); + assertEquals((short)0x0123, x, "setRelease short value"); } // Opaque { vh.setOpaque(array, i, (short)0x4567); short x = (short) vh.getOpaque(array, i); - assertEquals(x, (short)0x4567, "setOpaque short value"); + assertEquals((short)0x4567, x, "setOpaque short value"); } vh.set(array, i, (short)0x0123); @@ -1047,56 +1045,56 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, (short)0x0123, (short)0x4567); assertEquals(r, true, "success compareAndSet short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "success compareAndSet short value"); + assertEquals((short)0x4567, x, "success compareAndSet short value"); } { boolean r = vh.compareAndSet(array, i, (short)0x0123, (short)0x89AB); assertEquals(r, false, "failing compareAndSet short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "failing compareAndSet short value"); + assertEquals((short)0x4567, x, "failing compareAndSet short value"); } { short r = (short) vh.compareAndExchange(array, i, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchange short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "success compareAndExchange short value"); + assertEquals((short)0x0123, x, "success compareAndExchange short value"); } { short r = (short) vh.compareAndExchange(array, i, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchange short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); + assertEquals((short)0x0123, x, "failing compareAndExchange short value"); } { short r = (short) vh.compareAndExchangeAcquire(array, i, (short)0x0123, (short)0x4567); assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "success compareAndExchangeAcquire short value"); } { short r = (short) vh.compareAndExchangeAcquire(array, i, (short)0x0123, (short)0x89AB); assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "failing compareAndExchangeAcquire short value"); } { short r = (short) vh.compareAndExchangeRelease(array, i, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "success compareAndExchangeRelease short value"); } { short r = (short) vh.compareAndExchangeRelease(array, i, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "failing compareAndExchangeRelease short value"); } { @@ -1107,14 +1105,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "success weakCompareAndSetPlain short value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetPlain short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetPlain short value"); } { @@ -1125,14 +1123,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); + assertEquals((short)0x0123, x, "success weakCompareAndSetAcquire short"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetAcquire short value"); } { @@ -1143,14 +1141,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); + assertEquals((short)0x4567, x, "success weakCompareAndSetRelease short"); } { boolean success = vh.weakCompareAndSetRelease(array, i, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetRelease short value"); } { @@ -1161,14 +1159,14 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); + assertEquals((short)0x0123, x, "success weakCompareAndSet short"); } { boolean success = vh.weakCompareAndSet(array, i, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSet short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSet short value"); } // Compare set and get @@ -1176,27 +1174,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndSet(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSet short"); + assertEquals((short)0x0123, o, "getAndSet short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "getAndSet short value"); + assertEquals((short)0x4567, x, "getAndSet short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndSetAcquire(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetAcquire short"); + assertEquals((short)0x0123, o, "getAndSetAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); + assertEquals((short)0x4567, x, "getAndSetAcquire short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndSetRelease(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetRelease short"); + assertEquals((short)0x0123, o, "getAndSetRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)0x4567, "getAndSetRelease short value"); + assertEquals((short)0x4567, x, "getAndSetRelease short value"); } // get and add, add and get @@ -1204,27 +1202,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndAdd(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAdd short"); + assertEquals((short)0x0123, o, "getAndAdd short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAdd short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndAddAcquire(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddAcquire short"); + assertEquals((short)0x0123, o, "getAndAddAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddAcquire short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndAddRelease(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddReleaseshort"); + assertEquals((short)0x0123, o, "getAndAddReleaseshort"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddRelease short value"); } // get and bitwise or @@ -1232,27 +1230,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseOr(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); + assertEquals((short)0x0123, o, "getAndBitwiseOr short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOr short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseOrAcquire(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrAcquire short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseOrRelease(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrRelease short value"); } // get and bitwise and @@ -1260,27 +1258,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseAnd(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); + assertEquals((short)0x0123, o, "getAndBitwiseAnd short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAnd short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseAndAcquire(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndAcquire short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseAndRelease(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndRelease short value"); } // get and bitwise xor @@ -1288,27 +1286,27 @@ public class VarHandleTestAccessShort extends VarHandleBaseTest { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseXor(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); + assertEquals((short)0x0123, o, "getAndBitwiseXor short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXor short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseXorAcquire(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorAcquire short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorAcquire short value"); } { vh.set(array, i, (short)0x0123); short o = (short) vh.getAndBitwiseXorRelease(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorRelease short"); short x = (short) vh.get(array, i); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorRelease short value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java index 8bc30739660..d1a746ba80e 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccessString + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccessString * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessString - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessString - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessString + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccessString + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccessString + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccessString */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccessString extends VarHandleBaseTest { static final String static_final_v = "foo"; @@ -109,7 +111,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccessString.class, "final_v", String.class); @@ -127,8 +129,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class); } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -158,7 +158,8 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -196,8 +197,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccessString.class)}); @@ -207,16 +206,16 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), String.class); + assertEquals(String.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -243,8 +242,6 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -291,7 +288,8 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -304,26 +302,26 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { // Plain { String x = (String) vh.get(recv); - assertEquals(x, "foo", "get String value"); + assertEquals("foo", x, "get String value"); } // Volatile { String x = (String) vh.getVolatile(recv); - assertEquals(x, "foo", "getVolatile String value"); + assertEquals("foo", x, "getVolatile String value"); } // Lazy { String x = (String) vh.getAcquire(recv); - assertEquals(x, "foo", "getRelease String value"); + assertEquals("foo", x, "getRelease String value"); } // Opaque { String x = (String) vh.getOpaque(recv); - assertEquals(x, "foo", "getOpaque String value"); + assertEquals("foo", x, "getOpaque String value"); } } @@ -399,26 +397,26 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { // Plain { String x = (String) vh.get(); - assertEquals(x, "foo", "get String value"); + assertEquals("foo", x, "get String value"); } // Volatile { String x = (String) vh.getVolatile(); - assertEquals(x, "foo", "getVolatile String value"); + assertEquals("foo", x, "getVolatile String value"); } // Lazy { String x = (String) vh.getAcquire(); - assertEquals(x, "foo", "getRelease String value"); + assertEquals("foo", x, "getRelease String value"); } // Opaque { String x = (String) vh.getOpaque(); - assertEquals(x, "foo", "getOpaque String value"); + assertEquals("foo", x, "getOpaque String value"); } } @@ -495,7 +493,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { { vh.set(recv, "foo"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "set String value"); + assertEquals("foo", x, "set String value"); } @@ -503,21 +501,21 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { { vh.setVolatile(recv, "bar"); String x = (String) vh.getVolatile(recv); - assertEquals(x, "bar", "setVolatile String value"); + assertEquals("bar", x, "setVolatile String value"); } // Lazy { vh.setRelease(recv, "foo"); String x = (String) vh.getAcquire(recv); - assertEquals(x, "foo", "setRelease String value"); + assertEquals("foo", x, "setRelease String value"); } // Opaque { vh.setOpaque(recv, "bar"); String x = (String) vh.getOpaque(recv); - assertEquals(x, "bar", "setOpaque String value"); + assertEquals("bar", x, "setOpaque String value"); } vh.set(recv, "foo"); @@ -527,56 +525,56 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, "foo", "bar"); assertEquals(r, true, "success compareAndSet String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "success compareAndSet String value"); + assertEquals("bar", x, "success compareAndSet String value"); } { boolean r = vh.compareAndSet(recv, "foo", "baz"); assertEquals(r, false, "failing compareAndSet String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "failing compareAndSet String value"); + assertEquals("bar", x, "failing compareAndSet String value"); } { String r = (String) vh.compareAndExchange(recv, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchange String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "success compareAndExchange String value"); + assertEquals("foo", x, "success compareAndExchange String value"); } { String r = (String) vh.compareAndExchange(recv, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchange String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "failing compareAndExchange String value"); + assertEquals("foo", x, "failing compareAndExchange String value"); } { String r = (String) vh.compareAndExchangeAcquire(recv, "foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); + assertEquals("bar", x, "success compareAndExchangeAcquire String value"); } { String r = (String) vh.compareAndExchangeAcquire(recv, "foo", "baz"); assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); + assertEquals("bar", x, "failing compareAndExchangeAcquire String value"); } { String r = (String) vh.compareAndExchangeRelease(recv, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchangeRelease String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "success compareAndExchangeRelease String value"); + assertEquals("foo", x, "success compareAndExchangeRelease String value"); } { String r = (String) vh.compareAndExchangeRelease(recv, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchangeRelease String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "failing compareAndExchangeRelease String value"); + assertEquals("foo", x, "failing compareAndExchangeRelease String value"); } { @@ -587,14 +585,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "success weakCompareAndSetPlain String value"); + assertEquals("bar", x, "success weakCompareAndSetPlain String value"); } { boolean success = vh.weakCompareAndSetPlain(recv, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetPlain String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "failing weakCompareAndSetPlain String value"); + assertEquals("bar", x, "failing weakCompareAndSetPlain String value"); } { @@ -605,14 +603,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "success weakCompareAndSetAcquire String"); + assertEquals("foo", x, "success weakCompareAndSetAcquire String"); } { boolean success = vh.weakCompareAndSetAcquire(recv, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value"); + assertEquals("foo", x, "failing weakCompareAndSetAcquire String value"); } { @@ -623,14 +621,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "success weakCompareAndSetRelease String"); + assertEquals("bar", x, "success weakCompareAndSetRelease String"); } { boolean success = vh.weakCompareAndSetRelease(recv, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetRelease String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "failing weakCompareAndSetRelease String value"); + assertEquals("bar", x, "failing weakCompareAndSetRelease String value"); } { @@ -641,14 +639,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "success weakCompareAndSet String value"); + assertEquals("foo", x, "success weakCompareAndSet String value"); } { boolean success = vh.weakCompareAndSet(recv, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSet String"); String x = (String) vh.get(recv); - assertEquals(x, "foo", "failing weakCompareAndSet String value"); + assertEquals("foo", x, "failing weakCompareAndSet String value"); } // Compare set and get @@ -656,27 +654,27 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { vh.set(recv, "foo"); String o = (String) vh.getAndSet(recv, "bar"); - assertEquals(o, "foo", "getAndSet String"); + assertEquals("foo", o, "getAndSet String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "getAndSet String value"); + assertEquals("bar", x, "getAndSet String value"); } { vh.set(recv, "foo"); String o = (String) vh.getAndSetAcquire(recv, "bar"); - assertEquals(o, "foo", "getAndSetAcquire String"); + assertEquals("foo", o, "getAndSetAcquire String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "getAndSetAcquire String value"); + assertEquals("bar", x, "getAndSetAcquire String value"); } { vh.set(recv, "foo"); String o = (String) vh.getAndSetRelease(recv, "bar"); - assertEquals(o, "foo", "getAndSetRelease String"); + assertEquals("foo", o, "getAndSetRelease String"); String x = (String) vh.get(recv); - assertEquals(x, "bar", "getAndSetRelease String value"); + assertEquals("bar", x, "getAndSetRelease String value"); } @@ -739,7 +737,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { { vh.set("foo"); String x = (String) vh.get(); - assertEquals(x, "foo", "set String value"); + assertEquals("foo", x, "set String value"); } @@ -747,21 +745,21 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { { vh.setVolatile("bar"); String x = (String) vh.getVolatile(); - assertEquals(x, "bar", "setVolatile String value"); + assertEquals("bar", x, "setVolatile String value"); } // Lazy { vh.setRelease("foo"); String x = (String) vh.getAcquire(); - assertEquals(x, "foo", "setRelease String value"); + assertEquals("foo", x, "setRelease String value"); } // Opaque { vh.setOpaque("bar"); String x = (String) vh.getOpaque(); - assertEquals(x, "bar", "setOpaque String value"); + assertEquals("bar", x, "setOpaque String value"); } vh.set("foo"); @@ -771,56 +769,56 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { boolean r = vh.compareAndSet("foo", "bar"); assertEquals(r, true, "success compareAndSet String"); String x = (String) vh.get(); - assertEquals(x, "bar", "success compareAndSet String value"); + assertEquals("bar", x, "success compareAndSet String value"); } { boolean r = vh.compareAndSet("foo", "baz"); assertEquals(r, false, "failing compareAndSet String"); String x = (String) vh.get(); - assertEquals(x, "bar", "failing compareAndSet String value"); + assertEquals("bar", x, "failing compareAndSet String value"); } { String r = (String) vh.compareAndExchange("bar", "foo"); assertEquals(r, "bar", "success compareAndExchange String"); String x = (String) vh.get(); - assertEquals(x, "foo", "success compareAndExchange String value"); + assertEquals("foo", x, "success compareAndExchange String value"); } { String r = (String) vh.compareAndExchange("bar", "baz"); assertEquals(r, "foo", "failing compareAndExchange String"); String x = (String) vh.get(); - assertEquals(x, "foo", "failing compareAndExchange String value"); + assertEquals("foo", x, "failing compareAndExchange String value"); } { String r = (String) vh.compareAndExchangeAcquire("foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire String"); String x = (String) vh.get(); - assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); + assertEquals("bar", x, "success compareAndExchangeAcquire String value"); } { String r = (String) vh.compareAndExchangeAcquire("foo", "baz"); assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); String x = (String) vh.get(); - assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); + assertEquals("bar", x, "failing compareAndExchangeAcquire String value"); } { String r = (String) vh.compareAndExchangeRelease("bar", "foo"); assertEquals(r, "bar", "success compareAndExchangeRelease String"); String x = (String) vh.get(); - assertEquals(x, "foo", "success compareAndExchangeRelease String value"); + assertEquals("foo", x, "success compareAndExchangeRelease String value"); } { String r = (String) vh.compareAndExchangeRelease("bar", "baz"); assertEquals(r, "foo", "failing compareAndExchangeRelease String"); String x = (String) vh.get(); - assertEquals(x, "foo", "failing compareAndExchangeRelease String value"); + assertEquals("foo", x, "failing compareAndExchangeRelease String value"); } { @@ -831,14 +829,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain String"); String x = (String) vh.get(); - assertEquals(x, "bar", "success weakCompareAndSetPlain String value"); + assertEquals("bar", x, "success weakCompareAndSetPlain String value"); } { boolean success = vh.weakCompareAndSetPlain("foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetPlain String"); String x = (String) vh.get(); - assertEquals(x, "bar", "failing weakCompareAndSetPlain String value"); + assertEquals("bar", x, "failing weakCompareAndSetPlain String value"); } { @@ -849,14 +847,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire String"); String x = (String) vh.get(); - assertEquals(x, "foo", "success weakCompareAndSetAcquire String"); + assertEquals("foo", x, "success weakCompareAndSetAcquire String"); } { boolean success = vh.weakCompareAndSetAcquire("bar", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) vh.get(); - assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value"); + assertEquals("foo", x, "failing weakCompareAndSetAcquire String value"); } { @@ -867,14 +865,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease String"); String x = (String) vh.get(); - assertEquals(x, "bar", "success weakCompareAndSetRelease String"); + assertEquals("bar", x, "success weakCompareAndSetRelease String"); } { boolean success = vh.weakCompareAndSetRelease("foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetRelease String"); String x = (String) vh.get(); - assertEquals(x, "bar", "failing weakCompareAndSetRelease String value"); + assertEquals("bar", x, "failing weakCompareAndSetRelease String value"); } { @@ -885,14 +883,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet String"); String x = (String) vh.get(); - assertEquals(x, "foo", "success weakCompareAndSet String"); + assertEquals("foo", x, "success weakCompareAndSet String"); } { boolean success = vh.weakCompareAndSet("bar", "baz"); assertEquals(success, false, "failing weakCompareAndSet String"); String x = (String) vh.get(); - assertEquals(x, "foo", "failing weakCompareAndSet String value"); + assertEquals("foo", x, "failing weakCompareAndSet String value"); } // Compare set and get @@ -900,27 +898,27 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { vh.set("foo"); String o = (String) vh.getAndSet("bar"); - assertEquals(o, "foo", "getAndSet String"); + assertEquals("foo", o, "getAndSet String"); String x = (String) vh.get(); - assertEquals(x, "bar", "getAndSet String value"); + assertEquals("bar", x, "getAndSet String value"); } { vh.set("foo"); String o = (String) vh.getAndSetAcquire("bar"); - assertEquals(o, "foo", "getAndSetAcquire String"); + assertEquals("foo", o, "getAndSetAcquire String"); String x = (String) vh.get(); - assertEquals(x, "bar", "getAndSetAcquire String value"); + assertEquals("bar", x, "getAndSetAcquire String value"); } { vh.set("foo"); String o = (String) vh.getAndSetRelease("bar"); - assertEquals(o, "foo", "getAndSetRelease String"); + assertEquals("foo", o, "getAndSetRelease String"); String x = (String) vh.get(); - assertEquals(x, "bar", "getAndSetRelease String value"); + assertEquals("bar", x, "getAndSetRelease String value"); } @@ -986,7 +984,7 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { { vh.set(array, i, "foo"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "get String value"); + assertEquals("foo", x, "get String value"); } @@ -994,21 +992,21 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { { vh.setVolatile(array, i, "bar"); String x = (String) vh.getVolatile(array, i); - assertEquals(x, "bar", "setVolatile String value"); + assertEquals("bar", x, "setVolatile String value"); } // Lazy { vh.setRelease(array, i, "foo"); String x = (String) vh.getAcquire(array, i); - assertEquals(x, "foo", "setRelease String value"); + assertEquals("foo", x, "setRelease String value"); } // Opaque { vh.setOpaque(array, i, "bar"); String x = (String) vh.getOpaque(array, i); - assertEquals(x, "bar", "setOpaque String value"); + assertEquals("bar", x, "setOpaque String value"); } vh.set(array, i, "foo"); @@ -1018,56 +1016,56 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, "foo", "bar"); assertEquals(r, true, "success compareAndSet String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "success compareAndSet String value"); + assertEquals("bar", x, "success compareAndSet String value"); } { boolean r = vh.compareAndSet(array, i, "foo", "baz"); assertEquals(r, false, "failing compareAndSet String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "failing compareAndSet String value"); + assertEquals("bar", x, "failing compareAndSet String value"); } { String r = (String) vh.compareAndExchange(array, i, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchange String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "success compareAndExchange String value"); + assertEquals("foo", x, "success compareAndExchange String value"); } { String r = (String) vh.compareAndExchange(array, i, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchange String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "failing compareAndExchange String value"); + assertEquals("foo", x, "failing compareAndExchange String value"); } { String r = (String) vh.compareAndExchangeAcquire(array, i, "foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); + assertEquals("bar", x, "success compareAndExchangeAcquire String value"); } { String r = (String) vh.compareAndExchangeAcquire(array, i, "foo", "baz"); assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); + assertEquals("bar", x, "failing compareAndExchangeAcquire String value"); } { String r = (String) vh.compareAndExchangeRelease(array, i, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchangeRelease String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "success compareAndExchangeRelease String value"); + assertEquals("foo", x, "success compareAndExchangeRelease String value"); } { String r = (String) vh.compareAndExchangeRelease(array, i, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchangeRelease String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "failing compareAndExchangeRelease String value"); + assertEquals("foo", x, "failing compareAndExchangeRelease String value"); } { @@ -1078,14 +1076,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "success weakCompareAndSetPlain String value"); + assertEquals("bar", x, "success weakCompareAndSetPlain String value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetPlain String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "failing weakCompareAndSetPlain String value"); + assertEquals("bar", x, "failing weakCompareAndSetPlain String value"); } { @@ -1096,14 +1094,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "success weakCompareAndSetAcquire String"); + assertEquals("foo", x, "success weakCompareAndSetAcquire String"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value"); + assertEquals("foo", x, "failing weakCompareAndSetAcquire String value"); } { @@ -1114,14 +1112,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "success weakCompareAndSetRelease String"); + assertEquals("bar", x, "success weakCompareAndSetRelease String"); } { boolean success = vh.weakCompareAndSetRelease(array, i, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetRelease String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "failing weakCompareAndSetRelease String value"); + assertEquals("bar", x, "failing weakCompareAndSetRelease String value"); } { @@ -1132,14 +1130,14 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "success weakCompareAndSet String"); + assertEquals("foo", x, "success weakCompareAndSet String"); } { boolean success = vh.weakCompareAndSet(array, i, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSet String"); String x = (String) vh.get(array, i); - assertEquals(x, "foo", "failing weakCompareAndSet String value"); + assertEquals("foo", x, "failing weakCompareAndSet String value"); } // Compare set and get @@ -1147,27 +1145,27 @@ public class VarHandleTestAccessString extends VarHandleBaseTest { vh.set(array, i, "foo"); String o = (String) vh.getAndSet(array, i, "bar"); - assertEquals(o, "foo", "getAndSet String"); + assertEquals("foo", o, "getAndSet String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "getAndSet String value"); + assertEquals("bar", x, "getAndSet String value"); } { vh.set(array, i, "foo"); String o = (String) vh.getAndSetAcquire(array, i, "bar"); - assertEquals(o, "foo", "getAndSetAcquire String"); + assertEquals("foo", o, "getAndSetAcquire String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "getAndSetAcquire String value"); + assertEquals("bar", x, "getAndSetAcquire String value"); } { vh.set(array, i, "foo"); String o = (String) vh.getAndSetRelease(array, i, "bar"); - assertEquals(o, "foo", "getAndSetRelease String"); + assertEquals("foo", o, "getAndSetRelease String"); String x = (String) vh.get(array, i); - assertEquals(x, "bar", "getAndSetRelease String value"); + assertEquals("bar", x, "getAndSetRelease String value"); } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java index 78c13da45a9..26ac4aab893 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsChar - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsChar - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsChar + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsChar + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsChar + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsChar */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { static final int SIZE = Character.BYTES; @@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -158,17 +159,16 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), char.class); + assertEquals(char.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -230,7 +230,8 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -239,7 +240,6 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -740,7 +740,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); char x = (char) vh.get(array, i); - assertEquals(x, VALUE_1, "get char value"); + assertEquals(VALUE_1, x, "get char value"); } } } @@ -759,7 +759,7 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); char x = (char) vh.get(array, i); - assertEquals(x, VALUE_1, "get char value"); + assertEquals(VALUE_1, x, "get char value"); } if (iAligned) { @@ -767,21 +767,21 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); char x = (char) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile char value"); + assertEquals(VALUE_2, x, "setVolatile char value"); } // Lazy { vh.setRelease(array, i, VALUE_1); char x = (char) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease char value"); + assertEquals(VALUE_1, x, "setRelease char value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); char x = (char) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque char value"); + assertEquals(VALUE_2, x, "setOpaque char value"); } @@ -807,26 +807,26 @@ public class VarHandleTestByteArrayAsChar extends VarHandleBaseByteArrayTest { // Plain { char x = (char) vh.get(array, i); - assertEquals(x, v, "get char value"); + assertEquals(v, x, "get char value"); } if (iAligned) { // Volatile { char x = (char) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile char value"); + assertEquals(v, x, "getVolatile char value"); } // Lazy { char x = (char) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease char value"); + assertEquals(v, x, "getRelease char value"); } // Opaque { char x = (char) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque char value"); + assertEquals(v, x, "getOpaque char value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java index 331b9073e90..a9e1e603c5d 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsDouble - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsDouble - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsDouble + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsDouble + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsDouble + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsDouble */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { static final int SIZE = Double.BYTES; @@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -172,17 +173,16 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), double.class); + assertEquals(double.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -244,7 +244,8 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -253,7 +254,6 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -883,7 +883,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "get double value"); + assertEquals(VALUE_1, x, "get double value"); } } } @@ -902,7 +902,7 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "get double value"); + assertEquals(VALUE_1, x, "get double value"); } if (iAligned) { @@ -910,21 +910,21 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); double x = (double) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile double value"); + assertEquals(VALUE_2, x, "setVolatile double value"); } // Lazy { vh.setRelease(array, i, VALUE_1); double x = (double) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease double value"); + assertEquals(VALUE_1, x, "setRelease double value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); double x = (double) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque double value"); + assertEquals(VALUE_2, x, "setOpaque double value"); } vh.set(array, i, VALUE_1); @@ -934,56 +934,56 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); assertEquals(r, true, "success compareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndSet double value"); + assertEquals(VALUE_2, x, "success compareAndSet double value"); } { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); assertEquals(r, false, "failing compareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndSet double value"); + assertEquals(VALUE_2, x, "failing compareAndSet double value"); } { double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchange double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchange double value"); + assertEquals(VALUE_1, x, "success compareAndExchange double value"); } { double r = (double) vh.compareAndExchange(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchange double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchange double value"); + assertEquals(VALUE_1, x, "failing compareAndExchange double value"); } { double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); assertEquals(r, VALUE_1, "success compareAndExchangeAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndExchangeAcquire double value"); + assertEquals(VALUE_2, x, "success compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire double value"); + assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchangeRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchangeRelease double value"); + assertEquals(VALUE_1, x, "success compareAndExchangeRelease double value"); } { double r = (double) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchangeRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchangeRelease double value"); + assertEquals(VALUE_1, x, "failing compareAndExchangeRelease double value"); } { @@ -994,14 +994,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetPlain double value"); + assertEquals(VALUE_2, x, "success weakCompareAndSetPlain double value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain double value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain double value"); } { @@ -1012,14 +1012,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire double"); + assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire double"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire double value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire double value"); } { @@ -1030,14 +1030,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetRelease double"); + assertEquals(VALUE_2, x, "success weakCompareAndSetRelease double"); } { boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease double value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease double value"); } { @@ -1048,14 +1048,14 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSet double"); + assertEquals(VALUE_1, x, "success weakCompareAndSet double"); } { boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSet double value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSet double value"); } // Compare set and get @@ -1063,27 +1063,27 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); double o = (double) vh.getAndSet(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSet double"); + assertEquals(VALUE_1, o, "getAndSet double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSet double value"); + assertEquals(VALUE_2, x, "getAndSet double value"); } { vh.set(array, i, VALUE_1); double o = (double) vh.getAndSetAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetAcquire double"); + assertEquals(VALUE_1, o, "getAndSetAcquire double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetAcquire double value"); + assertEquals(VALUE_2, x, "getAndSetAcquire double value"); } { vh.set(array, i, VALUE_1); double o = (double) vh.getAndSetRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetRelease double"); + assertEquals(VALUE_1, o, "getAndSetRelease double"); double x = (double) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetRelease double value"); + assertEquals(VALUE_2, x, "getAndSetRelease double value"); } @@ -1109,26 +1109,26 @@ public class VarHandleTestByteArrayAsDouble extends VarHandleBaseByteArrayTest { // Plain { double x = (double) vh.get(array, i); - assertEquals(x, v, "get double value"); + assertEquals(v, x, "get double value"); } if (iAligned) { // Volatile { double x = (double) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile double value"); + assertEquals(v, x, "getVolatile double value"); } // Lazy { double x = (double) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease double value"); + assertEquals(v, x, "getRelease double value"); } // Opaque { double x = (double) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque double value"); + assertEquals(v, x, "getOpaque double value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java index 908d61dd597..486487518e9 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsFloat - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsFloat - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsFloat + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsFloat + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsFloat + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsFloat */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { static final int SIZE = Float.BYTES; @@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -172,17 +173,16 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), float.class); + assertEquals(float.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -244,7 +244,8 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -253,7 +254,6 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -883,7 +883,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "get float value"); + assertEquals(VALUE_1, x, "get float value"); } } } @@ -902,7 +902,7 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "get float value"); + assertEquals(VALUE_1, x, "get float value"); } if (iAligned) { @@ -910,21 +910,21 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); float x = (float) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile float value"); + assertEquals(VALUE_2, x, "setVolatile float value"); } // Lazy { vh.setRelease(array, i, VALUE_1); float x = (float) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease float value"); + assertEquals(VALUE_1, x, "setRelease float value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); float x = (float) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque float value"); + assertEquals(VALUE_2, x, "setOpaque float value"); } vh.set(array, i, VALUE_1); @@ -934,56 +934,56 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); assertEquals(r, true, "success compareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndSet float value"); + assertEquals(VALUE_2, x, "success compareAndSet float value"); } { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); assertEquals(r, false, "failing compareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndSet float value"); + assertEquals(VALUE_2, x, "failing compareAndSet float value"); } { float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchange float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchange float value"); + assertEquals(VALUE_1, x, "success compareAndExchange float value"); } { float r = (float) vh.compareAndExchange(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchange float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchange float value"); + assertEquals(VALUE_1, x, "failing compareAndExchange float value"); } { float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); assertEquals(r, VALUE_1, "success compareAndExchangeAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndExchangeAcquire float value"); + assertEquals(VALUE_2, x, "success compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire float value"); + assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchangeRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchangeRelease float value"); + assertEquals(VALUE_1, x, "success compareAndExchangeRelease float value"); } { float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchangeRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchangeRelease float value"); + assertEquals(VALUE_1, x, "failing compareAndExchangeRelease float value"); } { @@ -994,14 +994,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetPlain float value"); + assertEquals(VALUE_2, x, "success weakCompareAndSetPlain float value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain float value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain float value"); } { @@ -1012,14 +1012,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire float"); + assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire float"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire float value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire float value"); } { @@ -1030,14 +1030,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetRelease float"); + assertEquals(VALUE_2, x, "success weakCompareAndSetRelease float"); } { boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease float value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease float value"); } { @@ -1048,14 +1048,14 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSet float"); + assertEquals(VALUE_1, x, "success weakCompareAndSet float"); } { boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSet float value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSet float value"); } // Compare set and get @@ -1063,27 +1063,27 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); float o = (float) vh.getAndSet(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSet float"); + assertEquals(VALUE_1, o, "getAndSet float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSet float value"); + assertEquals(VALUE_2, x, "getAndSet float value"); } { vh.set(array, i, VALUE_1); float o = (float) vh.getAndSetAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetAcquire float"); + assertEquals(VALUE_1, o, "getAndSetAcquire float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetAcquire float value"); + assertEquals(VALUE_2, x, "getAndSetAcquire float value"); } { vh.set(array, i, VALUE_1); float o = (float) vh.getAndSetRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetRelease float"); + assertEquals(VALUE_1, o, "getAndSetRelease float"); float x = (float) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetRelease float value"); + assertEquals(VALUE_2, x, "getAndSetRelease float value"); } @@ -1109,26 +1109,26 @@ public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { // Plain { float x = (float) vh.get(array, i); - assertEquals(x, v, "get float value"); + assertEquals(v, x, "get float value"); } if (iAligned) { // Volatile { float x = (float) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile float value"); + assertEquals(v, x, "getVolatile float value"); } // Lazy { float x = (float) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease float value"); + assertEquals(v, x, "getRelease float value"); } // Opaque { float x = (float) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque float value"); + assertEquals(v, x, "getOpaque float value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java index 791510281c1..ce55c3d5e31 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsInt - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsInt - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsInt + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsInt + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsInt + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsInt */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { static final int SIZE = Integer.BYTES; @@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -190,17 +191,16 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), int.class); + assertEquals(int.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -262,7 +262,8 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -271,7 +272,6 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -1039,7 +1039,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "get int value"); + assertEquals(VALUE_1, x, "get int value"); } } } @@ -1058,7 +1058,7 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "get int value"); + assertEquals(VALUE_1, x, "get int value"); } if (iAligned) { @@ -1066,21 +1066,21 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); int x = (int) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile int value"); + assertEquals(VALUE_2, x, "setVolatile int value"); } // Lazy { vh.setRelease(array, i, VALUE_1); int x = (int) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease int value"); + assertEquals(VALUE_1, x, "setRelease int value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); int x = (int) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque int value"); + assertEquals(VALUE_2, x, "setOpaque int value"); } vh.set(array, i, VALUE_1); @@ -1090,56 +1090,56 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); assertEquals(r, true, "success compareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndSet int value"); + assertEquals(VALUE_2, x, "success compareAndSet int value"); } { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); assertEquals(r, false, "failing compareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndSet int value"); + assertEquals(VALUE_2, x, "failing compareAndSet int value"); } { int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchange int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchange int value"); + assertEquals(VALUE_1, x, "success compareAndExchange int value"); } { int r = (int) vh.compareAndExchange(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchange int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchange int value"); + assertEquals(VALUE_1, x, "failing compareAndExchange int value"); } { int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); assertEquals(r, VALUE_1, "success compareAndExchangeAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndExchangeAcquire int value"); + assertEquals(VALUE_2, x, "success compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire int value"); + assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchangeRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchangeRelease int value"); + assertEquals(VALUE_1, x, "success compareAndExchangeRelease int value"); } { int r = (int) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchangeRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchangeRelease int value"); + assertEquals(VALUE_1, x, "failing compareAndExchangeRelease int value"); } { @@ -1150,14 +1150,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetPlain int value"); + assertEquals(VALUE_2, x, "success weakCompareAndSetPlain int value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain int value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain int value"); } { @@ -1168,14 +1168,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire int"); + assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire int"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire int value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire int value"); } { @@ -1186,14 +1186,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetRelease int"); + assertEquals(VALUE_2, x, "success weakCompareAndSetRelease int"); } { boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease int value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease int value"); } { @@ -1204,14 +1204,14 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSet int"); + assertEquals(VALUE_1, x, "success weakCompareAndSet int"); } { boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSet int value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSet int value"); } // Compare set and get @@ -1219,27 +1219,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); int o = (int) vh.getAndSet(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSet int"); + assertEquals(VALUE_1, o, "getAndSet int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSet int value"); + assertEquals(VALUE_2, x, "getAndSet int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndSetAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetAcquire int"); + assertEquals(VALUE_1, o, "getAndSetAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetAcquire int value"); + assertEquals(VALUE_2, x, "getAndSetAcquire int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndSetRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetRelease int"); + assertEquals(VALUE_1, o, "getAndSetRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetRelease int value"); + assertEquals(VALUE_2, x, "getAndSetRelease int value"); } // get and add, add and get @@ -1247,27 +1247,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); int o = (int) vh.getAndAdd(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAdd int"); + assertEquals(VALUE_1, o, "getAndAdd int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd int value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAdd int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndAddAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAddAcquire int"); + assertEquals(VALUE_1, o, "getAndAddAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire int value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAddAcquire int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndAddRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAddRelease int"); + assertEquals(VALUE_1, o, "getAndAddRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease int value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAddRelease int value"); } // get and bitwise or @@ -1275,27 +1275,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseOr(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOr int"); + assertEquals(VALUE_1, o, "getAndBitwiseOr int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr int value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOr int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseOrAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire int"); + assertEquals(VALUE_1, o, "getAndBitwiseOrAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire int value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrAcquire int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseOrRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOrRelease int"); + assertEquals(VALUE_1, o, "getAndBitwiseOrRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease int value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -1303,27 +1303,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseAnd(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAnd int"); + assertEquals(VALUE_1, o, "getAndBitwiseAnd int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd int value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAnd int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseAndAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire int"); + assertEquals(VALUE_1, o, "getAndBitwiseAndAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire int value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndAcquire int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseAndRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAndRelease int"); + assertEquals(VALUE_1, o, "getAndBitwiseAndRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease int value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -1331,27 +1331,27 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseXor(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXor int"); + assertEquals(VALUE_1, o, "getAndBitwiseXor int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor int value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXor int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseXorAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire int"); + assertEquals(VALUE_1, o, "getAndBitwiseXorAcquire int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire int value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorAcquire int value"); } { vh.set(array, i, VALUE_1); int o = (int) vh.getAndBitwiseXorRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXorRelease int"); + assertEquals(VALUE_1, o, "getAndBitwiseXorRelease int"); int x = (int) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease int value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorRelease int value"); } } } @@ -1375,26 +1375,26 @@ public class VarHandleTestByteArrayAsInt extends VarHandleBaseByteArrayTest { // Plain { int x = (int) vh.get(array, i); - assertEquals(x, v, "get int value"); + assertEquals(v, x, "get int value"); } if (iAligned) { // Volatile { int x = (int) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile int value"); + assertEquals(v, x, "getVolatile int value"); } // Lazy { int x = (int) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease int value"); + assertEquals(v, x, "getRelease int value"); } // Opaque { int x = (int) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque int value"); + assertEquals(v, x, "getOpaque int value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java index 4188a51a559..763703b6079 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsLong - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsLong - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsLong + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsLong + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsLong + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsLong */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { static final int SIZE = Long.BYTES; @@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -190,17 +191,16 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), long.class); + assertEquals(long.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -262,7 +262,8 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -271,7 +272,6 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -1039,7 +1039,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "get long value"); + assertEquals(VALUE_1, x, "get long value"); } } } @@ -1058,7 +1058,7 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "get long value"); + assertEquals(VALUE_1, x, "get long value"); } if (iAligned) { @@ -1066,21 +1066,21 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); long x = (long) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile long value"); + assertEquals(VALUE_2, x, "setVolatile long value"); } // Lazy { vh.setRelease(array, i, VALUE_1); long x = (long) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease long value"); + assertEquals(VALUE_1, x, "setRelease long value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); long x = (long) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque long value"); + assertEquals(VALUE_2, x, "setOpaque long value"); } vh.set(array, i, VALUE_1); @@ -1090,56 +1090,56 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); assertEquals(r, true, "success compareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndSet long value"); + assertEquals(VALUE_2, x, "success compareAndSet long value"); } { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); assertEquals(r, false, "failing compareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndSet long value"); + assertEquals(VALUE_2, x, "failing compareAndSet long value"); } { long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchange long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchange long value"); + assertEquals(VALUE_1, x, "success compareAndExchange long value"); } { long r = (long) vh.compareAndExchange(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchange long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchange long value"); + assertEquals(VALUE_1, x, "failing compareAndExchange long value"); } { long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); assertEquals(r, VALUE_1, "success compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndExchangeAcquire long value"); + assertEquals(VALUE_2, x, "success compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire long value"); + assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchangeRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchangeRelease long value"); + assertEquals(VALUE_1, x, "success compareAndExchangeRelease long value"); } { long r = (long) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchangeRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchangeRelease long value"); + assertEquals(VALUE_1, x, "failing compareAndExchangeRelease long value"); } { @@ -1150,14 +1150,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetPlain long value"); + assertEquals(VALUE_2, x, "success weakCompareAndSetPlain long value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain long value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain long value"); } { @@ -1168,14 +1168,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire long"); + assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire long"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire long value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire long value"); } { @@ -1186,14 +1186,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetRelease long"); + assertEquals(VALUE_2, x, "success weakCompareAndSetRelease long"); } { boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease long value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease long value"); } { @@ -1204,14 +1204,14 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSet long"); + assertEquals(VALUE_1, x, "success weakCompareAndSet long"); } { boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSet long value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSet long value"); } // Compare set and get @@ -1219,27 +1219,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); long o = (long) vh.getAndSet(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSet long"); + assertEquals(VALUE_1, o, "getAndSet long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSet long value"); + assertEquals(VALUE_2, x, "getAndSet long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndSetAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetAcquire long"); + assertEquals(VALUE_1, o, "getAndSetAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetAcquire long value"); + assertEquals(VALUE_2, x, "getAndSetAcquire long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndSetRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetRelease long"); + assertEquals(VALUE_1, o, "getAndSetRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetRelease long value"); + assertEquals(VALUE_2, x, "getAndSetRelease long value"); } // get and add, add and get @@ -1247,27 +1247,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); long o = (long) vh.getAndAdd(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAdd long"); + assertEquals(VALUE_1, o, "getAndAdd long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd long value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAdd long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndAddAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAddAcquire long"); + assertEquals(VALUE_1, o, "getAndAddAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire long value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAddAcquire long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndAddRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAddRelease long"); + assertEquals(VALUE_1, o, "getAndAddRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease long value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAddRelease long value"); } // get and bitwise or @@ -1275,27 +1275,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseOr(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOr long"); + assertEquals(VALUE_1, o, "getAndBitwiseOr long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr long value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOr long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseOrAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire long"); + assertEquals(VALUE_1, o, "getAndBitwiseOrAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire long value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrAcquire long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseOrRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOrRelease long"); + assertEquals(VALUE_1, o, "getAndBitwiseOrRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease long value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -1303,27 +1303,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseAnd(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAnd long"); + assertEquals(VALUE_1, o, "getAndBitwiseAnd long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd long value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAnd long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseAndAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire long"); + assertEquals(VALUE_1, o, "getAndBitwiseAndAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire long value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndAcquire long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseAndRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAndRelease long"); + assertEquals(VALUE_1, o, "getAndBitwiseAndRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease long value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -1331,27 +1331,27 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseXor(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXor long"); + assertEquals(VALUE_1, o, "getAndBitwiseXor long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor long value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXor long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseXorAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire long"); + assertEquals(VALUE_1, o, "getAndBitwiseXorAcquire long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire long value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorAcquire long value"); } { vh.set(array, i, VALUE_1); long o = (long) vh.getAndBitwiseXorRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXorRelease long"); + assertEquals(VALUE_1, o, "getAndBitwiseXorRelease long"); long x = (long) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease long value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorRelease long value"); } } } @@ -1375,26 +1375,26 @@ public class VarHandleTestByteArrayAsLong extends VarHandleBaseByteArrayTest { // Plain { long x = (long) vh.get(array, i); - assertEquals(x, v, "get long value"); + assertEquals(v, x, "get long value"); } if (iAligned) { // Volatile { long x = (long) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile long value"); + assertEquals(v, x, "getVolatile long value"); } // Lazy { long x = (long) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease long value"); + assertEquals(v, x, "getRelease long value"); } // Opaque { long x = (long) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque long value"); + assertEquals(v, x, "getOpaque long value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java index 1ecfef0476e..7a3bc069c22 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsShort - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsShort - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsShort + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsShort + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAsShort + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAsShort */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { static final int SIZE = Short.BYTES; @@ -107,7 +107,8 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -158,17 +159,16 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_BITWISE_XOR_RELEASE)); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), short.class); + assertEquals(short.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -230,7 +230,8 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -239,7 +240,6 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -740,7 +740,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); short x = (short) vh.get(array, i); - assertEquals(x, VALUE_1, "get short value"); + assertEquals(VALUE_1, x, "get short value"); } } } @@ -759,7 +759,7 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); short x = (short) vh.get(array, i); - assertEquals(x, VALUE_1, "get short value"); + assertEquals(VALUE_1, x, "get short value"); } if (iAligned) { @@ -767,21 +767,21 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); short x = (short) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile short value"); + assertEquals(VALUE_2, x, "setVolatile short value"); } // Lazy { vh.setRelease(array, i, VALUE_1); short x = (short) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease short value"); + assertEquals(VALUE_1, x, "setRelease short value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); short x = (short) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque short value"); + assertEquals(VALUE_2, x, "setOpaque short value"); } @@ -807,26 +807,26 @@ public class VarHandleTestByteArrayAsShort extends VarHandleBaseByteArrayTest { // Plain { short x = (short) vh.get(array, i); - assertEquals(x, v, "get short value"); + assertEquals(v, x, "get short value"); } if (iAligned) { // Volatile { short x = (short) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile short value"); + assertEquals(v, x, "getVolatile short value"); } // Lazy { short x = (short) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease short value"); + assertEquals(v, x, "getRelease short value"); } // Opaque { short x = (short) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque short value"); + assertEquals(v, x, "getOpaque short value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java index fc706815bce..9960e08a0c7 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestExact.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -26,20 +26,20 @@ * @modules java.base/jdk.internal.access.foreign * @modules java.base/jdk.internal.foreign.layout * - * @run testng/othervm -Xverify:all + * @run junit/othervm -Xverify:all * -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false * VarHandleTestExact - * @run testng/othervm -Xverify:all + * @run junit/othervm -Xverify:all * -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false * -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true * -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true * VarHandleTestExact - * @run testng/othervm -Xverify:all + * @run junit/othervm -Xverify:all * -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false * -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false * -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false * VarHandleTestExact - * @run testng/othervm -Xverify:all + * @run junit/othervm -Xverify:all * -Djdk.internal.foreign.SHOULD_ADAPT_HANDLES=false * -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false * -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true @@ -50,9 +50,6 @@ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import jdk.internal.foreign.layout.ValueLayouts; -import org.testng.SkipException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -64,8 +61,13 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestExact { private static class Widget { @@ -90,12 +92,13 @@ public class VarHandleTestExact { final Long aLongField_RO = 1234L; } - @Test(dataProvider = "dataObjectAccess") + @ParameterizedTest + @MethodSource("dataObjectAccess") public void testExactSet(String fieldBaseName, Class fieldType, boolean ro, Object testValue, SetX setter, GetX getter, SetStaticX staticSetter, GetStaticX staticGetter) throws NoSuchFieldException, IllegalAccessException { - if (ro) throw new SkipException("Can not test setter with read only field"); + Assumptions.assumeFalse(ro, "Can not test setter with read only field"); VarHandle vh = MethodHandles.lookup().findVarHandle(Widget.class, fieldBaseName + "_RW", fieldType); Widget w = new Widget(); @@ -105,7 +108,8 @@ public class VarHandleTestExact { ".*\\Qhandle's method type (Widget," + fieldType.getSimpleName() + ")void \\E.*"); } - @Test(dataProvider = "dataObjectAccess") + @ParameterizedTest + @MethodSource("dataObjectAccess") public void testExactGet(String fieldBaseName, Class fieldType, boolean ro, Object testValue, SetX setter, GetX getter, SetStaticX staticSetter, GetStaticX staticGetter) @@ -119,12 +123,13 @@ public class VarHandleTestExact { ".*\\Qhandle's method type (Widget)" + fieldType.getSimpleName() + " \\E.*"); } - @Test(dataProvider = "dataObjectAccess") + @ParameterizedTest + @MethodSource("dataObjectAccess") public void testExactSetStatic(String fieldBaseName, Class fieldType, boolean ro, Object testValue, SetX setter, GetX getter, SetStaticX staticSetter, GetStaticX staticGetter) throws NoSuchFieldException, IllegalAccessException { - if (ro) throw new SkipException("Can not test setter with read only field"); + Assumptions.assumeFalse(ro, "Can not test setter with read only field"); VarHandle vh = MethodHandles.lookup().findStaticVarHandle(Widget.class, fieldBaseName + "_SRW", fieldType); doTest(vh, @@ -133,7 +138,8 @@ public class VarHandleTestExact { ".*\\Qhandle's method type (" + fieldType.getSimpleName() + ")void \\E.*"); } - @Test(dataProvider = "dataObjectAccess") + @ParameterizedTest + @MethodSource("dataObjectAccess") public void testExactGetStatic(String fieldBaseName, Class fieldType, boolean ro, Object testValue, SetX setter, GetX getter, SetStaticX staticSetter, GetStaticX staticGetter) @@ -146,7 +152,8 @@ public class VarHandleTestExact { ".*\\Qhandle's method type ()" + fieldType.getSimpleName() + " \\E.*"); } - @Test(dataProvider = "dataSetArray") + @ParameterizedTest + @MethodSource("dataSetArray") public void testExactArraySet(Class arrayClass, Object testValue, SetArrayX setter) { VarHandle vh = MethodHandles.arrayElementVarHandle(arrayClass); Object arr = Array.newInstance(arrayClass.componentType(), 1); @@ -157,7 +164,8 @@ public class VarHandleTestExact { ".*\\Qhandle's method type (" + arrayClass.getSimpleName() + ",int," + arrayClass.componentType().getSimpleName() + ")void \\E.*"); } - @Test(dataProvider = "dataSetBuffer") + @ParameterizedTest + @MethodSource("dataSetBuffer") public void testExactBufferSet(Class arrayClass, Object testValue, SetBufferX setter) { VarHandle vh = MethodHandles.byteBufferViewVarHandle(arrayClass, ByteOrder.nativeOrder()); ByteBuffer buff = ByteBuffer.allocateDirect(8); @@ -168,7 +176,8 @@ public class VarHandleTestExact { ".*\\Qhandle's method type (ByteBuffer,int," + arrayClass.componentType().getSimpleName() + ")void \\E.*"); } - @Test(dataProvider = "dataSetMemorySegment") + @ParameterizedTest + @MethodSource("dataSetMemorySegment") public void testExactSegmentSet(Class carrier, Object testValue, SetSegmentX setter) { VarHandle vh = ValueLayouts.valueLayout(carrier, ByteOrder.nativeOrder()).varHandle(); try (Arena arena = Arena.ofConfined()) { @@ -265,7 +274,6 @@ public class VarHandleTestExact { cases.add(new Object[] { carrier, testValue, setter }); } - @DataProvider public static Object[][] dataObjectAccess() { List cases = new ArrayList<>(); @@ -334,7 +342,6 @@ public class VarHandleTestExact { return cases.toArray(Object[][]::new); } - @DataProvider public static Object[][] dataSetArray() { List cases = new ArrayList<>(); @@ -355,7 +362,6 @@ public class VarHandleTestExact { return cases.toArray(Object[][]::new); } - @DataProvider public static Object[][] dataSetBuffer() { List cases = new ArrayList<>(); @@ -373,7 +379,6 @@ public class VarHandleTestExact { return cases.toArray(Object[][]::new); } - @DataProvider public static Object[][] dataSetMemorySegment() { List cases = new ArrayList<>(); diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java index 14d5c05d3b8..6540693a906 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessBoolean + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessBoolean */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { static final boolean static_final_v = true; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessBoolean.class, "final_v", boolean.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(boolean[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessBoolean recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "set boolean value"); + assertEquals(true, x, "set boolean value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, false); boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, false, "setVolatile boolean value"); + assertEquals(false, x, "setVolatile boolean value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, true); boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, true, "setRelease boolean value"); + assertEquals(true, x, "setRelease boolean value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, false); boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, false, "setOpaque boolean value"); + assertEquals(false, x, "setOpaque boolean value"); } hs.get(TestAccessMode.SET).invokeExact(recv, true); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false); assertEquals(r, true, "success compareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "success compareAndSet boolean value"); + assertEquals(false, x, "success compareAndSet boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, true, false); assertEquals(r, false, "failing compareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "failing compareAndSet boolean value"); + assertEquals(false, x, "failing compareAndSet boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, true); assertEquals(r, false, "success compareAndExchange boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "success compareAndExchange boolean value"); + assertEquals(true, x, "success compareAndExchange boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, false, false); assertEquals(r, true, "failing compareAndExchange boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "failing compareAndExchange boolean value"); + assertEquals(true, x, "failing compareAndExchange boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false); assertEquals(r, true, "success compareAndExchangeAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "success compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, true, false); assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "failing compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, true); assertEquals(r, false, "success compareAndExchangeRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "success compareAndExchangeRelease boolean value"); + assertEquals(true, x, "success compareAndExchangeRelease boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, false, false); assertEquals(r, true, "failing compareAndExchangeRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); + assertEquals(true, x, "failing compareAndExchangeRelease boolean value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "success weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "success weakCompareAndSetPlain boolean value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, true, false); assertEquals(success, false, "failing weakCompareAndSetPlain boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "failing weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "failing weakCompareAndSetPlain boolean value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "success weakCompareAndSetAcquire boolean"); + assertEquals(true, x, "success weakCompareAndSetAcquire boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, false, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "success weakCompareAndSetRelease boolean"); + assertEquals(false, x, "success weakCompareAndSetRelease boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, true, false); assertEquals(success, false, "failing weakCompareAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "failing weakCompareAndSetRelease boolean value"); + assertEquals(false, x, "failing weakCompareAndSetRelease boolean value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "success weakCompareAndSet boolean"); + assertEquals(true, x, "success weakCompareAndSet boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, false, false); assertEquals(success, false, "failing weakCompareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, true, "failing weakCompareAndSet boolean value"); + assertEquals(true, x, "failing weakCompareAndSet boolean value"); } // Compare set and get { boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, false); - assertEquals(o, true, "getAndSet boolean"); + assertEquals(true, o, "getAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, false, "getAndSet boolean value"); + assertEquals(false, x, "getAndSet boolean value"); } @@ -300,27 +298,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseOr boolean"); + assertEquals(true, o, "getAndBitwiseOr boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseOrAcquire boolean"); + assertEquals(true, o, "getAndBitwiseOrAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseOrRelease boolean"); + assertEquals(true, o, "getAndBitwiseOrRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value"); } // get and bitwise and @@ -328,27 +326,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseAnd boolean"); + assertEquals(true, o, "getAndBitwiseAnd boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseAndAcquire boolean"); + assertEquals(true, o, "getAndBitwiseAndAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseAndRelease boolean"); + assertEquals(true, o, "getAndBitwiseAndRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value"); } // get and bitwise xor @@ -356,27 +354,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseXor boolean"); + assertEquals(true, o, "getAndBitwiseXor boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseXorAcquire boolean"); + assertEquals(true, o, "getAndBitwiseXorAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, false); - assertEquals(o, true, "getAndBitwiseXorRelease boolean"); + assertEquals(true, o, "getAndBitwiseXorRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value"); } } @@ -396,7 +394,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(true); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "set boolean value"); + assertEquals(true, x, "set boolean value"); } @@ -404,21 +402,21 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(false); boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, false, "setVolatile boolean value"); + assertEquals(false, x, "setVolatile boolean value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(true); boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, true, "setRelease boolean value"); + assertEquals(true, x, "setRelease boolean value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(false); boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, false, "setOpaque boolean value"); + assertEquals(false, x, "setOpaque boolean value"); } hs.get(TestAccessMode.SET).invokeExact(true); @@ -428,56 +426,56 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false); assertEquals(r, true, "success compareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "success compareAndSet boolean value"); + assertEquals(false, x, "success compareAndSet boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(true, false); assertEquals(r, false, "failing compareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "failing compareAndSet boolean value"); + assertEquals(false, x, "failing compareAndSet boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, true); assertEquals(r, false, "success compareAndExchange boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "success compareAndExchange boolean value"); + assertEquals(true, x, "success compareAndExchange boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(false, false); assertEquals(r, true, "failing compareAndExchange boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "failing compareAndExchange boolean value"); + assertEquals(true, x, "failing compareAndExchange boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false); assertEquals(r, true, "success compareAndExchangeAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "success compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(true, false); assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "failing compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, true); assertEquals(r, false, "success compareAndExchangeRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "success compareAndExchangeRelease boolean value"); + assertEquals(true, x, "success compareAndExchangeRelease boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(false, false); assertEquals(r, true, "failing compareAndExchangeRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); + assertEquals(true, x, "failing compareAndExchangeRelease boolean value"); } { @@ -489,14 +487,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "success weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "success weakCompareAndSetPlain boolean value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(true, false); assertEquals(success, false, "failing weakCompareAndSetPlain boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "failing weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "failing weakCompareAndSetPlain boolean value"); } { @@ -508,7 +506,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "success weakCompareAndSetAcquire boolean"); + assertEquals(true, x, "success weakCompareAndSetAcquire boolean"); } { @@ -516,7 +514,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact(false, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -528,14 +526,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "success weakCompareAndSetRelease boolean"); + assertEquals(false, x, "success weakCompareAndSetRelease boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(true, false); assertEquals(success, false, "failing weakCompareAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "failing weakCompareAndSetRelease boolean value"); + assertEquals(false, x, "failing weakCompareAndSetRelease boolean value"); } { @@ -547,14 +545,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "success weakCompareAndSet boolean"); + assertEquals(true, x, "success weakCompareAndSet boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(false, false); assertEquals(success, false, "failing weakCompareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, true, "failing weakCompareAndSetRe boolean value"); + assertEquals(true, x, "failing weakCompareAndSetRe boolean value"); } // Compare set and get @@ -562,9 +560,9 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(false); - assertEquals(o, true, "getAndSet boolean"); + assertEquals(true, o, "getAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "getAndSet boolean value"); + assertEquals(false, x, "getAndSet boolean value"); } // Compare set and get @@ -572,9 +570,9 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(false); - assertEquals(o, true, "getAndSetAcquire boolean"); + assertEquals(true, o, "getAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "getAndSetAcquire boolean value"); + assertEquals(false, x, "getAndSetAcquire boolean value"); } // Compare set and get @@ -582,9 +580,9 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(false); - assertEquals(o, true, "getAndSetRelease boolean"); + assertEquals(true, o, "getAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, false, "getAndSetRelease boolean value"); + assertEquals(false, x, "getAndSetRelease boolean value"); } @@ -593,27 +591,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(false); - assertEquals(o, true, "getAndBitwiseOr boolean"); + assertEquals(true, o, "getAndBitwiseOr boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(false); - assertEquals(o, true, "getAndBitwiseOrAcquire boolean"); + assertEquals(true, o, "getAndBitwiseOrAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(false); - assertEquals(o, true, "getAndBitwiseOrRelease boolean"); + assertEquals(true, o, "getAndBitwiseOrRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value"); } // get and bitwise and @@ -621,27 +619,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(false); - assertEquals(o, true, "getAndBitwiseAnd boolean"); + assertEquals(true, o, "getAndBitwiseAnd boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(false); - assertEquals(o, true, "getAndBitwiseAndAcquire boolean"); + assertEquals(true, o, "getAndBitwiseAndAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(false); - assertEquals(o, true, "getAndBitwiseAndRelease boolean"); + assertEquals(true, o, "getAndBitwiseAndRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value"); } // get and bitwise xor @@ -649,27 +647,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(false); - assertEquals(o, true, "getAndBitwiseXor boolean"); + assertEquals(true, o, "getAndBitwiseXor boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(false); - assertEquals(o, true, "getAndBitwiseXorAcquire boolean"); + assertEquals(true, o, "getAndBitwiseXorAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(false); - assertEquals(o, true, "getAndBitwiseXorRelease boolean"); + assertEquals(true, o, "getAndBitwiseXorRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value"); } } @@ -692,7 +690,7 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "get boolean value"); + assertEquals(true, x, "get boolean value"); } @@ -700,21 +698,21 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, false); boolean x = (boolean) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, false, "setVolatile boolean value"); + assertEquals(false, x, "setVolatile boolean value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, true); boolean x = (boolean) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, true, "setRelease boolean value"); + assertEquals(true, x, "setRelease boolean value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, false); boolean x = (boolean) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, false, "setOpaque boolean value"); + assertEquals(false, x, "setOpaque boolean value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, true); @@ -724,56 +722,56 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false); assertEquals(r, true, "success compareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "success compareAndSet boolean value"); + assertEquals(false, x, "success compareAndSet boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, true, false); assertEquals(r, false, "failing compareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "failing compareAndSet boolean value"); + assertEquals(false, x, "failing compareAndSet boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, true); assertEquals(r, false, "success compareAndExchange boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "success compareAndExchange boolean value"); + assertEquals(true, x, "success compareAndExchange boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, false, false); assertEquals(r, true, "failing compareAndExchange boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "failing compareAndExchange boolean value"); + assertEquals(true, x, "failing compareAndExchange boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false); assertEquals(r, true, "success compareAndExchangeAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "success compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "success compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, true, false); assertEquals(r, false, "failing compareAndExchangeAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "failing compareAndExchangeAcquire boolean value"); + assertEquals(false, x, "failing compareAndExchangeAcquire boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, true); assertEquals(r, false, "success compareAndExchangeRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "success compareAndExchangeRelease boolean value"); + assertEquals(true, x, "success compareAndExchangeRelease boolean value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, false, false); assertEquals(r, true, "failing compareAndExchangeRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "failing compareAndExchangeRelease boolean value"); + assertEquals(true, x, "failing compareAndExchangeRelease boolean value"); } { @@ -785,14 +783,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "success weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "success weakCompareAndSetPlain boolean value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, true, false); assertEquals(success, false, "failing weakCompareAndSetPlain boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "failing weakCompareAndSetPlain boolean value"); + assertEquals(false, x, "failing weakCompareAndSetPlain boolean value"); } { @@ -804,14 +802,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "success weakCompareAndSetAcquire boolean"); + assertEquals(true, x, "success weakCompareAndSetAcquire boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, false, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(true, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -823,14 +821,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "success weakCompareAndSetRelease boolean"); + assertEquals(false, x, "success weakCompareAndSetRelease boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, true, false); assertEquals(success, false, "failing weakCompareAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "failing weakCompareAndSetAcquire boolean value"); + assertEquals(false, x, "failing weakCompareAndSetAcquire boolean value"); } { @@ -842,14 +840,14 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "success weakCompareAndSet boolean"); + assertEquals(true, x, "success weakCompareAndSet boolean"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, false, false); assertEquals(success, false, "failing weakCompareAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, true, "failing weakCompareAndSet boolean value"); + assertEquals(true, x, "failing weakCompareAndSet boolean value"); } // Compare set and get @@ -857,27 +855,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, false); - assertEquals(o, true, "getAndSet boolean"); + assertEquals(true, o, "getAndSet boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "getAndSet boolean value"); + assertEquals(false, x, "getAndSet boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, false); - assertEquals(o, true, "getAndSetAcquire boolean"); + assertEquals(true, o, "getAndSetAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "getAndSetAcquire boolean value"); + assertEquals(false, x, "getAndSetAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, false); - assertEquals(o, true, "getAndSetRelease boolean"); + assertEquals(true, o, "getAndSetRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, false, "getAndSetRelease boolean value"); + assertEquals(false, x, "getAndSetRelease boolean value"); } @@ -886,27 +884,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseOr boolean"); + assertEquals(true, o, "getAndBitwiseOr boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOr boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOr boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseOrAcquire boolean"); + assertEquals(true, o, "getAndBitwiseOrAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrAcquire boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseOrRelease boolean"); + assertEquals(true, o, "getAndBitwiseOrRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true | false), "getAndBitwiseOrRelease boolean value"); + assertEquals((boolean)(true | false), x, "getAndBitwiseOrRelease boolean value"); } // get and bitwise and @@ -914,27 +912,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseAnd boolean"); + assertEquals(true, o, "getAndBitwiseAnd boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAnd boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAnd boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseAndAcquire boolean"); + assertEquals(true, o, "getAndBitwiseAndAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndAcquire boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseAndRelease boolean"); + assertEquals(true, o, "getAndBitwiseAndRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true & false), "getAndBitwiseAndRelease boolean value"); + assertEquals((boolean)(true & false), x, "getAndBitwiseAndRelease boolean value"); } // get and bitwise xor @@ -942,27 +940,27 @@ public class VarHandleTestMethodHandleAccessBoolean extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseXor boolean"); + assertEquals(true, o, "getAndBitwiseXor boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXor boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXor boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseXorAcquire boolean"); + assertEquals(true, o, "getAndBitwiseXorAcquire boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorAcquire boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorAcquire boolean value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, true); boolean o = (boolean) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, false); - assertEquals(o, true, "getAndBitwiseXorRelease boolean"); + assertEquals(true, o, "getAndBitwiseXorRelease boolean"); boolean x = (boolean) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (boolean)(true ^ false), "getAndBitwiseXorRelease boolean value"); + assertEquals((boolean)(true ^ false), x, "getAndBitwiseXorRelease boolean value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java index 5b3eafba63b..6f7f54a57f5 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessByte + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessByte */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { static final byte static_final_v = (byte)0x01; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessByte.class, "final_v", byte.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(byte[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "set byte value"); + assertEquals((byte)0x01, x, "set byte value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)0x23); byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, (byte)0x23, "setVolatile byte value"); + assertEquals((byte)0x23, x, "setVolatile byte value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)0x01); byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, (byte)0x01, "setRelease byte value"); + assertEquals((byte)0x01, x, "setRelease byte value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)0x23); byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, (byte)0x23, "setOpaque byte value"); + assertEquals((byte)0x23, x, "setOpaque byte value"); } hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23); assertEquals(r, true, "success compareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "success compareAndSet byte value"); + assertEquals((byte)0x23, x, "success compareAndSet byte value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45); assertEquals(r, false, "failing compareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); + assertEquals((byte)0x23, x, "failing compareAndSet byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchange byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); + assertEquals((byte)0x01, x, "success compareAndExchange byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchange byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23); assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "success compareAndExchangeAcquire byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45); assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "failing compareAndExchangeAcquire byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "success compareAndExchangeRelease byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchangeRelease byte value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "success weakCompareAndSetPlain byte value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetPlain byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetPlain byte value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSetAcquire byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte"); + assertEquals((byte)0x23, x, "success weakCompareAndSetRelease byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetRelease byte value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "success weakCompareAndSet byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSet byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSet byte value"); } // Compare set and get { byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSet byte"); + assertEquals((byte)0x01, o, "getAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)0x23, "getAndSet byte value"); + assertEquals((byte)0x23, x, "getAndSet byte value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAdd byte"); + assertEquals((byte)0x01, o, "getAndAdd byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAdd byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); + assertEquals((byte)0x01, o, "getAndAddAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddRelease byte"); + assertEquals((byte)0x01, o, "getAndAddRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddRelease byte value"); } // get and bitwise or @@ -327,27 +325,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOr byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOr byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrRelease byte value"); } // get and bitwise and @@ -355,27 +353,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAnd byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAnd byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndRelease byte value"); } // get and bitwise xor @@ -383,27 +381,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXor byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXor byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorRelease byte value"); } } @@ -418,7 +416,7 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "set byte value"); + assertEquals((byte)0x01, x, "set byte value"); } @@ -426,21 +424,21 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)0x23); byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, (byte)0x23, "setVolatile byte value"); + assertEquals((byte)0x23, x, "setVolatile byte value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)0x01); byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, (byte)0x01, "setRelease byte value"); + assertEquals((byte)0x01, x, "setRelease byte value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)0x23); byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, (byte)0x23, "setOpaque byte value"); + assertEquals((byte)0x23, x, "setOpaque byte value"); } hs.get(TestAccessMode.SET).invokeExact((byte)0x01); @@ -450,56 +448,56 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23); assertEquals(r, true, "success compareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "success compareAndSet byte value"); + assertEquals((byte)0x23, x, "success compareAndSet byte value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45); assertEquals(r, false, "failing compareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); + assertEquals((byte)0x23, x, "failing compareAndSet byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchange byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); + assertEquals((byte)0x01, x, "success compareAndExchange byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchange byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23); assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "success compareAndExchangeAcquire byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45); assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "failing compareAndExchangeAcquire byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "success compareAndExchangeRelease byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchangeRelease byte value"); } { @@ -511,14 +509,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "success weakCompareAndSetPlain byte value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetPlain byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetPlain byte value"); } { @@ -530,7 +528,7 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSetAcquire byte"); } { @@ -538,7 +536,7 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact((byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -550,14 +548,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte"); + assertEquals((byte)0x23, x, "success weakCompareAndSetRelease byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetRelease byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetRelease byte value"); } { @@ -569,14 +567,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "success weakCompareAndSet byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSet byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetRe byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetRe byte value"); } // Compare set and get @@ -584,9 +582,9 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndSet byte"); + assertEquals((byte)0x01, o, "getAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "getAndSet byte value"); + assertEquals((byte)0x23, x, "getAndSet byte value"); } // Compare set and get @@ -594,9 +592,9 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); + assertEquals((byte)0x01, o, "getAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); + assertEquals((byte)0x23, x, "getAndSetAcquire byte value"); } // Compare set and get @@ -604,9 +602,9 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetRelease byte"); + assertEquals((byte)0x01, o, "getAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); + assertEquals((byte)0x23, x, "getAndSetRelease byte value"); } // get and add, add and get @@ -614,27 +612,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndAdd byte"); + assertEquals((byte)0x01, o, "getAndAdd byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAdd byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); + assertEquals((byte)0x01, o, "getAndAddAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddRelease byte"); + assertEquals((byte)0x01, o, "getAndAddRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddRelease byte value"); } // get and bitwise or @@ -642,27 +640,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOr byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOr byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrRelease byte value"); } // get and bitwise and @@ -670,27 +668,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAnd byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAnd byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndRelease byte value"); } // get and bitwise xor @@ -698,27 +696,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXor byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXor byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact((byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorRelease byte value"); } } @@ -736,7 +734,7 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "get byte value"); + assertEquals((byte)0x01, x, "get byte value"); } @@ -744,21 +742,21 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)0x23); byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, (byte)0x23, "setVolatile byte value"); + assertEquals((byte)0x23, x, "setVolatile byte value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)0x01); byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, (byte)0x01, "setRelease byte value"); + assertEquals((byte)0x01, x, "setRelease byte value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)0x23); byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, (byte)0x23, "setOpaque byte value"); + assertEquals((byte)0x23, x, "setOpaque byte value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); @@ -768,56 +766,56 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23); assertEquals(r, true, "success compareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "success compareAndSet byte value"); + assertEquals((byte)0x23, x, "success compareAndSet byte value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45); assertEquals(r, false, "failing compareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); + assertEquals((byte)0x23, x, "failing compareAndSet byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchange byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "success compareAndExchange byte value"); + assertEquals((byte)0x01, x, "success compareAndExchange byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchange byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "failing compareAndExchange byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchange byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23); assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "success compareAndExchangeAcquire byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45); assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); + assertEquals((byte)0x23, x, "failing compareAndExchangeAcquire byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01); assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "success compareAndExchangeRelease byte value"); } { byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45); assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); + assertEquals((byte)0x01, x, "failing compareAndExchangeRelease byte value"); } { @@ -829,14 +827,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "success weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "success weakCompareAndSetPlain byte value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetPlain byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetPlain byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetPlain byte value"); } { @@ -848,14 +846,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "success weakCompareAndSetAcquire byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSetAcquire byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -867,14 +865,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "success weakCompareAndSetRelease byte"); + assertEquals((byte)0x23, x, "success weakCompareAndSetRelease byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "failing weakCompareAndSetAcquire byte value"); + assertEquals((byte)0x23, x, "failing weakCompareAndSetAcquire byte value"); } { @@ -886,14 +884,14 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "success weakCompareAndSet byte"); + assertEquals((byte)0x01, x, "success weakCompareAndSet byte"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (byte)0x23, (byte)0x45); assertEquals(success, false, "failing weakCompareAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x01, "failing weakCompareAndSet byte value"); + assertEquals((byte)0x01, x, "failing weakCompareAndSet byte value"); } // Compare set and get @@ -901,27 +899,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSet byte"); + assertEquals((byte)0x01, o, "getAndSet byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "getAndSet byte value"); + assertEquals((byte)0x23, x, "getAndSet byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetAcquire byte"); + assertEquals((byte)0x01, o, "getAndSetAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "getAndSetAcquire byte value"); + assertEquals((byte)0x23, x, "getAndSetAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndSetRelease byte"); + assertEquals((byte)0x01, o, "getAndSetRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)0x23, "getAndSetRelease byte value"); + assertEquals((byte)0x23, x, "getAndSetRelease byte value"); } // get and add, add and get @@ -929,27 +927,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAdd byte"); + assertEquals((byte)0x01, o, "getAndAdd byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAdd byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAdd byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddAcquire byte"); + assertEquals((byte)0x01, o, "getAndAddAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddAcquire byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndAddRelease byte"); + assertEquals((byte)0x01, o, "getAndAddRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 + (byte)0x23), "getAndAddRelease byte value"); + assertEquals((byte)((byte)0x01 + (byte)0x23), x, "getAndAddRelease byte value"); } // get and bitwise or @@ -957,27 +955,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOr byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOr byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOr byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOr byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrAcquire byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseOrRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseOrRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 | (byte)0x23), "getAndBitwiseOrRelease byte value"); + assertEquals((byte)((byte)0x01 | (byte)0x23), x, "getAndBitwiseOrRelease byte value"); } // get and bitwise and @@ -985,27 +983,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAnd byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAnd byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAnd byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAnd byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndAcquire byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseAndRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseAndRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 & (byte)0x23), "getAndBitwiseAndRelease byte value"); + assertEquals((byte)((byte)0x01 & (byte)0x23), x, "getAndBitwiseAndRelease byte value"); } // get and bitwise xor @@ -1013,27 +1011,27 @@ public class VarHandleTestMethodHandleAccessByte extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXor byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXor byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXor byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXor byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorAcquire byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorAcquire byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorAcquire byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorAcquire byte value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); byte o = (byte) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (byte)0x23); - assertEquals(o, (byte)0x01, "getAndBitwiseXorRelease byte"); + assertEquals((byte)0x01, o, "getAndBitwiseXorRelease byte"); byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (byte)((byte)0x01 ^ (byte)0x23), "getAndBitwiseXorRelease byte value"); + assertEquals((byte)((byte)0x01 ^ (byte)0x23), x, "getAndBitwiseXorRelease byte value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java index d191b507366..3e31ee282ff 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessChar + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessChar */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { static final char static_final_v = '\u0123'; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessChar.class, "final_v", char.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(char[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessChar recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "set char value"); + assertEquals('\u0123', x, "set char value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, '\u4567', "setVolatile char value"); + assertEquals('\u4567', x, "setVolatile char value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, '\u0123'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, '\u0123', "setRelease char value"); + assertEquals('\u0123', x, "setRelease char value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, '\u4567', "setOpaque char value"); + assertEquals('\u4567', x, "setOpaque char value"); } hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u4567'); assertEquals(r, true, "success compareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "success compareAndSet char value"); + assertEquals('\u4567', x, "success compareAndSet char value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, '\u0123', '\u89AB'); assertEquals(r, false, "failing compareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "failing compareAndSet char value"); + assertEquals('\u4567', x, "failing compareAndSet char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchange char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "success compareAndExchange char value"); + assertEquals('\u0123', x, "success compareAndExchange char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchange char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "failing compareAndExchange char value"); + assertEquals('\u0123', x, "failing compareAndExchange char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u4567'); assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "success compareAndExchangeAcquire char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, '\u0123', '\u89AB'); assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "failing compareAndExchangeAcquire char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "success compareAndExchangeRelease char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "failing compareAndExchangeRelease char value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "success weakCompareAndSetPlain char value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetPlain char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetPlain char value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); + assertEquals('\u0123', x, "success weakCompareAndSetAcquire char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetAcquire char value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); + assertEquals('\u4567', x, "success weakCompareAndSetRelease char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetRelease char value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "success weakCompareAndSet char"); + assertEquals('\u0123', x, "success weakCompareAndSet char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); + assertEquals('\u0123', x, "failing weakCompareAndSet char value"); } // Compare set and get { char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndSet char"); + assertEquals('\u0123', o, "getAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, '\u4567', "getAndSet char value"); + assertEquals('\u4567', x, "getAndSet char value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndAdd char"); + assertEquals('\u0123', o, "getAndAdd char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAdd char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndAddAcquire char"); + assertEquals('\u0123', o, "getAndAddAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndAddRelease char"); + assertEquals('\u0123', o, "getAndAddRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddRelease char value"); } // get and bitwise or @@ -327,27 +325,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOr char"); + assertEquals('\u0123', o, "getAndBitwiseOr char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOr char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseOrAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); + assertEquals('\u0123', o, "getAndBitwiseOrRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrRelease char value"); } // get and bitwise and @@ -355,27 +353,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAnd char"); + assertEquals('\u0123', o, "getAndBitwiseAnd char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAnd char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseAndAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); + assertEquals('\u0123', o, "getAndBitwiseAndRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndRelease char value"); } // get and bitwise xor @@ -383,27 +381,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXor char"); + assertEquals('\u0123', o, "getAndBitwiseXor char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXor char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseXorAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); + assertEquals('\u0123', o, "getAndBitwiseXorRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorRelease char value"); } } @@ -418,7 +416,7 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "set char value"); + assertEquals('\u0123', x, "set char value"); } @@ -426,21 +424,21 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact('\u4567'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, '\u4567', "setVolatile char value"); + assertEquals('\u4567', x, "setVolatile char value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact('\u0123'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, '\u0123', "setRelease char value"); + assertEquals('\u0123', x, "setRelease char value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact('\u4567'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, '\u4567', "setOpaque char value"); + assertEquals('\u4567', x, "setOpaque char value"); } hs.get(TestAccessMode.SET).invokeExact('\u0123'); @@ -450,56 +448,56 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u4567'); assertEquals(r, true, "success compareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "success compareAndSet char value"); + assertEquals('\u4567', x, "success compareAndSet char value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact('\u0123', '\u89AB'); assertEquals(r, false, "failing compareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "failing compareAndSet char value"); + assertEquals('\u4567', x, "failing compareAndSet char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact('\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchange char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "success compareAndExchange char value"); + assertEquals('\u0123', x, "success compareAndExchange char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact('\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchange char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "failing compareAndExchange char value"); + assertEquals('\u0123', x, "failing compareAndExchange char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u4567'); assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "success compareAndExchangeAcquire char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact('\u0123', '\u89AB'); assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "failing compareAndExchangeAcquire char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "success compareAndExchangeRelease char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact('\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "failing compareAndExchangeRelease char value"); } { @@ -511,14 +509,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "success weakCompareAndSetPlain char value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact('\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetPlain char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetPlain char value"); } { @@ -530,7 +528,7 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); + assertEquals('\u0123', x, "success weakCompareAndSetAcquire char"); } { @@ -538,7 +536,7 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact('\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetAcquire char value"); } { @@ -550,14 +548,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); + assertEquals('\u4567', x, "success weakCompareAndSetRelease char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact('\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "failing weakCompareAndSetRelease char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetRelease char value"); } { @@ -569,14 +567,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "success weakCompareAndSet char"); + assertEquals('\u0123', x, "success weakCompareAndSet char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact('\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u0123', "failing weakCompareAndSetRe char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetRe char value"); } // Compare set and get @@ -584,9 +582,9 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndSet char"); + assertEquals('\u0123', o, "getAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "getAndSet char value"); + assertEquals('\u4567', x, "getAndSet char value"); } // Compare set and get @@ -594,9 +592,9 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndSetAcquire char"); + assertEquals('\u0123', o, "getAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "getAndSetAcquire char value"); + assertEquals('\u4567', x, "getAndSetAcquire char value"); } // Compare set and get @@ -604,9 +602,9 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndSetRelease char"); + assertEquals('\u0123', o, "getAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, '\u4567', "getAndSetRelease char value"); + assertEquals('\u4567', x, "getAndSetRelease char value"); } // get and add, add and get @@ -614,27 +612,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndAdd char"); + assertEquals('\u0123', o, "getAndAdd char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAdd char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndAddAcquire char"); + assertEquals('\u0123', o, "getAndAddAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndAddRelease char"); + assertEquals('\u0123', o, "getAndAddRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddRelease char value"); } // get and bitwise or @@ -642,27 +640,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOr char"); + assertEquals('\u0123', o, "getAndBitwiseOr char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOr char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseOrAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); + assertEquals('\u0123', o, "getAndBitwiseOrRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrRelease char value"); } // get and bitwise and @@ -670,27 +668,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAnd char"); + assertEquals('\u0123', o, "getAndBitwiseAnd char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAnd char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseAndAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); + assertEquals('\u0123', o, "getAndBitwiseAndRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndRelease char value"); } // get and bitwise xor @@ -698,27 +696,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXor char"); + assertEquals('\u0123', o, "getAndBitwiseXor char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXor char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseXorAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact('\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact('\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); + assertEquals('\u0123', o, "getAndBitwiseXorRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorRelease char value"); } } @@ -736,7 +734,7 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "get char value"); + assertEquals('\u0123', x, "get char value"); } @@ -744,21 +742,21 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, '\u4567', "setVolatile char value"); + assertEquals('\u4567', x, "setVolatile char value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, '\u0123'); char x = (char) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, '\u0123', "setRelease char value"); + assertEquals('\u0123', x, "setRelease char value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, '\u4567'); char x = (char) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, '\u4567', "setOpaque char value"); + assertEquals('\u4567', x, "setOpaque char value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); @@ -768,56 +766,56 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u4567'); assertEquals(r, true, "success compareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "success compareAndSet char value"); + assertEquals('\u4567', x, "success compareAndSet char value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, '\u0123', '\u89AB'); assertEquals(r, false, "failing compareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "failing compareAndSet char value"); + assertEquals('\u4567', x, "failing compareAndSet char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchange char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "success compareAndExchange char value"); + assertEquals('\u0123', x, "success compareAndExchange char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchange char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "failing compareAndExchange char value"); + assertEquals('\u0123', x, "failing compareAndExchange char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u4567'); assertEquals(r, '\u0123', "success compareAndExchangeAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "success compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "success compareAndExchangeAcquire char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, '\u0123', '\u89AB'); assertEquals(r, '\u4567', "failing compareAndExchangeAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "failing compareAndExchangeAcquire char value"); + assertEquals('\u4567', x, "failing compareAndExchangeAcquire char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u0123'); assertEquals(r, '\u4567', "success compareAndExchangeRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "success compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "success compareAndExchangeRelease char value"); } { char r = (char) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, '\u4567', '\u89AB'); assertEquals(r, '\u0123', "failing compareAndExchangeRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "failing compareAndExchangeRelease char value"); + assertEquals('\u0123', x, "failing compareAndExchangeRelease char value"); } { @@ -829,14 +827,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "success weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "success weakCompareAndSetPlain char value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetPlain char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "failing weakCompareAndSetPlain char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetPlain char value"); } { @@ -848,14 +846,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "success weakCompareAndSetAcquire char"); + assertEquals('\u0123', x, "success weakCompareAndSetAcquire char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u0123', x, "failing weakCompareAndSetAcquire char value"); } { @@ -867,14 +865,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "success weakCompareAndSetRelease char"); + assertEquals('\u4567', x, "success weakCompareAndSetRelease char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, '\u0123', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "failing weakCompareAndSetAcquire char value"); + assertEquals('\u4567', x, "failing weakCompareAndSetAcquire char value"); } { @@ -886,14 +884,14 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "success weakCompareAndSet char"); + assertEquals('\u0123', x, "success weakCompareAndSet char"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, '\u4567', '\u89AB'); assertEquals(success, false, "failing weakCompareAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u0123', "failing weakCompareAndSet char value"); + assertEquals('\u0123', x, "failing weakCompareAndSet char value"); } // Compare set and get @@ -901,27 +899,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndSet char"); + assertEquals('\u0123', o, "getAndSet char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "getAndSet char value"); + assertEquals('\u4567', x, "getAndSet char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndSetAcquire char"); + assertEquals('\u0123', o, "getAndSetAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "getAndSetAcquire char value"); + assertEquals('\u4567', x, "getAndSetAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndSetRelease char"); + assertEquals('\u0123', o, "getAndSetRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, '\u4567', "getAndSetRelease char value"); + assertEquals('\u4567', x, "getAndSetRelease char value"); } // get and add, add and get @@ -929,27 +927,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndAdd char"); + assertEquals('\u0123', o, "getAndAdd char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAdd char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAdd char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndAddAcquire char"); + assertEquals('\u0123', o, "getAndAddAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddAcquire char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndAddRelease char"); + assertEquals('\u0123', o, "getAndAddRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' + '\u4567'), "getAndAddRelease char value"); + assertEquals((char)('\u0123' + '\u4567'), x, "getAndAddRelease char value"); } // get and bitwise or @@ -957,27 +955,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOr char"); + assertEquals('\u0123', o, "getAndBitwiseOr char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOr char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOr char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseOrAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrAcquire char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseOrRelease char"); + assertEquals('\u0123', o, "getAndBitwiseOrRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' | '\u4567'), "getAndBitwiseOrRelease char value"); + assertEquals((char)('\u0123' | '\u4567'), x, "getAndBitwiseOrRelease char value"); } // get and bitwise and @@ -985,27 +983,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAnd char"); + assertEquals('\u0123', o, "getAndBitwiseAnd char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAnd char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAnd char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseAndAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndAcquire char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseAndRelease char"); + assertEquals('\u0123', o, "getAndBitwiseAndRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' & '\u4567'), "getAndBitwiseAndRelease char value"); + assertEquals((char)('\u0123' & '\u4567'), x, "getAndBitwiseAndRelease char value"); } // get and bitwise xor @@ -1013,27 +1011,27 @@ public class VarHandleTestMethodHandleAccessChar extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXor char"); + assertEquals('\u0123', o, "getAndBitwiseXor char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXor char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXor char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorAcquire char"); + assertEquals('\u0123', o, "getAndBitwiseXorAcquire char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorAcquire char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorAcquire char value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, '\u0123'); char o = (char) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, '\u4567'); - assertEquals(o, '\u0123', "getAndBitwiseXorRelease char"); + assertEquals('\u0123', o, "getAndBitwiseXorRelease char"); char x = (char) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (char)('\u0123' ^ '\u4567'), "getAndBitwiseXorRelease char value"); + assertEquals((char)('\u0123' ^ '\u4567'), x, "getAndBitwiseXorRelease char value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java index fe0455d2375..056d45478ed 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessDouble + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessDouble */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { static final double static_final_v = 1.0d; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessDouble.class, "final_v", double.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(double[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessDouble recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "set double value"); + assertEquals(1.0d, x, "set double value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0d); double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, 2.0d, "setVolatile double value"); + assertEquals(2.0d, x, "setVolatile double value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0d); double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, 1.0d, "setRelease double value"); + assertEquals(1.0d, x, "setRelease double value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0d); double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, 2.0d, "setOpaque double value"); + assertEquals(2.0d, x, "setOpaque double value"); } hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 2.0d); assertEquals(r, true, "success compareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "success compareAndSet double value"); + assertEquals(2.0d, x, "success compareAndSet double value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0d, 3.0d); assertEquals(r, false, "failing compareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "failing compareAndSet double value"); + assertEquals(2.0d, x, "failing compareAndSet double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchange double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "success compareAndExchange double value"); + assertEquals(1.0d, x, "success compareAndExchange double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchange double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "failing compareAndExchange double value"); + assertEquals(1.0d, x, "failing compareAndExchange double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 2.0d); assertEquals(r, 1.0d, "success compareAndExchangeAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "success compareAndExchangeAcquire double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0d, 3.0d); assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchangeRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "success compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "success compareAndExchangeRelease double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchangeRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "failing compareAndExchangeRelease double value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "success weakCompareAndSetPlain double value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double"); + assertEquals(1.0d, x, "success weakCompareAndSetAcquire double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "success weakCompareAndSetRelease double"); + assertEquals(2.0d, x, "success weakCompareAndSetRelease double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "success weakCompareAndSet double"); + assertEquals(1.0d, x, "success weakCompareAndSet double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0d, "failing weakCompareAndSet double value"); + assertEquals(1.0d, x, "failing weakCompareAndSet double value"); } // Compare set and get { double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0d); - assertEquals(o, 1.0d, "getAndSet double"); + assertEquals(1.0d, o, "getAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0d, "getAndSet double value"); + assertEquals(2.0d, x, "getAndSet double value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0d); - assertEquals(o, 1.0d, "getAndAdd double"); + assertEquals(1.0d, o, "getAndAdd double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0d); - assertEquals(o, 1.0d, "getAndAddAcquire double"); + assertEquals(1.0d, o, "getAndAddAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0d); - assertEquals(o, 1.0d, "getAndAddRelease double"); + assertEquals(1.0d, o, "getAndAddRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value"); } } @@ -340,7 +338,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(1.0d); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "set double value"); + assertEquals(1.0d, x, "set double value"); } @@ -348,21 +346,21 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0d); double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, 2.0d, "setVolatile double value"); + assertEquals(2.0d, x, "setVolatile double value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0d); double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, 1.0d, "setRelease double value"); + assertEquals(1.0d, x, "setRelease double value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0d); double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, 2.0d, "setOpaque double value"); + assertEquals(2.0d, x, "setOpaque double value"); } hs.get(TestAccessMode.SET).invokeExact(1.0d); @@ -372,56 +370,56 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 2.0d); assertEquals(r, true, "success compareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "success compareAndSet double value"); + assertEquals(2.0d, x, "success compareAndSet double value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0d, 3.0d); assertEquals(r, false, "failing compareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "failing compareAndSet double value"); + assertEquals(2.0d, x, "failing compareAndSet double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchange double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "success compareAndExchange double value"); + assertEquals(1.0d, x, "success compareAndExchange double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchange double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "failing compareAndExchange double value"); + assertEquals(1.0d, x, "failing compareAndExchange double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 2.0d); assertEquals(r, 1.0d, "success compareAndExchangeAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "success compareAndExchangeAcquire double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0d, 3.0d); assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchangeRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "success compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "success compareAndExchangeRelease double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchangeRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "failing compareAndExchangeRelease double value"); } { @@ -433,14 +431,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "success weakCompareAndSetPlain double value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value"); } { @@ -452,7 +450,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double"); + assertEquals(1.0d, x, "success weakCompareAndSetAcquire double"); } { @@ -460,7 +458,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact(2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -472,14 +470,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "success weakCompareAndSetRelease double"); + assertEquals(2.0d, x, "success weakCompareAndSetRelease double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "failing weakCompareAndSetRelease double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetRelease double value"); } { @@ -491,14 +489,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "success weakCompareAndSet double"); + assertEquals(1.0d, x, "success weakCompareAndSet double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0d, "failing weakCompareAndSetRe double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetRe double value"); } // Compare set and get @@ -506,9 +504,9 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2.0d); - assertEquals(o, 1.0d, "getAndSet double"); + assertEquals(1.0d, o, "getAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "getAndSet double value"); + assertEquals(2.0d, x, "getAndSet double value"); } // Compare set and get @@ -516,9 +514,9 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0d); - assertEquals(o, 1.0d, "getAndSetAcquire double"); + assertEquals(1.0d, o, "getAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "getAndSetAcquire double value"); + assertEquals(2.0d, x, "getAndSetAcquire double value"); } // Compare set and get @@ -526,9 +524,9 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0d); - assertEquals(o, 1.0d, "getAndSetRelease double"); + assertEquals(1.0d, o, "getAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0d, "getAndSetRelease double value"); + assertEquals(2.0d, x, "getAndSetRelease double value"); } // get and add, add and get @@ -536,27 +534,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0d); - assertEquals(o, 1.0d, "getAndAdd double"); + assertEquals(1.0d, o, "getAndAdd double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value"); } { hs.get(TestAccessMode.SET).invokeExact(1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0d); - assertEquals(o, 1.0d, "getAndAddAcquire double"); + assertEquals(1.0d, o, "getAndAddAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value"); } { hs.get(TestAccessMode.SET).invokeExact(1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0d); - assertEquals(o, 1.0d, "getAndAddRelease double"); + assertEquals(1.0d, o, "getAndAddRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value"); } } @@ -580,7 +578,7 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "get double value"); + assertEquals(1.0d, x, "get double value"); } @@ -588,21 +586,21 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0d); double x = (double) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, 2.0d, "setVolatile double value"); + assertEquals(2.0d, x, "setVolatile double value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0d); double x = (double) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, 1.0d, "setRelease double value"); + assertEquals(1.0d, x, "setRelease double value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0d); double x = (double) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, 2.0d, "setOpaque double value"); + assertEquals(2.0d, x, "setOpaque double value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); @@ -612,56 +610,56 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 2.0d); assertEquals(r, true, "success compareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "success compareAndSet double value"); + assertEquals(2.0d, x, "success compareAndSet double value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0d, 3.0d); assertEquals(r, false, "failing compareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "failing compareAndSet double value"); + assertEquals(2.0d, x, "failing compareAndSet double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchange double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "success compareAndExchange double value"); + assertEquals(1.0d, x, "success compareAndExchange double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchange double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "failing compareAndExchange double value"); + assertEquals(1.0d, x, "failing compareAndExchange double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 2.0d); assertEquals(r, 1.0d, "success compareAndExchangeAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "success compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "success compareAndExchangeAcquire double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0d, 3.0d); assertEquals(r, 2.0d, "failing compareAndExchangeAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "failing compareAndExchangeAcquire double value"); + assertEquals(2.0d, x, "failing compareAndExchangeAcquire double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 1.0d); assertEquals(r, 2.0d, "success compareAndExchangeRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "success compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "success compareAndExchangeRelease double value"); } { double r = (double) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0d, 3.0d); assertEquals(r, 1.0d, "failing compareAndExchangeRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "failing compareAndExchangeRelease double value"); + assertEquals(1.0d, x, "failing compareAndExchangeRelease double value"); } { @@ -673,14 +671,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "success weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "success weakCompareAndSetPlain double value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetPlain double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "failing weakCompareAndSetPlain double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetPlain double value"); } { @@ -692,14 +690,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "success weakCompareAndSetAcquire double"); + assertEquals(1.0d, x, "success weakCompareAndSetAcquire double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(1.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -711,14 +709,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "success weakCompareAndSetRelease double"); + assertEquals(2.0d, x, "success weakCompareAndSetRelease double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 1.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "failing weakCompareAndSetAcquire double value"); + assertEquals(2.0d, x, "failing weakCompareAndSetAcquire double value"); } { @@ -730,14 +728,14 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "success weakCompareAndSet double"); + assertEquals(1.0d, x, "success weakCompareAndSet double"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 2.0d, 3.0d); assertEquals(success, false, "failing weakCompareAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0d, "failing weakCompareAndSet double value"); + assertEquals(1.0d, x, "failing weakCompareAndSet double value"); } // Compare set and get @@ -745,27 +743,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndSet double"); + assertEquals(1.0d, o, "getAndSet double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "getAndSet double value"); + assertEquals(2.0d, x, "getAndSet double value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndSetAcquire double"); + assertEquals(1.0d, o, "getAndSetAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "getAndSetAcquire double value"); + assertEquals(2.0d, x, "getAndSetAcquire double value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndSetRelease double"); + assertEquals(1.0d, o, "getAndSetRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0d, "getAndSetRelease double value"); + assertEquals(2.0d, x, "getAndSetRelease double value"); } // get and add, add and get @@ -773,27 +771,27 @@ public class VarHandleTestMethodHandleAccessDouble extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndAdd double"); + assertEquals(1.0d, o, "getAndAdd double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAdd double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAdd double value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndAddAcquire double"); + assertEquals(1.0d, o, "getAndAddAcquire double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddAcquire double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddAcquire double value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0d); double o = (double) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0d); - assertEquals(o, 1.0d, "getAndAddRelease double"); + assertEquals(1.0d, o, "getAndAddRelease double"); double x = (double) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (double)(1.0d + 2.0d), "getAndAddRelease double value"); + assertEquals((double)(1.0d + 2.0d), x, "getAndAddRelease double value"); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java index 256e4723eec..98eb72301cb 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessFloat + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessFloat */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { static final float static_final_v = 1.0f; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessFloat.class, "final_v", float.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(float[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessFloat recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "set float value"); + assertEquals(1.0f, x, "set float value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 2.0f); float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, 2.0f, "setVolatile float value"); + assertEquals(2.0f, x, "setVolatile float value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 1.0f); float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, 1.0f, "setRelease float value"); + assertEquals(1.0f, x, "setRelease float value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 2.0f); float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, 2.0f, "setOpaque float value"); + assertEquals(2.0f, x, "setOpaque float value"); } hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 2.0f); assertEquals(r, true, "success compareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "success compareAndSet float value"); + assertEquals(2.0f, x, "success compareAndSet float value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 1.0f, 3.0f); assertEquals(r, false, "failing compareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "failing compareAndSet float value"); + assertEquals(2.0f, x, "failing compareAndSet float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchange float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "success compareAndExchange float value"); + assertEquals(1.0f, x, "success compareAndExchange float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchange float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "failing compareAndExchange float value"); + assertEquals(1.0f, x, "failing compareAndExchange float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 2.0f); assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "success compareAndExchangeAcquire float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 1.0f, 3.0f); assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "success compareAndExchangeRelease float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "failing compareAndExchangeRelease float value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "success weakCompareAndSetPlain float value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float"); + assertEquals(1.0f, x, "success weakCompareAndSetAcquire float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "success weakCompareAndSetRelease float"); + assertEquals(2.0f, x, "success weakCompareAndSetRelease float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "success weakCompareAndSet float"); + assertEquals(1.0f, x, "success weakCompareAndSet float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 1.0f, "failing weakCompareAndSet float value"); + assertEquals(1.0f, x, "failing weakCompareAndSet float value"); } // Compare set and get { float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 2.0f); - assertEquals(o, 1.0f, "getAndSet float"); + assertEquals(1.0f, o, "getAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 2.0f, "getAndSet float value"); + assertEquals(2.0f, x, "getAndSet float value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 2.0f); - assertEquals(o, 1.0f, "getAndAdd float"); + assertEquals(1.0f, o, "getAndAdd float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 2.0f); - assertEquals(o, 1.0f, "getAndAddAcquire float"); + assertEquals(1.0f, o, "getAndAddAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 2.0f); - assertEquals(o, 1.0f, "getAndAddRelease float"); + assertEquals(1.0f, o, "getAndAddRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value"); } } @@ -340,7 +338,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(1.0f); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "set float value"); + assertEquals(1.0f, x, "set float value"); } @@ -348,21 +346,21 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(2.0f); float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, 2.0f, "setVolatile float value"); + assertEquals(2.0f, x, "setVolatile float value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(1.0f); float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, 1.0f, "setRelease float value"); + assertEquals(1.0f, x, "setRelease float value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(2.0f); float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, 2.0f, "setOpaque float value"); + assertEquals(2.0f, x, "setOpaque float value"); } hs.get(TestAccessMode.SET).invokeExact(1.0f); @@ -372,56 +370,56 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 2.0f); assertEquals(r, true, "success compareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "success compareAndSet float value"); + assertEquals(2.0f, x, "success compareAndSet float value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(1.0f, 3.0f); assertEquals(r, false, "failing compareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "failing compareAndSet float value"); + assertEquals(2.0f, x, "failing compareAndSet float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchange float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "success compareAndExchange float value"); + assertEquals(1.0f, x, "success compareAndExchange float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchange float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "failing compareAndExchange float value"); + assertEquals(1.0f, x, "failing compareAndExchange float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 2.0f); assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "success compareAndExchangeAcquire float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(1.0f, 3.0f); assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "success compareAndExchangeRelease float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "failing compareAndExchangeRelease float value"); } { @@ -433,14 +431,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "success weakCompareAndSetPlain float value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value"); } { @@ -452,7 +450,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float"); + assertEquals(1.0f, x, "success weakCompareAndSetAcquire float"); } { @@ -460,7 +458,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact(2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -472,14 +470,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "success weakCompareAndSetRelease float"); + assertEquals(2.0f, x, "success weakCompareAndSetRelease float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "failing weakCompareAndSetRelease float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetRelease float value"); } { @@ -491,14 +489,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "success weakCompareAndSet float"); + assertEquals(1.0f, x, "success weakCompareAndSet float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 1.0f, "failing weakCompareAndSetRe float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetRe float value"); } // Compare set and get @@ -506,9 +504,9 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(2.0f); - assertEquals(o, 1.0f, "getAndSet float"); + assertEquals(1.0f, o, "getAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "getAndSet float value"); + assertEquals(2.0f, x, "getAndSet float value"); } // Compare set and get @@ -516,9 +514,9 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(2.0f); - assertEquals(o, 1.0f, "getAndSetAcquire float"); + assertEquals(1.0f, o, "getAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "getAndSetAcquire float value"); + assertEquals(2.0f, x, "getAndSetAcquire float value"); } // Compare set and get @@ -526,9 +524,9 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(2.0f); - assertEquals(o, 1.0f, "getAndSetRelease float"); + assertEquals(1.0f, o, "getAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 2.0f, "getAndSetRelease float value"); + assertEquals(2.0f, x, "getAndSetRelease float value"); } // get and add, add and get @@ -536,27 +534,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(2.0f); - assertEquals(o, 1.0f, "getAndAdd float"); + assertEquals(1.0f, o, "getAndAdd float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value"); } { hs.get(TestAccessMode.SET).invokeExact(1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(2.0f); - assertEquals(o, 1.0f, "getAndAddAcquire float"); + assertEquals(1.0f, o, "getAndAddAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value"); } { hs.get(TestAccessMode.SET).invokeExact(1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(2.0f); - assertEquals(o, 1.0f, "getAndAddRelease float"); + assertEquals(1.0f, o, "getAndAddRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value"); } } @@ -580,7 +578,7 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "get float value"); + assertEquals(1.0f, x, "get float value"); } @@ -588,21 +586,21 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 2.0f); float x = (float) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, 2.0f, "setVolatile float value"); + assertEquals(2.0f, x, "setVolatile float value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 1.0f); float x = (float) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, 1.0f, "setRelease float value"); + assertEquals(1.0f, x, "setRelease float value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 2.0f); float x = (float) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, 2.0f, "setOpaque float value"); + assertEquals(2.0f, x, "setOpaque float value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); @@ -612,56 +610,56 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 2.0f); assertEquals(r, true, "success compareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "success compareAndSet float value"); + assertEquals(2.0f, x, "success compareAndSet float value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 1.0f, 3.0f); assertEquals(r, false, "failing compareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "failing compareAndSet float value"); + assertEquals(2.0f, x, "failing compareAndSet float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchange float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "success compareAndExchange float value"); + assertEquals(1.0f, x, "success compareAndExchange float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchange float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "failing compareAndExchange float value"); + assertEquals(1.0f, x, "failing compareAndExchange float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 2.0f); assertEquals(r, 1.0f, "success compareAndExchangeAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "success compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "success compareAndExchangeAcquire float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f); assertEquals(r, 2.0f, "failing compareAndExchangeAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "failing compareAndExchangeAcquire float value"); + assertEquals(2.0f, x, "failing compareAndExchangeAcquire float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 1.0f); assertEquals(r, 2.0f, "success compareAndExchangeRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "success compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "success compareAndExchangeRelease float value"); } { float r = (float) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 2.0f, 3.0f); assertEquals(r, 1.0f, "failing compareAndExchangeRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "failing compareAndExchangeRelease float value"); + assertEquals(1.0f, x, "failing compareAndExchangeRelease float value"); } { @@ -673,14 +671,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "success weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "success weakCompareAndSetPlain float value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetPlain float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "failing weakCompareAndSetPlain float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetPlain float value"); } { @@ -692,14 +690,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "success weakCompareAndSetAcquire float"); + assertEquals(1.0f, x, "success weakCompareAndSetAcquire float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(1.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -711,14 +709,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "success weakCompareAndSetRelease float"); + assertEquals(2.0f, x, "success weakCompareAndSetRelease float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 1.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "failing weakCompareAndSetAcquire float value"); + assertEquals(2.0f, x, "failing weakCompareAndSetAcquire float value"); } { @@ -730,14 +728,14 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "success weakCompareAndSet float"); + assertEquals(1.0f, x, "success weakCompareAndSet float"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 2.0f, 3.0f); assertEquals(success, false, "failing weakCompareAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 1.0f, "failing weakCompareAndSet float value"); + assertEquals(1.0f, x, "failing weakCompareAndSet float value"); } // Compare set and get @@ -745,27 +743,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndSet float"); + assertEquals(1.0f, o, "getAndSet float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "getAndSet float value"); + assertEquals(2.0f, x, "getAndSet float value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndSetAcquire float"); + assertEquals(1.0f, o, "getAndSetAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "getAndSetAcquire float value"); + assertEquals(2.0f, x, "getAndSetAcquire float value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndSetRelease float"); + assertEquals(1.0f, o, "getAndSetRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 2.0f, "getAndSetRelease float value"); + assertEquals(2.0f, x, "getAndSetRelease float value"); } // get and add, add and get @@ -773,27 +771,27 @@ public class VarHandleTestMethodHandleAccessFloat extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndAdd float"); + assertEquals(1.0f, o, "getAndAdd float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAdd float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAdd float value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndAddAcquire float"); + assertEquals(1.0f, o, "getAndAddAcquire float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddAcquire float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddAcquire float value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 1.0f); float o = (float) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 2.0f); - assertEquals(o, 1.0f, "getAndAddRelease float"); + assertEquals(1.0f, o, "getAndAddRelease float"); float x = (float) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (float)(1.0f + 2.0f), "getAndAddRelease float value"); + assertEquals((float)(1.0f + 2.0f), x, "getAndAddRelease float value"); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java index d8558e0b070..920d8453bab 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessInt + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessInt */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { static final int static_final_v = 0x01234567; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessInt.class, "final_v", int.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(int[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessInt recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "set int value"); + assertEquals(0x01234567, x, "set int value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0x89ABCDEF); int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "setVolatile int value"); + assertEquals(0x89ABCDEF, x, "setVolatile int value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x01234567); int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, 0x01234567, "setRelease int value"); + assertEquals(0x01234567, x, "setRelease int value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0x89ABCDEF); int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "setOpaque int value"); + assertEquals(0x89ABCDEF, x, "setOpaque int value"); } hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0x89ABCDEF); assertEquals(r, true, "success compareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "success compareAndSet int value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x01234567, 0xCAFEBABE); assertEquals(r, false, "failing compareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndSet int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "success compareAndExchange int value"); + assertEquals(0x01234567, x, "success compareAndExchange int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchange int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "failing compareAndExchange int value"); + assertEquals(0x01234567, x, "failing compareAndExchange int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x01234567, 0x89ABCDEF); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "success compareAndExchangeAcquire int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x01234567, 0xCAFEBABE); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "success compareAndExchangeRelease int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "failing compareAndExchangeRelease int value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetPlain int value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetPlain int value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "success weakCompareAndSetAcquire int"); + assertEquals(0x01234567, x, "success weakCompareAndSetAcquire int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetAcquire int value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetRelease int"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetRelease int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetRelease int value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "success weakCompareAndSet int"); + assertEquals(0x01234567, x, "success weakCompareAndSet int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x01234567, "failing weakCompareAndSet int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSet int value"); } // Compare set and get { int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSet int"); + assertEquals(0x01234567, o, "getAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x89ABCDEF, "getAndSet int value"); + assertEquals(0x89ABCDEF, x, "getAndSet int value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAdd int"); + assertEquals(0x01234567, o, "getAndAdd int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAdd int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddAcquire int"); + assertEquals(0x01234567, o, "getAndAddAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddRelease int"); + assertEquals(0x01234567, o, "getAndAddRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddRelease int value"); } // get and bitwise or @@ -327,27 +325,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOr int"); + assertEquals(0x01234567, o, "getAndBitwiseOr int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOr int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseOrAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseOrRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -355,27 +353,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); + assertEquals(0x01234567, o, "getAndBitwiseAnd int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAnd int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseAndAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseAndRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -383,27 +381,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXor int"); + assertEquals(0x01234567, o, "getAndBitwiseXor int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXor int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseXorAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseXorRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorRelease int value"); } } @@ -418,7 +416,7 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "set int value"); + assertEquals(0x01234567, x, "set int value"); } @@ -426,21 +424,21 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0x89ABCDEF); int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, 0x89ABCDEF, "setVolatile int value"); + assertEquals(0x89ABCDEF, x, "setVolatile int value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x01234567); int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, 0x01234567, "setRelease int value"); + assertEquals(0x01234567, x, "setRelease int value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0x89ABCDEF); int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, 0x89ABCDEF, "setOpaque int value"); + assertEquals(0x89ABCDEF, x, "setOpaque int value"); } hs.get(TestAccessMode.SET).invokeExact(0x01234567); @@ -450,56 +448,56 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x01234567, 0x89ABCDEF); assertEquals(r, true, "success compareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "success compareAndSet int value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x01234567, 0xCAFEBABE); assertEquals(r, false, "failing compareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndSet int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "success compareAndExchange int value"); + assertEquals(0x01234567, x, "success compareAndExchange int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchange int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "failing compareAndExchange int value"); + assertEquals(0x01234567, x, "failing compareAndExchange int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x01234567, 0x89ABCDEF); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "success compareAndExchangeAcquire int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x01234567, 0xCAFEBABE); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "success compareAndExchangeRelease int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "failing compareAndExchangeRelease int value"); } { @@ -511,14 +509,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetPlain int value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetPlain int value"); } { @@ -530,7 +528,7 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "success weakCompareAndSetAcquire int"); + assertEquals(0x01234567, x, "success weakCompareAndSetAcquire int"); } { @@ -538,7 +536,7 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact(0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetAcquire int value"); } { @@ -550,14 +548,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetRelease int"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetRelease int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetRelease int value"); } { @@ -569,14 +567,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "success weakCompareAndSet int"); + assertEquals(0x01234567, x, "success weakCompareAndSet int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x01234567, "failing weakCompareAndSetRe int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetRe int value"); } // Compare set and get @@ -584,9 +582,9 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSet int"); + assertEquals(0x01234567, o, "getAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "getAndSet int value"); + assertEquals(0x89ABCDEF, x, "getAndSet int value"); } // Compare set and get @@ -594,9 +592,9 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetAcquire int"); + assertEquals(0x01234567, o, "getAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); + assertEquals(0x89ABCDEF, x, "getAndSetAcquire int value"); } // Compare set and get @@ -604,9 +602,9 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetRelease int"); + assertEquals(0x01234567, o, "getAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "getAndSetRelease int value"); } // get and add, add and get @@ -614,27 +612,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAdd int"); + assertEquals(0x01234567, o, "getAndAdd int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAdd int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddAcquire int"); + assertEquals(0x01234567, o, "getAndAddAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddRelease int"); + assertEquals(0x01234567, o, "getAndAddRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddRelease int value"); } // get and bitwise or @@ -642,27 +640,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOr int"); + assertEquals(0x01234567, o, "getAndBitwiseOr int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOr int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseOrAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseOrRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -670,27 +668,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); + assertEquals(0x01234567, o, "getAndBitwiseAnd int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAnd int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseAndAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseAndRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -698,27 +696,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXor int"); + assertEquals(0x01234567, o, "getAndBitwiseXor int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXor int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseXorAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseXorRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorRelease int value"); } } @@ -736,7 +734,7 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "get int value"); + assertEquals(0x01234567, x, "get int value"); } @@ -744,21 +742,21 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0x89ABCDEF); int x = (int) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "setVolatile int value"); + assertEquals(0x89ABCDEF, x, "setVolatile int value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x01234567); int x = (int) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, 0x01234567, "setRelease int value"); + assertEquals(0x01234567, x, "setRelease int value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0x89ABCDEF); int x = (int) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "setOpaque int value"); + assertEquals(0x89ABCDEF, x, "setOpaque int value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); @@ -768,56 +766,56 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0x89ABCDEF); assertEquals(r, true, "success compareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "success compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "success compareAndSet int value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x01234567, 0xCAFEBABE); assertEquals(r, false, "failing compareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "failing compareAndSet int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndSet int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchange int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "success compareAndExchange int value"); + assertEquals(0x01234567, x, "success compareAndExchange int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchange int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "failing compareAndExchange int value"); + assertEquals(0x01234567, x, "failing compareAndExchange int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x01234567, 0x89ABCDEF); assertEquals(r, 0x01234567, "success compareAndExchangeAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "success compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "success compareAndExchangeAcquire int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x01234567, 0xCAFEBABE); assertEquals(r, 0x89ABCDEF, "failing compareAndExchangeAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "failing compareAndExchangeAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing compareAndExchangeAcquire int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0x89ABCDEF, 0x01234567); assertEquals(r, 0x89ABCDEF, "success compareAndExchangeRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "success compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "success compareAndExchangeRelease int value"); } { int r = (int) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(r, 0x01234567, "failing compareAndExchangeRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "failing compareAndExchangeRelease int value"); + assertEquals(0x01234567, x, "failing compareAndExchangeRelease int value"); } { @@ -829,14 +827,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetPlain int value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetPlain int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetPlain int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetPlain int value"); } { @@ -848,14 +846,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "success weakCompareAndSetAcquire int"); + assertEquals(0x01234567, x, "success weakCompareAndSetAcquire int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSetAcquire int value"); } { @@ -867,14 +865,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "success weakCompareAndSetRelease int"); + assertEquals(0x89ABCDEF, x, "success weakCompareAndSetRelease int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0x01234567, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "failing weakCompareAndSetAcquire int value"); + assertEquals(0x89ABCDEF, x, "failing weakCompareAndSetAcquire int value"); } { @@ -886,14 +884,14 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "success weakCompareAndSet int"); + assertEquals(0x01234567, x, "success weakCompareAndSet int"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0x89ABCDEF, 0xCAFEBABE); assertEquals(success, false, "failing weakCompareAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x01234567, "failing weakCompareAndSet int value"); + assertEquals(0x01234567, x, "failing weakCompareAndSet int value"); } // Compare set and get @@ -901,27 +899,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSet int"); + assertEquals(0x01234567, o, "getAndSet int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "getAndSet int value"); + assertEquals(0x89ABCDEF, x, "getAndSet int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetAcquire int"); + assertEquals(0x01234567, o, "getAndSetAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "getAndSetAcquire int value"); + assertEquals(0x89ABCDEF, x, "getAndSetAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndSetRelease int"); + assertEquals(0x01234567, o, "getAndSetRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x89ABCDEF, "getAndSetRelease int value"); + assertEquals(0x89ABCDEF, x, "getAndSetRelease int value"); } // get and add, add and get @@ -929,27 +927,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAdd int"); + assertEquals(0x01234567, o, "getAndAdd int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAdd int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAdd int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddAcquire int"); + assertEquals(0x01234567, o, "getAndAddAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddAcquire int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndAddRelease int"); + assertEquals(0x01234567, o, "getAndAddRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 + 0x89ABCDEF), "getAndAddRelease int value"); + assertEquals((int)(0x01234567 + 0x89ABCDEF), x, "getAndAddRelease int value"); } // get and bitwise or @@ -957,27 +955,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOr int"); + assertEquals(0x01234567, o, "getAndBitwiseOr int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOr int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOr int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseOrAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrAcquire int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseOrRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseOrRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 | 0x89ABCDEF), "getAndBitwiseOrRelease int value"); + assertEquals((int)(0x01234567 | 0x89ABCDEF), x, "getAndBitwiseOrRelease int value"); } // get and bitwise and @@ -985,27 +983,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAnd int"); + assertEquals(0x01234567, o, "getAndBitwiseAnd int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAnd int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAnd int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseAndAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndAcquire int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseAndRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseAndRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 & 0x89ABCDEF), "getAndBitwiseAndRelease int value"); + assertEquals((int)(0x01234567 & 0x89ABCDEF), x, "getAndBitwiseAndRelease int value"); } // get and bitwise xor @@ -1013,27 +1011,27 @@ public class VarHandleTestMethodHandleAccessInt extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXor int"); + assertEquals(0x01234567, o, "getAndBitwiseXor int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXor int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXor int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorAcquire int"); + assertEquals(0x01234567, o, "getAndBitwiseXorAcquire int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorAcquire int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorAcquire int value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x01234567); int o = (int) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, 0x89ABCDEF); - assertEquals(o, 0x01234567, "getAndBitwiseXorRelease int"); + assertEquals(0x01234567, o, "getAndBitwiseXorRelease int"); int x = (int) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (int)(0x01234567 ^ 0x89ABCDEF), "getAndBitwiseXorRelease int value"); + assertEquals((int)(0x01234567 ^ 0x89ABCDEF), x, "getAndBitwiseXorRelease int value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java index 0e73063395d..90f6dd12c47 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessLong + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessLong */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { static final long static_final_v = 0x0123456789ABCDEFL; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessLong.class, "final_v", long.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(long[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessLong recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "set long value"); + assertEquals(0x0123456789ABCDEFL, x, "set long value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, 0xCAFEBABECAFEBABEL); long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setVolatile long value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL); long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "setRelease long value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, 0xCAFEBABECAFEBABEL); long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setOpaque long value"); } hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndSet long value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndSet long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchange long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchange long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndExchangeAcquire long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchangeRelease long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchangeRelease long value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetPlain long value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetPlain long value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSetAcquire long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetRelease long"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetRelease long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetRelease long value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSet long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSet long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSet long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSet long value"); } // Compare set and get { long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSet long value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAdd long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAdd long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddRelease long value"); } // get and bitwise or @@ -327,27 +325,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOr long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOr long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -355,27 +353,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAnd long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAnd long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -383,27 +381,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXor long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXor long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorRelease long value"); } } @@ -418,7 +416,7 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "set long value"); + assertEquals(0x0123456789ABCDEFL, x, "set long value"); } @@ -426,21 +424,21 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(0xCAFEBABECAFEBABEL); long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setVolatile long value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(0x0123456789ABCDEFL); long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "setRelease long value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(0xCAFEBABECAFEBABEL); long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setOpaque long value"); } hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); @@ -450,56 +448,56 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndSet long value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndSet long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchange long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchange long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndExchangeAcquire long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchangeRelease long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchangeRelease long value"); } { @@ -511,14 +509,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetPlain long value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetPlain long value"); } { @@ -530,7 +528,7 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSetAcquire long"); } { @@ -538,7 +536,7 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -550,14 +548,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetRelease long"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetRelease long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetRelease long value"); } { @@ -569,14 +567,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSet long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSet long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetRe long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetRe long value"); } // Compare set and get @@ -584,9 +582,9 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSet long value"); } // Compare set and get @@ -594,9 +592,9 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetAcquire long value"); } // Compare set and get @@ -604,9 +602,9 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetRelease long value"); } // get and add, add and get @@ -614,27 +612,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAdd long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAdd long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddRelease long value"); } // get and bitwise or @@ -642,27 +640,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOr long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOr long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -670,27 +668,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAnd long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAnd long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -698,27 +696,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXor long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXor long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorRelease long value"); } } @@ -736,7 +734,7 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "get long value"); + assertEquals(0x0123456789ABCDEFL, x, "get long value"); } @@ -744,21 +742,21 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); long x = (long) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setVolatile long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setVolatile long value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, 0x0123456789ABCDEFL); long x = (long) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "setRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "setRelease long value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); long x = (long) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "setOpaque long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "setOpaque long value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); @@ -768,56 +766,56 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, true, "success compareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndSet long value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, false, "failing compareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndSet long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchange long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchange long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchange long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchange long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchange long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xCAFEBABECAFEBABEL); assertEquals(r, 0x0123456789ABCDEFL, "success compareAndExchangeAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success compareAndExchangeAcquire long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing compareAndExchangeAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing compareAndExchangeAcquire long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0x0123456789ABCDEFL); assertEquals(r, 0xCAFEBABECAFEBABEL, "success compareAndExchangeRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "success compareAndExchangeRelease long value"); } { long r = (long) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(r, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing compareAndExchangeRelease long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing compareAndExchangeRelease long value"); } { @@ -829,14 +827,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetPlain long value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetPlain long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetPlain long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetPlain long value"); } { @@ -848,14 +846,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSetAcquire long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -867,14 +865,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "success weakCompareAndSetRelease long"); + assertEquals(0xCAFEBABECAFEBABEL, x, "success weakCompareAndSetRelease long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, 0x0123456789ABCDEFL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "failing weakCompareAndSetAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "failing weakCompareAndSetAcquire long value"); } { @@ -886,14 +884,14 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "success weakCompareAndSet long"); + assertEquals(0x0123456789ABCDEFL, x, "success weakCompareAndSet long"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL, 0xDEADBEEFDEADBEEFL); assertEquals(success, false, "failing weakCompareAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0x0123456789ABCDEFL, "failing weakCompareAndSet long value"); + assertEquals(0x0123456789ABCDEFL, x, "failing weakCompareAndSet long value"); } // Compare set and get @@ -901,27 +899,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSet long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSet long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSet long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSet long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetAcquire long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndSetRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndSetRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, 0xCAFEBABECAFEBABEL, "getAndSetRelease long value"); + assertEquals(0xCAFEBABECAFEBABEL, x, "getAndSetRelease long value"); } // get and add, add and get @@ -929,27 +927,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAdd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAdd long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAdd long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAdd long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndAddRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndAddRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), "getAndAddRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL + 0xCAFEBABECAFEBABEL), x, "getAndAddRelease long value"); } // get and bitwise or @@ -957,27 +955,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOr long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOr long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOr long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOr long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseOrRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseOrRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), "getAndBitwiseOrRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL | 0xCAFEBABECAFEBABEL), x, "getAndBitwiseOrRelease long value"); } // get and bitwise and @@ -985,27 +983,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAnd long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAnd long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAnd long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAnd long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseAndRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseAndRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), "getAndBitwiseAndRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL & 0xCAFEBABECAFEBABEL), x, "getAndBitwiseAndRelease long value"); } // get and bitwise xor @@ -1013,27 +1011,27 @@ public class VarHandleTestMethodHandleAccessLong extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXor long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXor long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXor long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXor long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorAcquire long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorAcquire long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorAcquire long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorAcquire long value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, 0x0123456789ABCDEFL); long o = (long) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, 0xCAFEBABECAFEBABEL); - assertEquals(o, 0x0123456789ABCDEFL, "getAndBitwiseXorRelease long"); + assertEquals(0x0123456789ABCDEFL, o, "getAndBitwiseXorRelease long"); long x = (long) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), "getAndBitwiseXorRelease long value"); + assertEquals((long)(0x0123456789ABCDEFL ^ 0xCAFEBABECAFEBABEL), x, "getAndBitwiseXorRelease long value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java index 8fb23d7dc55..d8f548fe2d6 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessShort + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessShort */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { static final short static_final_v = (short)0x0123; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessShort.class, "final_v", short.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(short[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessShort recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "set short value"); + assertEquals((short)0x0123, x, "set short value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (short)0x4567); short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, (short)0x4567, "setVolatile short value"); + assertEquals((short)0x4567, x, "setVolatile short value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (short)0x0123); short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, (short)0x0123, "setRelease short value"); + assertEquals((short)0x0123, x, "setRelease short value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (short)0x4567); short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, (short)0x4567, "setOpaque short value"); + assertEquals((short)0x4567, x, "setOpaque short value"); } hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x4567); assertEquals(r, true, "success compareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "success compareAndSet short value"); + assertEquals((short)0x4567, x, "success compareAndSet short value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (short)0x0123, (short)0x89AB); assertEquals(r, false, "failing compareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "failing compareAndSet short value"); + assertEquals((short)0x4567, x, "failing compareAndSet short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchange short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "success compareAndExchange short value"); + assertEquals((short)0x0123, x, "success compareAndExchange short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchange short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); + assertEquals((short)0x0123, x, "failing compareAndExchange short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x4567); assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "success compareAndExchangeAcquire short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (short)0x0123, (short)0x89AB); assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "failing compareAndExchangeAcquire short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "success compareAndExchangeRelease short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "failing compareAndExchangeRelease short value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "success weakCompareAndSetPlain short value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetPlain short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetPlain short value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); + assertEquals((short)0x0123, x, "success weakCompareAndSetAcquire short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetAcquire short value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); + assertEquals((short)0x4567, x, "success weakCompareAndSetRelease short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetRelease short value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); + assertEquals((short)0x0123, x, "success weakCompareAndSet short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSet short value"); } // Compare set and get { short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSet short"); + assertEquals((short)0x0123, o, "getAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)0x4567, "getAndSet short value"); + assertEquals((short)0x4567, x, "getAndSet short value"); } // get and add, add and get @@ -299,27 +297,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAdd short"); + assertEquals((short)0x0123, o, "getAndAdd short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAdd short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddAcquire short"); + assertEquals((short)0x0123, o, "getAndAddAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddRelease short"); + assertEquals((short)0x0123, o, "getAndAddRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddRelease short value"); } // get and bitwise or @@ -327,27 +325,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); + assertEquals((short)0x0123, o, "getAndBitwiseOr short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOr short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrRelease short value"); } // get and bitwise and @@ -355,27 +353,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); + assertEquals((short)0x0123, o, "getAndBitwiseAnd short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAnd short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndRelease short value"); } // get and bitwise xor @@ -383,27 +381,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); + assertEquals((short)0x0123, o, "getAndBitwiseXor short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXor short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorRelease short value"); } } @@ -418,7 +416,7 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "set short value"); + assertEquals((short)0x0123, x, "set short value"); } @@ -426,21 +424,21 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact((short)0x4567); short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, (short)0x4567, "setVolatile short value"); + assertEquals((short)0x4567, x, "setVolatile short value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact((short)0x0123); short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, (short)0x0123, "setRelease short value"); + assertEquals((short)0x0123, x, "setRelease short value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact((short)0x4567); short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, (short)0x4567, "setOpaque short value"); + assertEquals((short)0x4567, x, "setOpaque short value"); } hs.get(TestAccessMode.SET).invokeExact((short)0x0123); @@ -450,56 +448,56 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x4567); assertEquals(r, true, "success compareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "success compareAndSet short value"); + assertEquals((short)0x4567, x, "success compareAndSet short value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((short)0x0123, (short)0x89AB); assertEquals(r, false, "failing compareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "failing compareAndSet short value"); + assertEquals((short)0x4567, x, "failing compareAndSet short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchange short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "success compareAndExchange short value"); + assertEquals((short)0x0123, x, "success compareAndExchange short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact((short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchange short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); + assertEquals((short)0x0123, x, "failing compareAndExchange short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x4567); assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "success compareAndExchangeAcquire short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((short)0x0123, (short)0x89AB); assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "failing compareAndExchangeAcquire short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "success compareAndExchangeRelease short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "failing compareAndExchangeRelease short value"); } { @@ -511,14 +509,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "success weakCompareAndSetPlain short value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact((short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetPlain short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetPlain short value"); } { @@ -530,7 +528,7 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); + assertEquals((short)0x0123, x, "success weakCompareAndSetAcquire short"); } { @@ -538,7 +536,7 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact((short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetAcquire short value"); } { @@ -550,14 +548,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); + assertEquals((short)0x4567, x, "success weakCompareAndSetRelease short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetRelease short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetRelease short value"); } { @@ -569,14 +567,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); + assertEquals((short)0x0123, x, "success weakCompareAndSet short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetRe short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetRe short value"); } // Compare set and get @@ -584,9 +582,9 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndSet short"); + assertEquals((short)0x0123, o, "getAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "getAndSet short value"); + assertEquals((short)0x4567, x, "getAndSet short value"); } // Compare set and get @@ -594,9 +592,9 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetAcquire short"); + assertEquals((short)0x0123, o, "getAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); + assertEquals((short)0x4567, x, "getAndSetAcquire short value"); } // Compare set and get @@ -604,9 +602,9 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetRelease short"); + assertEquals((short)0x0123, o, "getAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)0x4567, "getAndSetRelease short value"); + assertEquals((short)0x4567, x, "getAndSetRelease short value"); } // get and add, add and get @@ -614,27 +612,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndAdd short"); + assertEquals((short)0x0123, o, "getAndAdd short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAdd short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddAcquire short"); + assertEquals((short)0x0123, o, "getAndAddAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddRelease short"); + assertEquals((short)0x0123, o, "getAndAddRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddRelease short value"); } // get and bitwise or @@ -642,27 +640,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); + assertEquals((short)0x0123, o, "getAndBitwiseOr short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOr short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrRelease short value"); } // get and bitwise and @@ -670,27 +668,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); + assertEquals((short)0x0123, o, "getAndBitwiseAnd short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAnd short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndRelease short value"); } // get and bitwise xor @@ -698,27 +696,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); + assertEquals((short)0x0123, o, "getAndBitwiseXor short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXor short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact((short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact((short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorRelease short value"); } } @@ -736,7 +734,7 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "get short value"); + assertEquals((short)0x0123, x, "get short value"); } @@ -744,21 +742,21 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (short)0x4567); short x = (short) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, (short)0x4567, "setVolatile short value"); + assertEquals((short)0x4567, x, "setVolatile short value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (short)0x0123); short x = (short) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, (short)0x0123, "setRelease short value"); + assertEquals((short)0x0123, x, "setRelease short value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (short)0x4567); short x = (short) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, (short)0x4567, "setOpaque short value"); + assertEquals((short)0x4567, x, "setOpaque short value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); @@ -768,56 +766,56 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x4567); assertEquals(r, true, "success compareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "success compareAndSet short value"); + assertEquals((short)0x4567, x, "success compareAndSet short value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (short)0x0123, (short)0x89AB); assertEquals(r, false, "failing compareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "failing compareAndSet short value"); + assertEquals((short)0x4567, x, "failing compareAndSet short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchange short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "success compareAndExchange short value"); + assertEquals((short)0x0123, x, "success compareAndExchange short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchange short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "failing compareAndExchange short value"); + assertEquals((short)0x0123, x, "failing compareAndExchange short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x4567); assertEquals(r, (short)0x0123, "success compareAndExchangeAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "success compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "success compareAndExchangeAcquire short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB); assertEquals(r, (short)0x4567, "failing compareAndExchangeAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "failing compareAndExchangeAcquire short value"); + assertEquals((short)0x4567, x, "failing compareAndExchangeAcquire short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x0123); assertEquals(r, (short)0x4567, "success compareAndExchangeRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "success compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "success compareAndExchangeRelease short value"); } { short r = (short) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (short)0x4567, (short)0x89AB); assertEquals(r, (short)0x0123, "failing compareAndExchangeRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "failing compareAndExchangeRelease short value"); + assertEquals((short)0x0123, x, "failing compareAndExchangeRelease short value"); } { @@ -829,14 +827,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "success weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "success weakCompareAndSetPlain short value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetPlain short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetPlain short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetPlain short value"); } { @@ -848,14 +846,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "success weakCompareAndSetAcquire short"); + assertEquals((short)0x0123, x, "success weakCompareAndSetAcquire short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSetAcquire short value"); } { @@ -867,14 +865,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "success weakCompareAndSetRelease short"); + assertEquals((short)0x4567, x, "success weakCompareAndSetRelease short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x0123, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "failing weakCompareAndSetAcquire short value"); + assertEquals((short)0x4567, x, "failing weakCompareAndSetAcquire short value"); } { @@ -886,14 +884,14 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "success weakCompareAndSet short"); + assertEquals((short)0x0123, x, "success weakCompareAndSet short"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (short)0x4567, (short)0x89AB); assertEquals(success, false, "failing weakCompareAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x0123, "failing weakCompareAndSet short value"); + assertEquals((short)0x0123, x, "failing weakCompareAndSet short value"); } // Compare set and get @@ -901,27 +899,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSet short"); + assertEquals((short)0x0123, o, "getAndSet short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "getAndSet short value"); + assertEquals((short)0x4567, x, "getAndSet short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetAcquire short"); + assertEquals((short)0x0123, o, "getAndSetAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "getAndSetAcquire short value"); + assertEquals((short)0x4567, x, "getAndSetAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndSetRelease short"); + assertEquals((short)0x0123, o, "getAndSetRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)0x4567, "getAndSetRelease short value"); + assertEquals((short)0x4567, x, "getAndSetRelease short value"); } // get and add, add and get @@ -929,27 +927,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAdd short"); + assertEquals((short)0x0123, o, "getAndAdd short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAdd short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAdd short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddAcquire short"); + assertEquals((short)0x0123, o, "getAndAddAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddAcquire short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndAddRelease short"); + assertEquals((short)0x0123, o, "getAndAddRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 + (short)0x4567), "getAndAddRelease short value"); + assertEquals((short)((short)0x0123 + (short)0x4567), x, "getAndAddRelease short value"); } // get and bitwise or @@ -957,27 +955,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOr short"); + assertEquals((short)0x0123, o, "getAndBitwiseOr short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOr short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOr short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrAcquire short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseOrRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseOrRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 | (short)0x4567), "getAndBitwiseOrRelease short value"); + assertEquals((short)((short)0x0123 | (short)0x4567), x, "getAndBitwiseOrRelease short value"); } // get and bitwise and @@ -985,27 +983,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAnd short"); + assertEquals((short)0x0123, o, "getAndBitwiseAnd short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAnd short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAnd short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndAcquire short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseAndRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseAndRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 & (short)0x4567), "getAndBitwiseAndRelease short value"); + assertEquals((short)((short)0x0123 & (short)0x4567), x, "getAndBitwiseAndRelease short value"); } // get and bitwise xor @@ -1013,27 +1011,27 @@ public class VarHandleTestMethodHandleAccessShort extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXor short"); + assertEquals((short)0x0123, o, "getAndBitwiseXor short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXor short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXor short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorAcquire short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorAcquire short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorAcquire short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorAcquire short value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, (short)0x0123); short o = (short) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, (short)0x4567); - assertEquals(o, (short)0x0123, "getAndBitwiseXorRelease short"); + assertEquals((short)0x0123, o, "getAndBitwiseXorRelease short"); short x = (short) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, (short)((short)0x0123 ^ (short)0x4567), "getAndBitwiseXorRelease short value"); + assertEquals((short)((short)0x0123 ^ (short)0x4567), x, "getAndBitwiseXorRelease short value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java index 8ccede760c9..35723f63d27 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessString + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccessString */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { static final String static_final_v = "foo"; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccessString.class, "final_v", String.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(String[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccessString recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, "foo"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "set String value"); + assertEquals("foo", x, "set String value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, "bar"); String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, "bar", "setVolatile String value"); + assertEquals("bar", x, "setVolatile String value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, "foo"); String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, "foo", "setRelease String value"); + assertEquals("foo", x, "setRelease String value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, "bar"); String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, "bar", "setOpaque String value"); + assertEquals("bar", x, "setOpaque String value"); } hs.get(TestAccessMode.SET).invokeExact(recv, "foo"); @@ -158,56 +156,56 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, "foo", "bar"); assertEquals(r, true, "success compareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "success compareAndSet String value"); + assertEquals("bar", x, "success compareAndSet String value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, "foo", "baz"); assertEquals(r, false, "failing compareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "failing compareAndSet String value"); + assertEquals("bar", x, "failing compareAndSet String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchange String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "success compareAndExchange String value"); + assertEquals("foo", x, "success compareAndExchange String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchange String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "failing compareAndExchange String value"); + assertEquals("foo", x, "failing compareAndExchange String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, "foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); + assertEquals("bar", x, "success compareAndExchangeAcquire String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, "foo", "baz"); assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); + assertEquals("bar", x, "failing compareAndExchangeAcquire String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchangeRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "success compareAndExchangeRelease String value"); + assertEquals("foo", x, "success compareAndExchangeRelease String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchangeRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "failing compareAndExchangeRelease String value"); + assertEquals("foo", x, "failing compareAndExchangeRelease String value"); } { @@ -219,14 +217,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "success weakCompareAndSetPlain String value"); + assertEquals("bar", x, "success weakCompareAndSetPlain String value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetPlain String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "failing weakCompareAndSetPlain String value"); + assertEquals("bar", x, "failing weakCompareAndSetPlain String value"); } { @@ -238,14 +236,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "success weakCompareAndSetAcquire String"); + assertEquals("foo", x, "success weakCompareAndSetAcquire String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value"); + assertEquals("foo", x, "failing weakCompareAndSetAcquire String value"); } { @@ -257,14 +255,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "success weakCompareAndSetRelease String"); + assertEquals("bar", x, "success weakCompareAndSetRelease String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "failing weakCompareAndSetRelease String value"); + assertEquals("bar", x, "failing weakCompareAndSetRelease String value"); } { @@ -276,22 +274,22 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "success weakCompareAndSet String"); + assertEquals("foo", x, "success weakCompareAndSet String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "foo", "failing weakCompareAndSet String value"); + assertEquals("foo", x, "failing weakCompareAndSet String value"); } // Compare set and get { String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, "bar"); - assertEquals(o, "foo", "getAndSet String"); + assertEquals("foo", o, "getAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, "bar", "getAndSet String value"); + assertEquals("bar", x, "getAndSet String value"); } @@ -318,7 +316,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact("foo"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "set String value"); + assertEquals("foo", x, "set String value"); } @@ -326,21 +324,21 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact("bar"); String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, "bar", "setVolatile String value"); + assertEquals("bar", x, "setVolatile String value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact("foo"); String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, "foo", "setRelease String value"); + assertEquals("foo", x, "setRelease String value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact("bar"); String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, "bar", "setOpaque String value"); + assertEquals("bar", x, "setOpaque String value"); } hs.get(TestAccessMode.SET).invokeExact("foo"); @@ -350,56 +348,56 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "bar"); assertEquals(r, true, "success compareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "success compareAndSet String value"); + assertEquals("bar", x, "success compareAndSet String value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact("foo", "baz"); assertEquals(r, false, "failing compareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "failing compareAndSet String value"); + assertEquals("bar", x, "failing compareAndSet String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "foo"); assertEquals(r, "bar", "success compareAndExchange String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "success compareAndExchange String value"); + assertEquals("foo", x, "success compareAndExchange String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact("bar", "baz"); assertEquals(r, "foo", "failing compareAndExchange String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "failing compareAndExchange String value"); + assertEquals("foo", x, "failing compareAndExchange String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); + assertEquals("bar", x, "success compareAndExchangeAcquire String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact("foo", "baz"); assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); + assertEquals("bar", x, "failing compareAndExchangeAcquire String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "foo"); assertEquals(r, "bar", "success compareAndExchangeRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "success compareAndExchangeRelease String value"); + assertEquals("foo", x, "success compareAndExchangeRelease String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact("bar", "baz"); assertEquals(r, "foo", "failing compareAndExchangeRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "failing compareAndExchangeRelease String value"); + assertEquals("foo", x, "failing compareAndExchangeRelease String value"); } { @@ -411,14 +409,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "success weakCompareAndSetPlain String value"); + assertEquals("bar", x, "success weakCompareAndSetPlain String value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact("foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetPlain String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "failing weakCompareAndSetPlain String value"); + assertEquals("bar", x, "failing weakCompareAndSetPlain String value"); } { @@ -430,7 +428,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "success weakCompareAndSetAcquire String"); + assertEquals("foo", x, "success weakCompareAndSetAcquire String"); } { @@ -438,7 +436,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact("bar", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value"); + assertEquals("foo", x, "failing weakCompareAndSetAcquire String value"); } { @@ -450,14 +448,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "success weakCompareAndSetRelease String"); + assertEquals("bar", x, "success weakCompareAndSetRelease String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact("foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "failing weakCompareAndSetRelease String value"); + assertEquals("bar", x, "failing weakCompareAndSetRelease String value"); } { @@ -469,14 +467,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "success weakCompareAndSet String"); + assertEquals("foo", x, "success weakCompareAndSet String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact("bar", "baz"); assertEquals(success, false, "failing weakCompareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "foo", "failing weakCompareAndSetRe String value"); + assertEquals("foo", x, "failing weakCompareAndSetRe String value"); } // Compare set and get @@ -484,9 +482,9 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact("foo"); String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact("bar"); - assertEquals(o, "foo", "getAndSet String"); + assertEquals("foo", o, "getAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "getAndSet String value"); + assertEquals("bar", x, "getAndSet String value"); } // Compare set and get @@ -494,9 +492,9 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact("foo"); String o = (String) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact("bar"); - assertEquals(o, "foo", "getAndSetAcquire String"); + assertEquals("foo", o, "getAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "getAndSetAcquire String value"); + assertEquals("bar", x, "getAndSetAcquire String value"); } // Compare set and get @@ -504,9 +502,9 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact("foo"); String o = (String) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact("bar"); - assertEquals(o, "foo", "getAndSetRelease String"); + assertEquals("foo", o, "getAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, "bar", "getAndSetRelease String value"); + assertEquals("bar", x, "getAndSetRelease String value"); } @@ -536,7 +534,7 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "get String value"); + assertEquals("foo", x, "get String value"); } @@ -544,21 +542,21 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, "bar"); String x = (String) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, "bar", "setVolatile String value"); + assertEquals("bar", x, "setVolatile String value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, "foo"); String x = (String) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, "foo", "setRelease String value"); + assertEquals("foo", x, "setRelease String value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, "bar"); String x = (String) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, "bar", "setOpaque String value"); + assertEquals("bar", x, "setOpaque String value"); } hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); @@ -568,56 +566,56 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "bar"); assertEquals(r, true, "success compareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "success compareAndSet String value"); + assertEquals("bar", x, "success compareAndSet String value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, "foo", "baz"); assertEquals(r, false, "failing compareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "failing compareAndSet String value"); + assertEquals("bar", x, "failing compareAndSet String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchange String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "success compareAndExchange String value"); + assertEquals("foo", x, "success compareAndExchange String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchange String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "failing compareAndExchange String value"); + assertEquals("foo", x, "failing compareAndExchange String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "bar"); assertEquals(r, "foo", "success compareAndExchangeAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "success compareAndExchangeAcquire String value"); + assertEquals("bar", x, "success compareAndExchangeAcquire String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, "foo", "baz"); assertEquals(r, "bar", "failing compareAndExchangeAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "failing compareAndExchangeAcquire String value"); + assertEquals("bar", x, "failing compareAndExchangeAcquire String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "foo"); assertEquals(r, "bar", "success compareAndExchangeRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "success compareAndExchangeRelease String value"); + assertEquals("foo", x, "success compareAndExchangeRelease String value"); } { String r = (String) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, "bar", "baz"); assertEquals(r, "foo", "failing compareAndExchangeRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "failing compareAndExchangeRelease String value"); + assertEquals("foo", x, "failing compareAndExchangeRelease String value"); } { @@ -629,14 +627,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "success weakCompareAndSetPlain String value"); + assertEquals("bar", x, "success weakCompareAndSetPlain String value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetPlain String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "failing weakCompareAndSetPlain String value"); + assertEquals("bar", x, "failing weakCompareAndSetPlain String value"); } { @@ -648,14 +646,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "success weakCompareAndSetAcquire String"); + assertEquals("foo", x, "success weakCompareAndSetAcquire String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "failing weakCompareAndSetAcquire String value"); + assertEquals("foo", x, "failing weakCompareAndSetAcquire String value"); } { @@ -667,14 +665,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "success weakCompareAndSetRelease String"); + assertEquals("bar", x, "success weakCompareAndSetRelease String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, "foo", "baz"); assertEquals(success, false, "failing weakCompareAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "failing weakCompareAndSetAcquire String value"); + assertEquals("bar", x, "failing weakCompareAndSetAcquire String value"); } { @@ -686,14 +684,14 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "success weakCompareAndSet String"); + assertEquals("foo", x, "success weakCompareAndSet String"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, "bar", "baz"); assertEquals(success, false, "failing weakCompareAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "foo", "failing weakCompareAndSet String value"); + assertEquals("foo", x, "failing weakCompareAndSet String value"); } // Compare set and get @@ -701,27 +699,27 @@ public class VarHandleTestMethodHandleAccessString extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); String o = (String) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, "bar"); - assertEquals(o, "foo", "getAndSet String"); + assertEquals("foo", o, "getAndSet String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "getAndSet String value"); + assertEquals("bar", x, "getAndSet String value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); String o = (String) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, "bar"); - assertEquals(o, "foo", "getAndSetAcquire String"); + assertEquals("foo", o, "getAndSetAcquire String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "getAndSetAcquire String value"); + assertEquals("bar", x, "getAndSetAcquire String value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, "foo"); String o = (String) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, "bar"); - assertEquals(o, "foo", "getAndSetRelease String"); + assertEquals("foo", o, "getAndSetRelease String"); String x = (String) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, "bar", "getAndSetRelease String value"); + assertEquals("bar", x, "getAndSetRelease String value"); } diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java index eb6327d4c55..b10466a1fc7 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeBoolean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeBoolean - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeBoolean - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean + * @run junit/othervm VarHandleTestMethodTypeBoolean + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeBoolean + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeBoolean */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest { static final boolean static_final_v = true; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeBoolean.class, "final_v", boolean.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(boolean[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeBoolean extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeBoolean recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java index 08b834699af..ce8686ebd74 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeByte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeByte - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeByte - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte + * @run junit/othervm VarHandleTestMethodTypeByte + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeByte + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeByte */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeByte extends VarHandleBaseTest { static final byte static_final_v = (byte)0x01; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeByte.class, "final_v", byte.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(byte[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeByte extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeByte recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java index 25aa62825b7..d89af7f212c 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeChar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeChar - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeChar - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar + * @run junit/othervm VarHandleTestMethodTypeChar + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeChar + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeChar */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeChar extends VarHandleBaseTest { static final char static_final_v = '\u0123'; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeChar.class, "final_v", char.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(char[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeChar extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeChar recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java index c3f8d22435b..0363a996ceb 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeDouble.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeDouble - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeDouble - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble + * @run junit/othervm VarHandleTestMethodTypeDouble + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeDouble + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeDouble */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest { static final double static_final_v = 1.0d; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeDouble.class, "final_v", double.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(double[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeDouble extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeDouble recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java index 0d05270b3ac..c8b965e41df 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeFloat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeFloat - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeFloat - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat + * @run junit/othervm VarHandleTestMethodTypeFloat + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeFloat + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeFloat */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest { static final float static_final_v = 1.0f; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeFloat.class, "final_v", float.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(float[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeFloat extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeFloat recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java index a431c0a889e..e09427c55c7 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeInt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeInt - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeInt - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt + * @run junit/othervm VarHandleTestMethodTypeInt + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeInt + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeInt */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeInt extends VarHandleBaseTest { static final int static_final_v = 0x01234567; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeInt.class, "final_v", int.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(int[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeInt extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeInt recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java index 53b9257d700..5944e935877 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeLong.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeLong - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeLong - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong + * @run junit/othervm VarHandleTestMethodTypeLong + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeLong + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeLong */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeLong extends VarHandleBaseTest { static final long static_final_v = 0x0123456789ABCDEFL; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeLong.class, "final_v", long.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(long[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeLong extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeLong recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java index 10dd5832c9b..fdb30ee88aa 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeShort.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeShort - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeShort - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort + * @run junit/othervm VarHandleTestMethodTypeShort + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeShort + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeShort */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeShort extends VarHandleBaseTest { static final short static_final_v = (short)0x0123; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeShort.class, "final_v", short.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(short[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeShort extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeShort recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java index d823a21d69f..2a5284ca36e 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodTypeString.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodTypeString - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeString - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString + * @run junit/othervm VarHandleTestMethodTypeString + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodTypeString + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodTypeString */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodTypeString extends VarHandleBaseTest { static final String static_final_v = "foo"; @@ -63,7 +63,7 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodTypeString.class, "final_v", String.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle(String[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodTypeString extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodTypeString recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestReflection.java b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestReflection.java index b20e18d263e..2c22fd5595b 100644 --- a/test/jdk/java/lang/invoke/VarHandles/VarHandleTestReflection.java +++ b/test/jdk/java/lang/invoke/VarHandles/VarHandleTestReflection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -23,11 +23,9 @@ /* * @test - * @run testng VarHandleTestReflection + * @run junit VarHandleTestReflection */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandleInfo; @@ -36,11 +34,16 @@ import java.lang.invoke.VarHandle; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.stream.Stream; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestReflection extends VarHandleBaseTest { String string; - @DataProvider public static Object[][] accessModesProvider() { return Stream.of(VarHandle.AccessMode.values()). map(am -> new Object[]{am}). @@ -52,17 +55,19 @@ public class VarHandleTestReflection extends VarHandleBaseTest { findVarHandle(VarHandleTestReflection.class, "string", String.class); } - @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("accessModesProvider") public void methodInvocationArgumentMismatch(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); // Try a reflective invoke using a Method, with no arguments Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class); - vhm.invoke(v, new Object[]{}); + assertThrows(IllegalArgumentException.class, () -> vhm.invoke(v, new Object[]{})); } - @Test(dataProvider = "accessModesProvider") + @ParameterizedTest + @MethodSource("accessModesProvider") public void methodInvocationMatchingArguments(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); @@ -70,17 +75,15 @@ public class VarHandleTestReflection extends VarHandleBaseTest { Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class); Object arg = new Object[0]; - try { - vhm.invoke(v, arg); - } catch (InvocationTargetException e) { - if (!(e.getCause() instanceof UnsupportedOperationException)) { - throw new RuntimeException("expected UnsupportedOperationException but got: " - + e.getCause().getClass().getName(), e); - } + var e = assertThrows(InvocationTargetException.class, () -> vhm.invoke(v, arg)); + if (!(e.getCause() instanceof UnsupportedOperationException)) { + throw new RuntimeException("expected UnsupportedOperationException but got: " + + e.getCause().getClass().getName(), e); } } - @Test(dataProvider = "accessModesProvider", expectedExceptions = UnsupportedOperationException.class) + @ParameterizedTest + @MethodSource("accessModesProvider") public void methodHandleInvoke(VarHandle.AccessMode accessMode) throws Throwable { VarHandle v = handle(); @@ -90,10 +93,13 @@ public class VarHandleTestReflection extends VarHandleBaseTest { VarHandle.class.getMethod(accessMode.methodName(), Object[].class)); // Use invoke to avoid WrongMethodTypeException for // non-signature-polymorphic return types - Object o = (Object) mh.invoke(v, new Object[]{}); + assertThrows(UnsupportedOperationException.class, () -> { + Object o = (Object) mh.invoke(v, new Object[]{}); + }); } - @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("accessModesProvider") public void methodInvocationFromMethodInfo(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); @@ -104,10 +110,13 @@ public class VarHandleTestReflection extends VarHandleBaseTest { VarHandle.class.getMethod(accessMode.methodName(), Object[].class)); MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); Method im = info.reflectAs(Method.class, MethodHandles.lookup()); - im.invoke(v, new Object[]{}); + assertThrows(IllegalArgumentException.class, () -> { + im.invoke(v, new Object[]{}); + }); } - @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("accessModesProvider") public void reflectAsFromVarHandleInvoker(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); @@ -116,10 +125,11 @@ public class VarHandleTestReflection extends VarHandleBaseTest { MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); - info.reflectAs(Method.class, MethodHandles.lookup()); + assertThrows(IllegalArgumentException.class, () -> info.reflectAs(Method.class, MethodHandles.lookup())); } - @Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) + @ParameterizedTest + @MethodSource("accessModesProvider") public void reflectAsFromFindVirtual(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); @@ -128,6 +138,6 @@ public class VarHandleTestReflection extends VarHandleBaseTest { MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); - info.reflectAs(Method.class, MethodHandles.lookup()); + assertThrows(IllegalArgumentException.class, () -> info.reflectAs(Method.class, MethodHandles.lookup())); } } diff --git a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template index f3c90c5e8cc..b18dbb6e1b0 100644 --- a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template +++ b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -23,28 +23,30 @@ /* * @test - * @run testng/othervm -Diters=10 -Xint VarHandleTestAccess$Type$ + * @run junit/othervm -Diters=10 -Xint VarHandleTestAccess$Type$ * * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds * - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccess$Type$ - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccess$Type$ - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccess$Type$ + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestAccess$Type$ + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestAccess$Type$ + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestAccess$Type$ */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { static final $type$ static_final_v = $value1$; @@ -115,7 +117,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { return vhs.toArray(new VarHandle[0]); } - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestAccess$Type$.class, "final_v", $type$.class); @@ -135,8 +137,6 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { #end[String] } - - @DataProvider public Object[][] varHandlesProvider() throws Exception { List vhs = new ArrayList<>(); vhs.add(vhField); @@ -166,7 +166,8 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("varHandlesProvider") public void testIsAccessModeSupported(VarHandle vh) { assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); @@ -236,8 +237,6 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { #end[Bitwise] } - - @DataProvider public Object[][] typesProvider() throws Exception { List types = new ArrayList<>(); types.add(new Object[] {vhField, Arrays.asList(VarHandleTestAccess$Type$.class)}); @@ -247,16 +246,16 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { return types.stream().toArray(Object[][]::new); } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), $type$.class); + assertEquals($type$.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - @Test public void testLookupInstanceToStatic() { checkIAE("Lookup of static final field to instance final field", () -> { @@ -283,8 +282,6 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { }); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -335,7 +332,8 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -348,26 +346,26 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { // Plain { $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "get $type$ value"); + assertEquals($value1$, x, "get $type$ value"); } // Volatile { $type$ x = ($type$) vh.getVolatile(recv); - assertEquals(x, $value1$, "getVolatile $type$ value"); + assertEquals($value1$, x, "getVolatile $type$ value"); } // Lazy { $type$ x = ($type$) vh.getAcquire(recv); - assertEquals(x, $value1$, "getRelease $type$ value"); + assertEquals($value1$, x, "getRelease $type$ value"); } // Opaque { $type$ x = ($type$) vh.getOpaque(recv); - assertEquals(x, $value1$, "getOpaque $type$ value"); + assertEquals($value1$, x, "getOpaque $type$ value"); } } @@ -492,26 +490,26 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { // Plain { $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "get $type$ value"); + assertEquals($value1$, x, "get $type$ value"); } // Volatile { $type$ x = ($type$) vh.getVolatile(); - assertEquals(x, $value1$, "getVolatile $type$ value"); + assertEquals($value1$, x, "getVolatile $type$ value"); } // Lazy { $type$ x = ($type$) vh.getAcquire(); - assertEquals(x, $value1$, "getRelease $type$ value"); + assertEquals($value1$, x, "getRelease $type$ value"); } // Opaque { $type$ x = ($type$) vh.getOpaque(); - assertEquals(x, $value1$, "getOpaque $type$ value"); + assertEquals($value1$, x, "getOpaque $type$ value"); } } @@ -637,7 +635,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { { vh.set(recv, $value1$); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "set $type$ value"); + assertEquals($value1$, x, "set $type$ value"); } @@ -645,21 +643,21 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { { vh.setVolatile(recv, $value2$); $type$ x = ($type$) vh.getVolatile(recv); - assertEquals(x, $value2$, "setVolatile $type$ value"); + assertEquals($value2$, x, "setVolatile $type$ value"); } // Lazy { vh.setRelease(recv, $value1$); $type$ x = ($type$) vh.getAcquire(recv); - assertEquals(x, $value1$, "setRelease $type$ value"); + assertEquals($value1$, x, "setRelease $type$ value"); } // Opaque { vh.setOpaque(recv, $value2$); $type$ x = ($type$) vh.getOpaque(recv); - assertEquals(x, $value2$, "setOpaque $type$ value"); + assertEquals($value2$, x, "setOpaque $type$ value"); } #if[CAS] @@ -670,56 +668,56 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { boolean r = vh.compareAndSet(recv, $value1$, $value2$); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "success compareAndSet $type$ value"); + assertEquals($value2$, x, "success compareAndSet $type$ value"); } { boolean r = vh.compareAndSet(recv, $value1$, $value3$); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "failing compareAndSet $type$ value"); + assertEquals($value2$, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchange $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "success compareAndExchange $type$ value"); + assertEquals($value1$, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange(recv, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchange $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "failing compareAndExchange $type$ value"); + assertEquals($value1$, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value2$); assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire(recv, $value1$, $value3$); assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease(recv, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -730,14 +728,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "success weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = vh.weakCompareAndSetPlain(recv, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "failing weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -748,14 +746,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "success weakCompareAndSetAcquire $type$"); + assertEquals($value1$, x, "success weakCompareAndSetAcquire $type$"); } { boolean success = vh.weakCompareAndSetAcquire(recv, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -766,14 +764,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "success weakCompareAndSetRelease $type$"); + assertEquals($value2$, x, "success weakCompareAndSetRelease $type$"); } { boolean success = vh.weakCompareAndSetRelease(recv, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "failing weakCompareAndSetRelease $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetRelease $type$ value"); } { @@ -784,14 +782,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "success weakCompareAndSet $type$ value"); + assertEquals($value1$, x, "success weakCompareAndSet $type$ value"); } { boolean success = vh.weakCompareAndSet(recv, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value1$, "failing weakCompareAndSet $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSet $type$ value"); } // Compare set and get @@ -799,27 +797,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndSet(recv, $value2$); - assertEquals(o, $value1$, "getAndSet $type$"); + assertEquals($value1$, o, "getAndSet $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "getAndSet $type$ value"); + assertEquals($value2$, x, "getAndSet $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndSetAcquire(recv, $value2$); - assertEquals(o, $value1$, "getAndSetAcquire $type$"); + assertEquals($value1$, o, "getAndSetAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "getAndSetAcquire $type$ value"); + assertEquals($value2$, x, "getAndSetAcquire $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndSetRelease(recv, $value2$); - assertEquals(o, $value1$, "getAndSetRelease $type$"); + assertEquals($value1$, o, "getAndSetRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, $value2$, "getAndSetRelease $type$ value"); + assertEquals($value2$, x, "getAndSetRelease $type$ value"); } #end[CAS] @@ -829,27 +827,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndAdd(recv, $value2$); - assertEquals(o, $value1$, "getAndAdd $type$"); + assertEquals($value1$, o, "getAndAdd $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAdd $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndAddAcquire(recv, $value2$); - assertEquals(o, $value1$, "getAndAddAcquire $type$"); + assertEquals($value1$, o, "getAndAddAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddAcquire $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndAddRelease(recv, $value2$); - assertEquals(o, $value1$, "getAndAddRelease$type$"); + assertEquals($value1$, o, "getAndAddRelease$type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -859,27 +857,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseOr(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOr $type$"); + assertEquals($value1$, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOr $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseOrAcquire(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrAcquire $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseOrRelease(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -887,27 +885,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseAnd(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAnd $type$"); + assertEquals($value1$, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAnd $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseAndAcquire(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndAcquire $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseAndRelease(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -915,27 +913,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseXor(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXor $type$"); + assertEquals($value1$, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXor $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseXorAcquire(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorAcquire $type$ value"); } { vh.set(recv, $value1$); $type$ o = ($type$) vh.getAndBitwiseXorRelease(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) vh.get(recv); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } @@ -1046,7 +1044,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { { vh.set($value1$); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "set $type$ value"); + assertEquals($value1$, x, "set $type$ value"); } @@ -1054,21 +1052,21 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { { vh.setVolatile($value2$); $type$ x = ($type$) vh.getVolatile(); - assertEquals(x, $value2$, "setVolatile $type$ value"); + assertEquals($value2$, x, "setVolatile $type$ value"); } // Lazy { vh.setRelease($value1$); $type$ x = ($type$) vh.getAcquire(); - assertEquals(x, $value1$, "setRelease $type$ value"); + assertEquals($value1$, x, "setRelease $type$ value"); } // Opaque { vh.setOpaque($value2$); $type$ x = ($type$) vh.getOpaque(); - assertEquals(x, $value2$, "setOpaque $type$ value"); + assertEquals($value2$, x, "setOpaque $type$ value"); } #if[CAS] @@ -1079,56 +1077,56 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { boolean r = vh.compareAndSet($value1$, $value2$); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "success compareAndSet $type$ value"); + assertEquals($value2$, x, "success compareAndSet $type$ value"); } { boolean r = vh.compareAndSet($value1$, $value3$); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "failing compareAndSet $type$ value"); + assertEquals($value2$, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange($value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchange $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "success compareAndExchange $type$ value"); + assertEquals($value1$, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange($value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchange $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "failing compareAndExchange $type$ value"); + assertEquals($value1$, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value2$); assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire($value1$, $value3$); assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease($value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -1139,14 +1137,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "success weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = vh.weakCompareAndSetPlain($value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "failing weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -1157,14 +1155,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "success weakCompareAndSetAcquire $type$"); + assertEquals($value1$, x, "success weakCompareAndSetAcquire $type$"); } { boolean success = vh.weakCompareAndSetAcquire($value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -1175,14 +1173,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "success weakCompareAndSetRelease $type$"); + assertEquals($value2$, x, "success weakCompareAndSetRelease $type$"); } { boolean success = vh.weakCompareAndSetRelease($value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "failing weakCompareAndSetRelease $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetRelease $type$ value"); } { @@ -1193,14 +1191,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "success weakCompareAndSet $type$"); + assertEquals($value1$, x, "success weakCompareAndSet $type$"); } { boolean success = vh.weakCompareAndSet($value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value1$, "failing weakCompareAndSet $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSet $type$ value"); } // Compare set and get @@ -1208,27 +1206,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set($value1$); $type$ o = ($type$) vh.getAndSet($value2$); - assertEquals(o, $value1$, "getAndSet $type$"); + assertEquals($value1$, o, "getAndSet $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "getAndSet $type$ value"); + assertEquals($value2$, x, "getAndSet $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndSetAcquire($value2$); - assertEquals(o, $value1$, "getAndSetAcquire $type$"); + assertEquals($value1$, o, "getAndSetAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "getAndSetAcquire $type$ value"); + assertEquals($value2$, x, "getAndSetAcquire $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndSetRelease($value2$); - assertEquals(o, $value1$, "getAndSetRelease $type$"); + assertEquals($value1$, o, "getAndSetRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, $value2$, "getAndSetRelease $type$ value"); + assertEquals($value2$, x, "getAndSetRelease $type$ value"); } #end[CAS] @@ -1238,27 +1236,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set($value1$); $type$ o = ($type$) vh.getAndAdd($value2$); - assertEquals(o, $value1$, "getAndAdd $type$"); + assertEquals($value1$, o, "getAndAdd $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAdd $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndAddAcquire($value2$); - assertEquals(o, $value1$, "getAndAddAcquire $type$"); + assertEquals($value1$, o, "getAndAddAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddAcquire $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndAddRelease($value2$); - assertEquals(o, $value1$, "getAndAddRelease$type$"); + assertEquals($value1$, o, "getAndAddRelease$type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -1268,27 +1266,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseOr($value2$); - assertEquals(o, $value1$, "getAndBitwiseOr $type$"); + assertEquals($value1$, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOr $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseOrAcquire($value2$); - assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrAcquire $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseOrRelease($value2$); - assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -1296,27 +1294,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseAnd($value2$); - assertEquals(o, $value1$, "getAndBitwiseAnd $type$"); + assertEquals($value1$, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAnd $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseAndAcquire($value2$); - assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndAcquire $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseAndRelease($value2$); - assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -1324,27 +1322,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseXor($value2$); - assertEquals(o, $value1$, "getAndBitwiseXor $type$"); + assertEquals($value1$, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXor $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseXorAcquire($value2$); - assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorAcquire $type$ value"); } { vh.set($value1$); $type$ o = ($type$) vh.getAndBitwiseXorRelease($value2$); - assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) vh.get(); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } @@ -1458,7 +1456,7 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { { vh.set(array, i, $value1$); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "get $type$ value"); + assertEquals($value1$, x, "get $type$ value"); } @@ -1466,21 +1464,21 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { { vh.setVolatile(array, i, $value2$); $type$ x = ($type$) vh.getVolatile(array, i); - assertEquals(x, $value2$, "setVolatile $type$ value"); + assertEquals($value2$, x, "setVolatile $type$ value"); } // Lazy { vh.setRelease(array, i, $value1$); $type$ x = ($type$) vh.getAcquire(array, i); - assertEquals(x, $value1$, "setRelease $type$ value"); + assertEquals($value1$, x, "setRelease $type$ value"); } // Opaque { vh.setOpaque(array, i, $value2$); $type$ x = ($type$) vh.getOpaque(array, i); - assertEquals(x, $value2$, "setOpaque $type$ value"); + assertEquals($value2$, x, "setOpaque $type$ value"); } #if[CAS] @@ -1491,56 +1489,56 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { boolean r = vh.compareAndSet(array, i, $value1$, $value2$); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "success compareAndSet $type$ value"); + assertEquals($value2$, x, "success compareAndSet $type$ value"); } { boolean r = vh.compareAndSet(array, i, $value1$, $value3$); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "failing compareAndSet $type$ value"); + assertEquals($value2$, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchange $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "success compareAndExchange $type$ value"); + assertEquals($value1$, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange(array, i, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchange $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "failing compareAndExchange $type$ value"); + assertEquals($value1$, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value2$); assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, $value1$, $value3$); assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -1551,14 +1549,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "success weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "failing weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -1569,14 +1567,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "success weakCompareAndSetAcquire $type$"); + assertEquals($value1$, x, "success weakCompareAndSetAcquire $type$"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -1587,14 +1585,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "success weakCompareAndSetRelease $type$"); + assertEquals($value2$, x, "success weakCompareAndSetRelease $type$"); } { boolean success = vh.weakCompareAndSetRelease(array, i, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "failing weakCompareAndSetRelease $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetRelease $type$ value"); } { @@ -1605,14 +1603,14 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "success weakCompareAndSet $type$"); + assertEquals($value1$, x, "success weakCompareAndSet $type$"); } { boolean success = vh.weakCompareAndSet(array, i, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value1$, "failing weakCompareAndSet $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSet $type$ value"); } // Compare set and get @@ -1620,27 +1618,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndSet(array, i, $value2$); - assertEquals(o, $value1$, "getAndSet $type$"); + assertEquals($value1$, o, "getAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "getAndSet $type$ value"); + assertEquals($value2$, x, "getAndSet $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndSetAcquire(array, i, $value2$); - assertEquals(o, $value1$, "getAndSetAcquire $type$"); + assertEquals($value1$, o, "getAndSetAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "getAndSetAcquire $type$ value"); + assertEquals($value2$, x, "getAndSetAcquire $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndSetRelease(array, i, $value2$); - assertEquals(o, $value1$, "getAndSetRelease $type$"); + assertEquals($value1$, o, "getAndSetRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, $value2$, "getAndSetRelease $type$ value"); + assertEquals($value2$, x, "getAndSetRelease $type$ value"); } #end[CAS] @@ -1650,27 +1648,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndAdd(array, i, $value2$); - assertEquals(o, $value1$, "getAndAdd $type$"); + assertEquals($value1$, o, "getAndAdd $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAdd $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndAddAcquire(array, i, $value2$); - assertEquals(o, $value1$, "getAndAddAcquire $type$"); + assertEquals($value1$, o, "getAndAddAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddAcquire $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndAddRelease(array, i, $value2$); - assertEquals(o, $value1$, "getAndAddRelease$type$"); + assertEquals($value1$, o, "getAndAddRelease$type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -1680,27 +1678,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseOr(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOr $type$"); + assertEquals($value1$, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOr $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrAcquire $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -1708,27 +1706,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAnd $type$"); + assertEquals($value1$, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAnd $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndAcquire $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -1736,27 +1734,27 @@ public class VarHandleTestAccess$Type$ extends VarHandleBaseTest { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseXor(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXor $type$"); + assertEquals($value1$, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXor $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorAcquire $type$ value"); } { vh.set(array, i, $value1$); $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } diff --git a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template index c21709d6d37..9a40bfb2780 100644 --- a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template +++ b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -26,25 +26,25 @@ * @bug 8154556 * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAs$Type$ - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAs$Type$ - * @run testng/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAs$Type$ + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAs$Type$ + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestByteArrayAs$Type$ + * @run junit/othervm/timeout=360 -Diters=2000 -XX:CompileThresholdScaling=0.1 -XX:-TieredCompilation VarHandleTestByteArrayAs$Type$ */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { static final int SIZE = $BoxType$.BYTES; @@ -111,7 +111,8 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { } } - @Test(dataProvider = "varHandlesProvider") + @ParameterizedTest + @MethodSource("VarHandleBaseByteArrayTest#varHandlesProvider") public void testIsAccessModeSupported(VarHandleSource vhs) { VarHandle vh = vhs.s; @@ -206,17 +207,16 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { #end[Bitwise] } - @Test(dataProvider = "typesProvider") + @ParameterizedTest + @MethodSource("typesProvider") public void testTypes(VarHandle vh, List> pts) { - assertEquals(vh.varType(), $type$.class); + assertEquals($type$.class, vh.varType()); - assertEquals(vh.coordinateTypes(), pts); + assertEquals(pts, vh.coordinateTypes()); testTypes(vh); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -278,7 +278,8 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -287,7 +288,6 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { } } - static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { VarHandle vh = vhs.s; byte[] array = null; @@ -1272,7 +1272,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "get $type$ value"); + assertEquals(VALUE_1, x, "get $type$ value"); } } } @@ -1291,7 +1291,7 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { { vh.set(array, i, VALUE_1); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "get $type$ value"); + assertEquals(VALUE_1, x, "get $type$ value"); } if (iAligned) { @@ -1299,21 +1299,21 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { { vh.setVolatile(array, i, VALUE_2); $type$ x = ($type$) vh.getVolatile(array, i); - assertEquals(x, VALUE_2, "setVolatile $type$ value"); + assertEquals(VALUE_2, x, "setVolatile $type$ value"); } // Lazy { vh.setRelease(array, i, VALUE_1); $type$ x = ($type$) vh.getAcquire(array, i); - assertEquals(x, VALUE_1, "setRelease $type$ value"); + assertEquals(VALUE_1, x, "setRelease $type$ value"); } // Opaque { vh.setOpaque(array, i, VALUE_2); $type$ x = ($type$) vh.getOpaque(array, i); - assertEquals(x, VALUE_2, "setOpaque $type$ value"); + assertEquals(VALUE_2, x, "setOpaque $type$ value"); } #if[CAS] @@ -1324,56 +1324,56 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndSet $type$ value"); + assertEquals(VALUE_2, x, "success compareAndSet $type$ value"); } { boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndSet $type$ value"); + assertEquals(VALUE_2, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchange $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchange $type$ value"); + assertEquals(VALUE_1, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchange(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchange $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchange $type$ value"); + assertEquals(VALUE_1, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); assertEquals(r, VALUE_1, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "success compareAndExchangeAcquire $type$ value"); + assertEquals(VALUE_2, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire $type$ value"); + assertEquals(VALUE_2, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); assertEquals(r, VALUE_2, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "success compareAndExchangeRelease $type$ value"); + assertEquals(VALUE_1, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); assertEquals(r, VALUE_1, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "failing compareAndExchangeRelease $type$ value"); + assertEquals(VALUE_1, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -1384,14 +1384,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetPlain $type$ value"); + assertEquals(VALUE_2, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = vh.weakCompareAndSetPlain(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetPlain $type$ value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -1402,14 +1402,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSetAcquire $type$"); + assertEquals(VALUE_1, x, "success weakCompareAndSetAcquire $type$"); } { boolean success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -1420,14 +1420,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "success weakCompareAndSetRelease $type$"); + assertEquals(VALUE_2, x, "success weakCompareAndSetRelease $type$"); } { boolean success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_3); assertEquals(success, false, "failing weakCompareAndSetRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "failing weakCompareAndSetRelease $type$ value"); + assertEquals(VALUE_2, x, "failing weakCompareAndSetRelease $type$ value"); } { @@ -1438,14 +1438,14 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "success weakCompareAndSet $type$"); + assertEquals(VALUE_1, x, "success weakCompareAndSet $type$"); } { boolean success = vh.weakCompareAndSet(array, i, VALUE_2, VALUE_3); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1, "failing weakCompareAndSet $type$ value"); + assertEquals(VALUE_1, x, "failing weakCompareAndSet $type$ value"); } // Compare set and get @@ -1453,27 +1453,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndSet(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSet $type$"); + assertEquals(VALUE_1, o, "getAndSet $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSet $type$ value"); + assertEquals(VALUE_2, x, "getAndSet $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndSetAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetAcquire $type$"); + assertEquals(VALUE_1, o, "getAndSetAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetAcquire $type$ value"); + assertEquals(VALUE_2, x, "getAndSetAcquire $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndSetRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndSetRelease $type$"); + assertEquals(VALUE_1, o, "getAndSetRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_2, "getAndSetRelease $type$ value"); + assertEquals(VALUE_2, x, "getAndSetRelease $type$ value"); } #end[CAS] @@ -1483,27 +1483,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndAdd(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAdd $type$"); + assertEquals(VALUE_1, o, "getAndAdd $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAdd $type$ value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAdd $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndAddAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAddAcquire $type$"); + assertEquals(VALUE_1, o, "getAndAddAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAddAcquire $type$ value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAddAcquire $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndAddRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndAddRelease $type$"); + assertEquals(VALUE_1, o, "getAndAddRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 + VALUE_2, "getAndAddRelease $type$ value"); + assertEquals(VALUE_1 + VALUE_2, x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -1513,27 +1513,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseOr(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOr $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOr $type$ value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOr $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOrAcquire $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrAcquire $type$ value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrAcquire $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseOrRelease $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 | VALUE_2, "getAndBitwiseOrRelease $type$ value"); + assertEquals(VALUE_1 | VALUE_2, x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -1541,27 +1541,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseAnd(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAnd $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAnd $type$ value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAnd $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAndAcquire $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndAcquire $type$ value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndAcquire $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseAndRelease $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 & VALUE_2, "getAndBitwiseAndRelease $type$ value"); + assertEquals(VALUE_1 & VALUE_2, x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -1569,27 +1569,27 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseXor(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXor $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXor $type$ value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXor $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXorAcquire $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorAcquire $type$ value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorAcquire $type$ value"); } { vh.set(array, i, VALUE_1); $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, i, VALUE_2); - assertEquals(o, VALUE_1, "getAndBitwiseXorRelease $type$"); + assertEquals(VALUE_1, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) vh.get(array, i); - assertEquals(x, VALUE_1 ^ VALUE_2, "getAndBitwiseXorRelease $type$ value"); + assertEquals(VALUE_1 ^ VALUE_2, x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } @@ -1614,26 +1614,26 @@ public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest { // Plain { $type$ x = ($type$) vh.get(array, i); - assertEquals(x, v, "get $type$ value"); + assertEquals(v, x, "get $type$ value"); } if (iAligned) { // Volatile { $type$ x = ($type$) vh.getVolatile(array, i); - assertEquals(x, v, "getVolatile $type$ value"); + assertEquals(v, x, "getVolatile $type$ value"); } // Lazy { $type$ x = ($type$) vh.getAcquire(array, i); - assertEquals(x, v, "getRelease $type$ value"); + assertEquals(v, x, "getRelease $type$ value"); } // Opaque { $type$ x = ($type$) vh.getOpaque(array, i); - assertEquals(x, v, "getOpaque $type$ value"); + assertEquals(v, x, "getOpaque $type$ value"); } } } diff --git a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template index 4a9fa7c4fe8..a347b232d7e 100644 --- a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template +++ b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -25,22 +25,22 @@ * @test * @comment Set CompileThresholdScaling to 0.1 so that the warmup loop sets to 2000 iterations * to hit compilation thresholds - * @run testng/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccess$Type$ + * @run junit/othervm -Diters=2000 -XX:CompileThresholdScaling=0.1 VarHandleTestMethodHandleAccess$Type$ */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { static final $type$ static_final_v = $value1$; @@ -60,7 +60,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodHandleAccess$Type$.class, "final_v", $type$.class); @@ -77,8 +77,6 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle($type$[].class); } - - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -111,7 +109,8 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -120,13 +119,12 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } } - static void testInstanceField(VarHandleTestMethodHandleAccess$Type$ recv, Handles hs) throws Throwable { // Plain { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "set $type$ value"); + assertEquals($value1$, x, "set $type$ value"); } @@ -134,21 +132,21 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, $value2$); $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); - assertEquals(x, $value2$, "setVolatile $type$ value"); + assertEquals($value2$, x, "setVolatile $type$ value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, $value1$); $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); - assertEquals(x, $value1$, "setRelease $type$ value"); + assertEquals($value1$, x, "setRelease $type$ value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, $value2$); $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); - assertEquals(x, $value2$, "setOpaque $type$ value"); + assertEquals($value2$, x, "setOpaque $type$ value"); } #if[CAS] @@ -159,56 +157,56 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value2$); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "success compareAndSet $type$ value"); + assertEquals($value2$, x, "success compareAndSet $type$ value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, $value1$, $value3$); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "failing compareAndSet $type$ value"); + assertEquals($value2$, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchange $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "success compareAndExchange $type$ value"); + assertEquals($value1$, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(recv, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchange $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "failing compareAndExchange $type$ value"); + assertEquals($value1$, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value2$); assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, $value1$, $value3$); assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -220,14 +218,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "success weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(recv, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "failing weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -239,14 +237,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "success weakCompareAndSetAcquire $type$"); + assertEquals($value1$, x, "success weakCompareAndSetAcquire $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -258,14 +256,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "success weakCompareAndSetRelease $type$"); + assertEquals($value2$, x, "success weakCompareAndSetRelease $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "failing weakCompareAndSetRelease $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetRelease $type$ value"); } { @@ -277,22 +275,22 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "success weakCompareAndSet $type$"); + assertEquals($value1$, x, "success weakCompareAndSet $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value1$, "failing weakCompareAndSet $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSet $type$ value"); } // Compare set and get { $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndSet $type$"); + assertEquals($value1$, o, "getAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, $value2$, "getAndSet $type$ value"); + assertEquals($value2$, x, "getAndSet $type$ value"); } #end[CAS] @@ -302,27 +300,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndAdd $type$"); + assertEquals($value1$, o, "getAndAdd $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAdd $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndAddAcquire $type$"); + assertEquals($value1$, o, "getAndAddAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndAddRelease $type$"); + assertEquals($value1$, o, "getAndAddRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -332,27 +330,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOr $type$"); + assertEquals($value1$, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOr $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -360,27 +358,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAnd $type$"); + assertEquals($value1$, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAnd $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -388,27 +386,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXor $type$"); + assertEquals($value1$, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXor $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(recv, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(recv, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(recv); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } @@ -457,7 +455,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "set $type$ value"); + assertEquals($value1$, x, "set $type$ value"); } @@ -465,21 +463,21 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact($value2$); $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); - assertEquals(x, $value2$, "setVolatile $type$ value"); + assertEquals($value2$, x, "setVolatile $type$ value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact($value1$); $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); - assertEquals(x, $value1$, "setRelease $type$ value"); + assertEquals($value1$, x, "setRelease $type$ value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact($value2$); $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); - assertEquals(x, $value2$, "setOpaque $type$ value"); + assertEquals($value2$, x, "setOpaque $type$ value"); } #if[CAS] @@ -490,56 +488,56 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value2$); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "success compareAndSet $type$ value"); + assertEquals($value2$, x, "success compareAndSet $type$ value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact($value1$, $value3$); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "failing compareAndSet $type$ value"); + assertEquals($value2$, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact($value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchange $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "success compareAndExchange $type$ value"); + assertEquals($value1$, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact($value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchange $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "failing compareAndExchange $type$ value"); + assertEquals($value1$, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value2$); assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact($value1$, $value3$); assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact($value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -551,14 +549,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "success weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact($value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "failing weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -570,7 +568,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "success weakCompareAndSetAcquire $type$"); + assertEquals($value1$, x, "success weakCompareAndSetAcquire $type$"); } { @@ -578,7 +576,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { boolean success = (boolean) mh.invokeExact($value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -590,14 +588,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "success weakCompareAndSetRelease $type$"); + assertEquals($value2$, x, "success weakCompareAndSetRelease $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact($value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "failing weakCompareAndSetRelease $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetRelease $type$ value"); } { @@ -609,14 +607,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "success weakCompareAndSet $type$"); + assertEquals($value1$, x, "success weakCompareAndSet $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact($value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value1$, "failing weakCompareAndSetRe $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetRe $type$ value"); } // Compare set and get @@ -624,9 +622,9 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact($value2$); - assertEquals(o, $value1$, "getAndSet $type$"); + assertEquals($value1$, o, "getAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "getAndSet $type$ value"); + assertEquals($value2$, x, "getAndSet $type$ value"); } // Compare set and get @@ -634,9 +632,9 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndSetAcquire $type$"); + assertEquals($value1$, o, "getAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "getAndSetAcquire $type$ value"); + assertEquals($value2$, x, "getAndSetAcquire $type$ value"); } // Compare set and get @@ -644,9 +642,9 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndSetRelease $type$"); + assertEquals($value1$, o, "getAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, $value2$, "getAndSetRelease $type$ value"); + assertEquals($value2$, x, "getAndSetRelease $type$ value"); } #end[CAS] @@ -656,27 +654,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact($value2$); - assertEquals(o, $value1$, "getAndAdd $type$"); + assertEquals($value1$, o, "getAndAdd $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAdd $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndAddAcquire $type$"); + assertEquals($value1$, o, "getAndAddAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndAddRelease $type$"); + assertEquals($value1$, o, "getAndAddRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -686,27 +684,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseOr $type$"); + assertEquals($value1$, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOr $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -714,27 +712,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseAnd $type$"); + assertEquals($value1$, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAnd $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -742,27 +740,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseXor $type$"); + assertEquals($value1$, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXor $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact($value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact($value2$); - assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } @@ -814,7 +812,7 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "get $type$ value"); + assertEquals($value1$, x, "get $type$ value"); } @@ -822,21 +820,21 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { { hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, $value2$); $type$ x = ($type$) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); - assertEquals(x, $value2$, "setVolatile $type$ value"); + assertEquals($value2$, x, "setVolatile $type$ value"); } // Lazy { hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, $value1$); $type$ x = ($type$) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); - assertEquals(x, $value1$, "setRelease $type$ value"); + assertEquals($value1$, x, "setRelease $type$ value"); } // Opaque { hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, $value2$); $type$ x = ($type$) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); - assertEquals(x, $value2$, "setOpaque $type$ value"); + assertEquals($value2$, x, "setOpaque $type$ value"); } #if[CAS] @@ -847,56 +845,56 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value2$); assertEquals(r, true, "success compareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "success compareAndSet $type$ value"); + assertEquals($value2$, x, "success compareAndSet $type$ value"); } { boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, $value1$, $value3$); assertEquals(r, false, "failing compareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "failing compareAndSet $type$ value"); + assertEquals($value2$, x, "failing compareAndSet $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchange $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "success compareAndExchange $type$ value"); + assertEquals($value1$, x, "success compareAndExchange $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE).invokeExact(array, i, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchange $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "failing compareAndExchange $type$ value"); + assertEquals($value1$, x, "failing compareAndExchange $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value2$); assertEquals(r, $value1$, "success compareAndExchangeAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "success compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "success compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, $value1$, $value3$); assertEquals(r, $value2$, "failing compareAndExchangeAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "failing compareAndExchangeAcquire $type$ value"); + assertEquals($value2$, x, "failing compareAndExchangeAcquire $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value1$); assertEquals(r, $value2$, "success compareAndExchangeRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "success compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "success compareAndExchangeRelease $type$ value"); } { $type$ r = ($type$) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, $value2$, $value3$); assertEquals(r, $value1$, "failing compareAndExchangeRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "failing compareAndExchangeRelease $type$ value"); + assertEquals($value1$, x, "failing compareAndExchangeRelease $type$ value"); } { @@ -908,14 +906,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetPlain $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "success weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "success weakCompareAndSetPlain $type$ value"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_PLAIN).invokeExact(array, i, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetPlain $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "failing weakCompareAndSetPlain $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetPlain $type$ value"); } { @@ -927,14 +925,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "success weakCompareAndSetAcquire $type$"); + assertEquals($value1$, x, "success weakCompareAndSetAcquire $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -946,14 +944,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "success weakCompareAndSetRelease $type$"); + assertEquals($value2$, x, "success weakCompareAndSetRelease $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, $value1$, $value3$); assertEquals(success, false, "failing weakCompareAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "failing weakCompareAndSetAcquire $type$ value"); + assertEquals($value2$, x, "failing weakCompareAndSetAcquire $type$ value"); } { @@ -965,14 +963,14 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { } assertEquals(success, true, "success weakCompareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "success weakCompareAndSet $type$"); + assertEquals($value1$, x, "success weakCompareAndSet $type$"); } { boolean success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, $value2$, $value3$); assertEquals(success, false, "failing weakCompareAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value1$, "failing weakCompareAndSet $type$ value"); + assertEquals($value1$, x, "failing weakCompareAndSet $type$ value"); } // Compare set and get @@ -980,27 +978,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndSet $type$"); + assertEquals($value1$, o, "getAndSet $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "getAndSet $type$ value"); + assertEquals($value2$, x, "getAndSet $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_ACQUIRE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndSetAcquire $type$"); + assertEquals($value1$, o, "getAndSetAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "getAndSetAcquire $type$ value"); + assertEquals($value2$, x, "getAndSetAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_SET_RELEASE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndSetRelease $type$"); + assertEquals($value1$, o, "getAndSetRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, $value2$, "getAndSetRelease $type$ value"); + assertEquals($value2$, x, "getAndSetRelease $type$ value"); } #end[CAS] @@ -1010,27 +1008,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndAdd $type$"); + assertEquals($value1$, o, "getAndAdd $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAdd $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAdd $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_ACQUIRE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndAddAcquire $type$"); + assertEquals($value1$, o, "getAndAddAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddAcquire $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_ADD_RELEASE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndAddRelease $type$"); + assertEquals($value1$, o, "getAndAddRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ + $value2$), "getAndAddRelease $type$ value"); + assertEquals(($type$)($value1$ + $value2$), x, "getAndAddRelease $type$ value"); } #end[AtomicAdd] @@ -1040,27 +1038,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOr $type$"); + assertEquals($value1$, o, "getAndBitwiseOr $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOr $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOr $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_ACQUIRE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseOrAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrAcquire $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_OR_RELEASE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseOrRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseOrRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ | $value2$), "getAndBitwiseOrRelease $type$ value"); + assertEquals(($type$)($value1$ | $value2$), x, "getAndBitwiseOrRelease $type$ value"); } // get and bitwise and @@ -1068,27 +1066,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAnd $type$"); + assertEquals($value1$, o, "getAndBitwiseAnd $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAnd $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAnd $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_ACQUIRE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseAndAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndAcquire $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_AND_RELEASE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseAndRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseAndRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ & $value2$), "getAndBitwiseAndRelease $type$ value"); + assertEquals(($type$)($value1$ & $value2$), x, "getAndBitwiseAndRelease $type$ value"); } // get and bitwise xor @@ -1096,27 +1094,27 @@ public class VarHandleTestMethodHandleAccess$Type$ extends VarHandleBaseTest { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXor $type$"); + assertEquals($value1$, o, "getAndBitwiseXor $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXor $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXor $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_ACQUIRE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorAcquire $type$"); + assertEquals($value1$, o, "getAndBitwiseXorAcquire $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorAcquire $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorAcquire $type$ value"); } { hs.get(TestAccessMode.SET).invokeExact(array, i, $value1$); $type$ o = ($type$) hs.get(TestAccessMode.GET_AND_BITWISE_XOR_RELEASE).invokeExact(array, i, $value2$); - assertEquals(o, $value1$, "getAndBitwiseXorRelease $type$"); + assertEquals($value1$, o, "getAndBitwiseXorRelease $type$"); $type$ x = ($type$) hs.get(TestAccessMode.GET).invokeExact(array, i); - assertEquals(x, ($type$)($value1$ ^ $value2$), "getAndBitwiseXorRelease $type$ value"); + assertEquals(($type$)($value1$ ^ $value2$), x, "getAndBitwiseXorRelease $type$ value"); } #end[Bitwise] } diff --git a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template index 85ecf9bb95c..77531cc309f 100644 --- a/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template +++ b/test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodType.java.template @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -24,26 +24,26 @@ /* * @test * @bug 8156486 - * @run testng/othervm VarHandleTestMethodType$Type$ - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$ - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodType$Type$ - * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$ + * @run junit/othervm VarHandleTestMethodType$Type$ + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=true -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$ + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false VarHandleTestMethodType$Type$ + * @run junit/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true VarHandleTestMethodType$Type$ */ -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.testng.Assert.*; - import static java.lang.invoke.MethodType.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest { static final $type$ static_final_v = $value1$; @@ -63,7 +63,7 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest { VarHandle vhArray; - @BeforeClass + @BeforeAll public void setup() throws Exception { vhFinalField = MethodHandles.lookup().findVarHandle( VarHandleTestMethodType$Type$.class, "final_v", $type$.class); @@ -80,7 +80,6 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest { vhArray = MethodHandles.arrayElementVarHandle($type$[].class); } - @DataProvider public Object[][] accessTestCaseProvider() throws Exception { List> cases = new ArrayList<>(); @@ -115,7 +114,8 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest { return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); } - @Test(dataProvider = "accessTestCaseProvider") + @ParameterizedTest + @MethodSource("accessTestCaseProvider") public void testAccess(String desc, AccessTestCase atc) throws Throwable { T t = atc.get(); int iters = atc.requiresLoop() ? ITERS : 1; @@ -124,7 +124,6 @@ public class VarHandleTestMethodType$Type$ extends VarHandleBaseTest { } } - static void testInstanceFieldWrongMethodType(VarHandleTestMethodType$Type$ recv, VarHandle vh) throws Throwable { // Get // Incorrect argument types diff --git a/test/jdk/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java b/test/jdk/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java index 343b15a1caf..11cd6ec233c 100644 --- a/test/jdk/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java +++ b/test/jdk/java/lang/invoke/VarHandles/accessibility/TestFieldLookupAccessibility.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -27,14 +27,11 @@ * @compile TestFieldLookupAccessibility.java * pkg/A.java pkg/B_extends_A.java pkg/C.java * pkg/subpkg/B_extends_A.java pkg/subpkg/C.java - * @run testng/othervm --enable-final-field-mutation=ALL-UNNAMED -DwriteAccess=true TestFieldLookupAccessibility - * @run testng/othervm --illegal-final-field-mutation=deny -DwriteAccess=false TestFieldLookupAccessibility + * @run junit/othervm --enable-final-field-mutation=ALL-UNNAMED -DwriteAccess=true TestFieldLookupAccessibility + * @run junit/othervm --illegal-final-field-mutation=deny -DwriteAccess=false TestFieldLookupAccessibility */ -import static org.testng.Assert.*; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import static org.junit.jupiter.api.Assertions.*; import pkg.B_extends_A; import java.lang.invoke.MethodHandles; @@ -48,11 +45,14 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class TestFieldLookupAccessibility { static boolean writeAccess; - @BeforeClass + @BeforeAll static void setup() { String s = System.getProperty("writeAccess"); assertNotNull(s); @@ -188,8 +188,7 @@ public class TestFieldLookupAccessibility { } } - @DataProvider - public Object[][] lookupProvider() throws Exception { + public static Object[][] lookupProvider() throws Exception { Stream> baseCases = Stream.of( // Look up from same package List.of(pkg.A.class, pkg.A.lookup(), pkg.A.inaccessibleFields()), @@ -215,7 +214,8 @@ public class TestFieldLookupAccessibility { return pl.toArray(); } - @Test(dataProvider = "lookupProvider") + @ParameterizedTest + @MethodSource("lookupProvider") public void test(FieldLookup fl, Class src, MethodHandles.Lookup l, Set inaccessibleFields) { // Add to the expected failures all inaccessible fields due to accessibility modifiers Set expected = fl.inaccessibleFields(inaccessibleFields); @@ -240,10 +240,10 @@ public class TestFieldLookupAccessibility { collect(Collectors.toSet()); if (!actualFieldNames.equals(expected)) { if (actualFieldNames.isEmpty()) { - assertEquals(actualFieldNames, expected, "No accessibility failures:"); + assertEquals(expected, actualFieldNames, "No accessibility failures:"); } else { - assertEquals(actualFieldNames, expected, "Accessibility failures differ:"); + assertEquals(expected, actualFieldNames, "Accessibility failures differ:"); } } else { diff --git a/test/jdk/java/lang/invoke/WrongMethodTypeTest.java b/test/jdk/java/lang/invoke/WrongMethodTypeTest.java index be0c59e0d77..32cbfc545ce 100644 --- a/test/jdk/java/lang/invoke/WrongMethodTypeTest.java +++ b/test/jdk/java/lang/invoke/WrongMethodTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, 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 @@ -21,8 +21,9 @@ * questions. */ -/* @test 8299183 - * @run testng WrongMethodTypeTest +/* @test + * @bug 8299183 + * @run junit WrongMethodTypeTest */ import java.lang.invoke.MethodHandle; @@ -33,9 +34,10 @@ import java.lang.invoke.WrongMethodTypeException; import static java.lang.invoke.MethodType.methodType; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class WrongMethodTypeTest { static final Lookup LOOKUP = MethodHandles.lookup(); @@ -43,13 +45,11 @@ public class WrongMethodTypeTest { @Test public void checkExactType() throws Throwable { String expectedMessage = "handle's method type (int)int but found ()boolean"; - try { - MethodHandle mh = LOOKUP.findStatic(WrongMethodTypeTest.class, "m", methodType(int.class, int.class)); + MethodHandle mh = LOOKUP.findStatic(WrongMethodTypeTest.class, "m", methodType(int.class, int.class)); + var ex = assertThrows(WrongMethodTypeException.class, () -> { boolean b = (boolean)mh.invokeExact(); - fail("Expected WrongMethodTypeException"); - } catch (WrongMethodTypeException ex) { - assertEquals(expectedMessage, ex.getMessage()); - } + }); + assertEquals(expectedMessage, ex.getMessage()); } @Test @@ -57,11 +57,10 @@ public class WrongMethodTypeTest { String expectedMessage = "handle's method type ()int but found ()Void"; VarHandle vh = LOOKUP.findStaticVarHandle(WrongMethodTypeTest.class, "x", int.class) .withInvokeExactBehavior(); - try { + var ex = assertThrows(WrongMethodTypeException.class, () -> { Void o = (Void) vh.get(); - } catch (WrongMethodTypeException ex) { - assertEquals(expectedMessage, ex.getMessage()); - } + }); + assertEquals(expectedMessage, ex.getMessage()); } @Test @@ -69,11 +68,10 @@ public class WrongMethodTypeTest { String expectedMessage = "handle's method type (WrongMethodTypeTest)boolean but found (WrongMethodTypeTest)int"; VarHandle vh = LOOKUP.findVarHandle(WrongMethodTypeTest.class, "y", boolean.class) .withInvokeExactBehavior(); - try { + var ex = assertThrows(WrongMethodTypeException.class, () -> { int o = (int) vh.get(new WrongMethodTypeTest()); - } catch (WrongMethodTypeException ex) { - assertEquals(expectedMessage, ex.getMessage()); - } + }); + assertEquals(expectedMessage, ex.getMessage()); } static int m(int x) { diff --git a/test/jdk/java/lang/invoke/accessClassAndFindClass/TestAccessClass.java b/test/jdk/java/lang/invoke/accessClassAndFindClass/TestAccessClass.java index 083a357a430..23893655c0a 100644 --- a/test/jdk/java/lang/invoke/accessClassAndFindClass/TestAccessClass.java +++ b/test/jdk/java/lang/invoke/accessClassAndFindClass/TestAccessClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @bug 8150782 8207027 8266269 * @compile TestAccessClass.java TestCls.java p/Foo.java q/Bar.java - * @run testng/othervm -ea -esa test.java.lang.invoke.TestAccessClass + * @run junit/othervm -ea -esa test.java.lang.invoke.TestAccessClass */ package test.java.lang.invoke; @@ -36,9 +36,11 @@ import q.Bar; import static java.lang.invoke.MethodHandles.*; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; public class TestAccessClass { @@ -68,17 +70,19 @@ public class TestAccessClass { assertEquals(Class1[].class, aClass); } - @DataProvider - Object[][] illegalAccessAccess() { + static Object[][] illegalAccessAccess() { return new Object[][] { {publicLookup(), Class1.class}, {publicLookup(), TestCls.getPrivateSIC()} }; } - @Test(dataProvider = "illegalAccessAccess", expectedExceptions = {IllegalAccessException.class}) + @ParameterizedTest + @MethodSource("illegalAccessAccess") public void illegalAccessExceptionTest(Lookup lookup, Class klass) throws IllegalAccessException { - lookup.accessClass(klass); + assertThrows(IllegalAccessException.class, () -> { + lookup.accessClass(klass); + }); } @Test @@ -98,8 +102,8 @@ public class TestAccessClass { mh.invoke(null); } - @Test(expectedExceptions = {NullPointerException.class}) + @Test public void illegalArgument() throws IllegalAccessException { - lookup().accessClass(null); + assertThrows(NullPointerException.class, () -> lookup().accessClass(null)); } } diff --git a/test/jdk/java/lang/invoke/accessClassAndFindClass/TestFindClass.java b/test/jdk/java/lang/invoke/accessClassAndFindClass/TestFindClass.java index 54674729fe3..94ec3c54b4f 100644 --- a/test/jdk/java/lang/invoke/accessClassAndFindClass/TestFindClass.java +++ b/test/jdk/java/lang/invoke/accessClassAndFindClass/TestFindClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @bug 8150782 8207027 8266269 * @compile TestFindClass.java TestCls.java p/Foo.java q/Bar.java - * @run testng/othervm -ea -esa test.java.lang.invoke.TestFindClass + * @run junit/othervm -ea -esa test.java.lang.invoke.TestFindClass */ package test.java.lang.invoke; @@ -34,9 +34,11 @@ import q.Bar; import static java.lang.invoke.MethodHandles.*; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import org.testng.annotations.*; +import static org.junit.jupiter.api.Assertions.*; public class TestFindClass { @@ -68,13 +70,12 @@ public class TestFindClass { assertEquals(Class1[].class, aClass); } - @Test(expectedExceptions = {ClassNotFoundException.class}) + @Test public void classNotFoundExceptionTest() throws IllegalAccessException, ClassNotFoundException { - lookup().findClass(PACKAGE_PREFIX + "TestFindClass$NonExistent"); + assertThrows(ClassNotFoundException.class, () -> lookup().findClass(PACKAGE_PREFIX + "TestFindClass$NonExistent")); } - @DataProvider - Object[][] illegalAccessFind() { + static Object[][] illegalAccessFind() { return new Object[][] { {publicLookup(), PACKAGE_PREFIX + "TestFindClass$Class1"}, {publicLookup(), PACKAGE_PREFIX + "TestCls$PrivateSIC"} @@ -84,9 +85,10 @@ public class TestFindClass { /** * Assertion: @throws IllegalAccessException if the class is not accessible, using the allowed access modes. */ - @Test(dataProvider = "illegalAccessFind", expectedExceptions = {ClassNotFoundException.class}) + @ParameterizedTest + @MethodSource("illegalAccessFind") public void illegalAccessExceptionTest(Lookup lookup, String className) throws IllegalAccessException, ClassNotFoundException { - lookup.findClass(className); + assertThrows(ClassNotFoundException.class, () -> lookup.findClass(className)); } @Test @@ -104,8 +106,8 @@ public class TestFindClass { lookup().findClass("[Lp.Foo$T;"); } - @Test(expectedExceptions = {NullPointerException.class}) + @Test public void illegalArgument() throws IllegalAccessException, ClassNotFoundException { - lookup().findClass(null); + assertThrows(NullPointerException.class, () -> lookup().findClass(null)); } } diff --git a/test/jdk/java/lang/invoke/accessClassAndFindClass/TestLookup.java b/test/jdk/java/lang/invoke/accessClassAndFindClass/TestLookup.java index 555213bedcc..b0f2e00adbc 100644 --- a/test/jdk/java/lang/invoke/accessClassAndFindClass/TestLookup.java +++ b/test/jdk/java/lang/invoke/accessClassAndFindClass/TestLookup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -23,15 +23,15 @@ /* @test * @compile TestLookup.java TestCls.java - * @run testng/othervm -ea -esa test.java.lang.invoke.TestLookup + * @run junit/othervm -ea -esa test.java.lang.invoke.TestLookup */ package test.java.lang.invoke; -import org.testng.annotations.Test; - import static java.lang.invoke.MethodHandles.*; -import static org.testng.AssertJUnit.*; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; public class TestLookup { @@ -43,10 +43,10 @@ public class TestLookup { assertNull(lookup2.lookupClass().getClassLoader()); } - @Test(expectedExceptions = {ClassNotFoundException.class}) + @Test public void testPublicCannotLoadUserClass() throws IllegalAccessException, ClassNotFoundException { Lookup lookup = publicLookup(); - lookup.findClass("test.java.lang.invoke.TestCls"); + assertThrows(ClassNotFoundException.class, () -> lookup.findClass("test.java.lang.invoke.TestCls")); } @Test diff --git a/test/jdk/java/lang/invoke/callerSensitive/CallerSensitiveAccess.java b/test/jdk/java/lang/invoke/callerSensitive/CallerSensitiveAccess.java index a6359162629..67aa90ba99c 100644 --- a/test/jdk/java/lang/invoke/callerSensitive/CallerSensitiveAccess.java +++ b/test/jdk/java/lang/invoke/callerSensitive/CallerSensitiveAccess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -24,7 +24,7 @@ /* @test * @bug 8196830 8235351 8257874 * @modules java.base/jdk.internal.reflect - * @run testng/othervm CallerSensitiveAccess + * @run junit/othervm CallerSensitiveAccess * @summary Check Lookup findVirtual, findStatic and unreflect behavior with * caller sensitive methods with focus on AccessibleObject.setAccessible */ @@ -50,17 +50,16 @@ import java.util.stream.Stream; import jdk.internal.reflect.CallerSensitive; -import org.testng.annotations.DataProvider; -import org.testng.annotations.NoInjection; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class CallerSensitiveAccess { /** * Caller sensitive methods in APIs exported by java.base. */ - @DataProvider(name = "callerSensitiveMethods") static Object[][] callerSensitiveMethods() { try (Stream stream = callerSensitiveMethods(Object.class.getModule())) { return stream.map(m -> new Object[]{m, shortDescription(m)}) @@ -72,34 +71,35 @@ public class CallerSensitiveAccess { * Using publicLookup, attempt to use findVirtual or findStatic to obtain a * method handle to a caller sensitive method. */ - @Test(dataProvider = "callerSensitiveMethods", - expectedExceptions = IllegalAccessException.class) - public void testPublicLookupFind(@NoInjection Method method, String desc) throws Exception { + @ParameterizedTest + @MethodSource("callerSensitiveMethods") + public void testPublicLookupFind(Method method, String desc) throws Exception { Lookup lookup = MethodHandles.publicLookup(); Class refc = method.getDeclaringClass(); String name = method.getName(); MethodType mt = MethodType.methodType(method.getReturnType(), method.getParameterTypes()); - if (Modifier.isStatic(method.getModifiers())) { - lookup.findStatic(refc, name, mt); - } else { - lookup.findVirtual(refc, name, mt); - } + assertThrows(IllegalAccessException.class, () -> { + if (Modifier.isStatic(method.getModifiers())) { + lookup.findStatic(refc, name, mt); + } else { + lookup.findVirtual(refc, name, mt); + } + }); } /** * Using publicLookup, attempt to use unreflect to obtain a method handle to a * caller sensitive method. */ - @Test(dataProvider = "callerSensitiveMethods", - expectedExceptions = IllegalAccessException.class) - public void testPublicLookupUnreflect(@NoInjection Method method, String desc) throws Exception { - MethodHandles.publicLookup().unreflect(method); + @ParameterizedTest + @MethodSource("callerSensitiveMethods") + public void testPublicLookupUnreflect(Method method, String desc) throws Exception { + assertThrows(IllegalAccessException.class, () -> MethodHandles.publicLookup().unreflect(method)); } /** * public accessible caller sensitive methods in APIs exported by java.base. */ - @DataProvider(name = "accessibleCallerSensitiveMethods") static Object[][] accessibleCallerSensitiveMethods() { try (Stream stream = callerSensitiveMethods(Object.class.getModule())) { return stream @@ -114,41 +114,43 @@ public class CallerSensitiveAccess { * Using publicLookup, attempt to use unreflect to obtain a method handle to a * caller sensitive method. */ - @Test(dataProvider = "accessibleCallerSensitiveMethods", - expectedExceptions = IllegalAccessException.class) - public void testLookupUnreflect(@NoInjection Method method, String desc) throws Exception { - MethodHandles.publicLookup().unreflect(method); + @ParameterizedTest + @MethodSource("accessibleCallerSensitiveMethods") + public void testLookupUnreflect(Method method, String desc) throws Exception { + assertThrows(IllegalAccessException.class, () -> MethodHandles.publicLookup().unreflect(method)); } /** * Using a Lookup with no original access that can't lookup caller-sensitive * method */ - @Test(dataProvider = "callerSensitiveMethods", - expectedExceptions = IllegalAccessException.class) - public void testLookupNoOriginalAccessFind(@NoInjection Method method, String desc) throws Exception { + @ParameterizedTest + @MethodSource("callerSensitiveMethods") + public void testLookupNoOriginalAccessFind(Method method, String desc) throws Exception { Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.ORIGINAL); assertTrue(lookup.hasFullPrivilegeAccess()); Class refc = method.getDeclaringClass(); String name = method.getName(); MethodType mt = MethodType.methodType(method.getReturnType(), method.getParameterTypes()); - if (Modifier.isStatic(method.getModifiers())) { - lookup.findStatic(refc, name, mt); - } else { - lookup.findVirtual(refc, name, mt); - } + assertThrows(IllegalAccessException.class, () -> { + if (Modifier.isStatic(method.getModifiers())) { + lookup.findStatic(refc, name, mt); + } else { + lookup.findVirtual(refc, name, mt); + } + }); } /** * Using a Lookup with no original access that can't unreflect caller-sensitive * method */ - @Test(dataProvider = "callerSensitiveMethods", - expectedExceptions = IllegalAccessException.class) - public void testLookupNoOriginalAccessUnreflect(@NoInjection Method method, String desc) throws Exception { + @ParameterizedTest + @MethodSource("callerSensitiveMethods") + public void testLookupNoOriginalAccessUnreflect(Method method, String desc) throws Exception { Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.ORIGINAL); assertTrue(lookup.hasFullPrivilegeAccess()); - lookup.unreflect(method); + assertThrows(IllegalAccessException.class, () -> lookup.unreflect(method)); } // -- Test method handles to setAccessible -- @@ -156,21 +158,12 @@ public class CallerSensitiveAccess { private int aField; Field accessibleField() { - try { - return getClass().getDeclaredField("aField"); - } catch (NoSuchFieldException e) { - fail(); - return null; - } + var clazz = getClass(); + return assertDoesNotThrow(() -> clazz.getDeclaredField("aField")); } Field inaccessibleField() { - try { - return String.class.getDeclaredField("hash"); - } catch (NoSuchFieldException e) { - fail(); - return null; - } + return assertDoesNotThrow(() -> String.class.getDeclaredField("hash")); } void findAndInvokeSetAccessible(Class refc, Field f) throws Throwable { @@ -215,23 +208,23 @@ public class CallerSensitiveAccess { * Create a method handle to setAccessible and attempt to use it to suppress * access to an inaccessible member. */ - @Test(expectedExceptions = InaccessibleObjectException.class) + @Test public void testSetAccessible5() throws Throwable { - findAndInvokeSetAccessible(AccessibleObject.class, inaccessibleField()); + assertThrows(InaccessibleObjectException.class, () -> findAndInvokeSetAccessible(AccessibleObject.class, inaccessibleField())); } - @Test(expectedExceptions = InaccessibleObjectException.class) + @Test public void testSetAccessible6() throws Throwable { - findAndInvokeSetAccessible(Field.class, inaccessibleField()); + assertThrows(InaccessibleObjectException.class, () -> findAndInvokeSetAccessible(Field.class, inaccessibleField())); } - @Test(expectedExceptions = InaccessibleObjectException.class) + @Test public void testSetAccessible7() throws Throwable { Method m = AccessibleObject.class.getMethod("setAccessible", boolean.class); - unreflectAndInvokeSetAccessible(m, inaccessibleField()); + assertThrows(InaccessibleObjectException.class, () -> unreflectAndInvokeSetAccessible(m, inaccessibleField())); } - @Test(expectedExceptions = InaccessibleObjectException.class) + @Test public void testSetAccessible8() throws Throwable { Method m = Field.class.getMethod("setAccessible", boolean.class); - unreflectAndInvokeSetAccessible(m, inaccessibleField()); + assertThrows(InaccessibleObjectException.class, () -> unreflectAndInvokeSetAccessible(m, inaccessibleField())); } @@ -241,7 +234,6 @@ public class CallerSensitiveAccess { * Custom AccessibleObject objects. One class overrides setAccessible, the other * does not override this method. */ - @DataProvider(name = "customAccessibleObjects") static Object[][] customAccessibleObjectClasses() { return new Object[][] { { new S1() }, { new S2() } }; } @@ -271,20 +263,20 @@ public class CallerSensitiveAccess { * Using publicLookup, create a method handle to setAccessible and invoke it * on a custom AccessibleObject object. */ - @Test(expectedExceptions = IllegalAccessException.class) + @Test public void testPublicLookupSubclass1() throws Throwable { // S1 does not override setAccessible - findAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1()); + assertThrows(IllegalAccessException.class, () -> findAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1())); } @Test public void testPublicLookupSubclass2() throws Throwable { // S2 overrides setAccessible findAndInvokeSetAccessible(MethodHandles.publicLookup(), new S2()); } - @Test(expectedExceptions = IllegalAccessException.class) + @Test public void testPublicLookupSubclass3() throws Throwable { // S1 does not override setAccessible - unreflectAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1()); + assertThrows(IllegalAccessException.class, () -> unreflectAndInvokeSetAccessible(MethodHandles.publicLookup(), new S1())); } @Test public void testPublicLookupSubclass4() throws Throwable { @@ -296,11 +288,13 @@ public class CallerSensitiveAccess { * Using a full power lookup, create a method handle to setAccessible and * invoke it on a custom AccessibleObject object. */ - @Test(dataProvider = "customAccessibleObjects") + @ParameterizedTest + @MethodSource("customAccessibleObjectClasses") public void testLookupSubclass1(AccessibleObject obj) throws Throwable { findAndInvokeSetAccessible(MethodHandles.lookup(), obj); } - @Test(dataProvider = "customAccessibleObjects") + @ParameterizedTest + @MethodSource("customAccessibleObjectClasses") public void testLookupSubclass2(AccessibleObject obj) throws Throwable { unreflectAndInvokeSetAccessible(MethodHandles.lookup(), obj); } @@ -309,13 +303,13 @@ public class CallerSensitiveAccess { * Using a full power lookup, create a method handle to setAccessible on a * sub-class of AccessibleObject and then attempt to invoke it on a Field object. */ - @Test(dataProvider = "customAccessibleObjects", - expectedExceptions = ClassCastException.class) + @ParameterizedTest + @MethodSource("customAccessibleObjectClasses") public void testLookupSubclass3(AccessibleObject obj) throws Throwable { MethodType mt = MethodType.methodType(void.class, boolean.class); Lookup lookup = MethodHandles.lookup(); MethodHandle mh = lookup.findVirtual(obj.getClass(), "setAccessible", mt); - mh.invoke(accessibleField(), true); // should throw ClassCastException + assertThrows(ClassCastException.class, () -> mh.invoke(accessibleField(), true)); } /** @@ -333,29 +327,29 @@ public class CallerSensitiveAccess { mh.invoke(f, true); assertTrue(f.isAccessible()); } - @Test(expectedExceptions = InaccessibleObjectException.class) + @Test public void testLookupSubclass5() throws Throwable { // S1 does not override setAccessible Method m = S1.class.getMethod("setAccessible", boolean.class); assertTrue(m.getDeclaringClass() == AccessibleObject.class); MethodHandle mh = MethodHandles.lookup().unreflect(m); - mh.invoke(inaccessibleField(), true); // should throw InaccessibleObjectException + assertThrows(InaccessibleObjectException.class, () -> mh.invoke(inaccessibleField(), true)); } - @Test(expectedExceptions = ClassCastException.class) + @Test public void testLookupSubclass6() throws Throwable { // S2 overrides setAccessible Method m = S2.class.getMethod("setAccessible", boolean.class); assertTrue(m.getDeclaringClass() == S2.class); MethodHandle mh = MethodHandles.lookup().unreflect(m); - mh.invoke(accessibleField(), true); // should throw ClassCastException + assertThrows(ClassCastException.class, () -> mh.invoke(accessibleField(), true)); } - @Test(expectedExceptions = ClassCastException.class) + @Test public void testLookupSubclass7() throws Throwable { // S2 overrides setAccessible Method m = S2.class.getMethod("setAccessible", boolean.class); assertTrue(m.getDeclaringClass() == S2.class); MethodHandle mh = MethodHandles.lookup().unreflect(m); - mh.invoke(inaccessibleField(), true); // should throw ClassCastException + assertThrows(ClassCastException.class, () -> mh.invoke(inaccessibleField(), true)); } /** @@ -373,7 +367,7 @@ public class CallerSensitiveAccess { // Field::getInt mh = MethodHandles.lookup().findVirtual(Field.class, "getInt", MethodType.methodType(int.class, Object.class)); int value = (int)mh.invokeExact(f, (Object)null); - assertTrue(value == 5); + assertEquals(5, value); } private static class Inner { @@ -400,7 +394,7 @@ public class CallerSensitiveAccess { * exported by a named module. */ static Stream callerSensitiveMethods(Module module) { - assert module.isNamed(); + assertTrue(module.isNamed()); ModuleReference mref = module.getLayer().configuration() .findModule(module.getName()) .orElseThrow(() -> new RuntimeException()) diff --git a/test/jdk/java/lang/invoke/condy/BootstrapMethodJumboArgsTest.java b/test/jdk/java/lang/invoke/condy/BootstrapMethodJumboArgsTest.java index 0357afce668..4a2ad3f3091 100644 --- a/test/jdk/java/lang/invoke/condy/BootstrapMethodJumboArgsTest.java +++ b/test/jdk/java/lang/invoke/condy/BootstrapMethodJumboArgsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,12 +27,10 @@ * @summary Test bootstrap methods throwing an exception * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng BootstrapMethodJumboArgsTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 BootstrapMethodJumboArgsTest + * @run junit BootstrapMethodJumboArgsTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 BootstrapMethodJumboArgsTest */ -import org.testng.Assert; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.invoke.ConstantCallSite; @@ -43,6 +41,10 @@ import java.util.stream.IntStream; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + public class BootstrapMethodJumboArgsTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); @@ -93,7 +95,7 @@ public class BootstrapMethodJumboArgsTest { Object.class, Object[].class), expected); Object[] actual = (Object[]) mh.invoke(); - Assert.assertEquals(actual, expected); + assertArrayEquals(expected, actual); } { @@ -103,7 +105,7 @@ public class BootstrapMethodJumboArgsTest { Object.class, Object.class, Object[].class), expected); Object[] actual = (Object[]) mh.invoke(); - Assert.assertEquals(actual, expected); + assertArrayEquals(expected, actual); } { @@ -113,7 +115,7 @@ public class BootstrapMethodJumboArgsTest { Object.class, Object.class, Object.class, Object[].class), expected); Object[] actual = (Object[]) mh.invoke(); - Assert.assertEquals(actual, expected); + assertArrayEquals(expected, actual); } } @@ -128,7 +130,7 @@ public class BootstrapMethodJumboArgsTest { Object.class, Object[].class), expected); Object[] actual = (Object[]) mh.invoke(); - Assert.assertEquals(actual, expected); + assertArrayEquals(expected, actual); } { @@ -138,7 +140,7 @@ public class BootstrapMethodJumboArgsTest { Object.class, Object.class, Object[].class), expected); Object[] actual = (Object[]) mh.invoke(); - Assert.assertEquals(actual, expected); + assertArrayEquals(expected, actual); } { @@ -148,7 +150,7 @@ public class BootstrapMethodJumboArgsTest { Object.class, Object.class, Object.class, Object[].class), expected); Object[] actual = (Object[]) mh.invoke(); - Assert.assertEquals(actual, expected); + assertArrayEquals(expected, actual); } } } diff --git a/test/jdk/java/lang/invoke/condy/CondyBSMException.java b/test/jdk/java/lang/invoke/condy/CondyBSMException.java index 7aa25c5cd95..1c9f867bc8b 100644 --- a/test/jdk/java/lang/invoke/condy/CondyBSMException.java +++ b/test/jdk/java/lang/invoke/condy/CondyBSMException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,12 +27,10 @@ * @summary Test bootstrap methods throwing an exception * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyBSMException - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMException + * @run junit CondyBSMException + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMException */ -import org.testng.Assert; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.invoke.MethodHandle; @@ -41,6 +39,10 @@ import java.lang.reflect.Constructor; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class CondyBSMException { @Test @@ -70,26 +72,17 @@ public class CondyBSMException { static void test(String message, Class... ts) { MethodHandle mh = thrower(message, ts[ts.length - 1]); - Throwable caught = null; - try { - mh.invoke(); - } catch (Throwable t) { - caught = t; - } - - if (caught == null) { - Assert.fail("Throwable expected"); - } + Throwable caught = assertThrows(Throwable.class, mh::invoke); String actualMessage = null; for (int i = 0; i < ts.length; i++) { + int level = i; + assertInstanceOf(ts[i], caught, () -> "Level %d".formatted(level)); actualMessage = caught.getMessage(); - Assert.assertNotNull(caught); - Assert.assertTrue(ts[i].isAssignableFrom(caught.getClass())); caught = caught.getCause(); } - Assert.assertEquals(actualMessage, message); + assertEquals(message, actualMessage); } static Throwable throwingBsm(MethodHandles.Lookup l, String name, Class type) throws Throwable { diff --git a/test/jdk/java/lang/invoke/condy/CondyBSMInvocation.java b/test/jdk/java/lang/invoke/condy/CondyBSMInvocation.java index e9050126a79..897ee40b444 100644 --- a/test/jdk/java/lang/invoke/condy/CondyBSMInvocation.java +++ b/test/jdk/java/lang/invoke/condy/CondyBSMInvocation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,13 +27,10 @@ * @summary Test basic invocation of bootstrap methods * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyBSMInvocation - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMInvocation + * @run junit CondyBSMInvocation + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMInvocation */ - -import org.testng.Assert; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.constant.ConstantDesc; @@ -48,6 +45,10 @@ import java.util.stream.Stream; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class CondyBSMInvocation { static final MethodHandles.Lookup L = MethodHandles.lookup(); @@ -59,11 +60,7 @@ public class CondyBSMInvocation { "bsm", methodType(Object.class) ); - try { - mh.invoke(); - Assert.fail("NoSuchMethodError expected to be thrown"); - } catch (NoSuchMethodError e) { - } + assertThrows(NoSuchMethodError.class, mh::invoke); } static MethodHandle[] bsms(String bsmName) { @@ -114,11 +111,7 @@ public class CondyBSMInvocation { "shape_bsm", bsm.type() ); - try { - Object r = mh.invoke(); - Assert.fail("BootstrapMethodError expected to be thrown for " + bsm); - } catch (BootstrapMethodError e) { - } + assertThrows(BootstrapMethodError.class, mh::invoke); } } @@ -139,11 +132,7 @@ public class CondyBSMInvocation { "sig_bsm", bsm.type() ); - try { - Object r = mh.invoke(); - Assert.fail("BootstrapMethodError expected to be thrown for " + bsm); - } catch (BootstrapMethodError e) { - } + assertThrows(BootstrapMethodError.class, mh::invoke); } } @@ -202,7 +191,7 @@ public class CondyBSMInvocation { static void assertAll(Object... as) { for (int i = 0; i < as.length; i++) { - Assert.assertEquals(as[i], i); + assertEquals(i, as[i]); } } @@ -219,7 +208,7 @@ public class CondyBSMInvocation { ); Object r = mh.invoke(); - Assert.assertEquals(r, Integer.toString(n)); + assertEquals(Integer.toString(n), r); } { @@ -231,7 +220,7 @@ public class CondyBSMInvocation { ); Object r = mh.invoke(); - Assert.assertEquals(r, Integer.toString(9)); + assertEquals(Integer.toString(9), r); } } @@ -248,13 +237,8 @@ public class CondyBSMInvocation { IntStream.range(0, n - 1).boxed().toArray(ConstantDesc[]::new) ); - try { - Object r = mh.invoke(); - Assert.fail("BootstrapMethodError expected to be thrown for arrity " + n); - } catch (BootstrapMethodError e) { - Throwable t = e.getCause(); - Assert.assertTrue(WrongMethodTypeException.class.isAssignableFrom(t.getClass())); - } + var e = assertThrows(BootstrapMethodError.class, mh::invoke); + assertInstanceOf(WrongMethodTypeException.class, e.getCause()); } } } diff --git a/test/jdk/java/lang/invoke/condy/CondyBSMValidationTest.java b/test/jdk/java/lang/invoke/condy/CondyBSMValidationTest.java index d255202866f..e6c2aacea63 100644 --- a/test/jdk/java/lang/invoke/condy/CondyBSMValidationTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyBSMValidationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,28 +27,29 @@ * @summary Test invalid name in name and type * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyBSMValidationTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMValidationTest + * @run junit CondyBSMValidationTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyBSMValidationTest */ -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; -import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.util.stream.Stream; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class CondyBSMValidationTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); static final String BSM_TYPE = methodType(Object.class, MethodHandles.Lookup.class, String.class, Object.class) .toMethodDescriptorString(); - @DataProvider - public Object[][] invalidSignaturesProvider() throws Exception { + public static Object[][] invalidSignaturesProvider() throws Exception { return Stream.of(BSM_TYPE.replace("(", ""), BSM_TYPE.replace(")", ""), BSM_TYPE.replace("(", "").replace(")", ""), @@ -57,15 +58,13 @@ public class CondyBSMValidationTest { .map(e -> new Object[]{e}).toArray(Object[][]::new); } - @Test(dataProvider = "invalidSignaturesProvider") + @ParameterizedTest + @MethodSource("invalidSignaturesProvider") public void testInvalidBSMSignature(String sig) throws Exception { - try { - MethodHandle mh = InstructionHelper.ldcDynamicConstant( - L, "name", "Ljava/lang/Object;", - "bsm", sig - ); - } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage().contains("Bad method descriptor")); - } + var e = assertThrows(IllegalArgumentException.class, () -> InstructionHelper.ldcDynamicConstant( + L, "name", "Ljava/lang/Object;", + "bsm", sig + )); + assertTrue(e.getMessage().contains("Bad method descriptor")); } } diff --git a/test/jdk/java/lang/invoke/condy/CondyInterfaceWithOverpassMethods.java b/test/jdk/java/lang/invoke/condy/CondyInterfaceWithOverpassMethods.java index 9fd35ed21f0..fe477d87657 100644 --- a/test/jdk/java/lang/invoke/condy/CondyInterfaceWithOverpassMethods.java +++ b/test/jdk/java/lang/invoke/condy/CondyInterfaceWithOverpassMethods.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -27,20 +27,20 @@ * @summary Test for an interface using condy with default overpass methods * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyInterfaceWithOverpassMethods - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyInterfaceWithOverpassMethods + * @run junit CondyInterfaceWithOverpassMethods + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyInterfaceWithOverpassMethods */ import java.lang.classfile.ClassFile; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.constant.*; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -@Test +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + public class CondyInterfaceWithOverpassMethods { interface A { int a(); @@ -52,14 +52,14 @@ public class CondyInterfaceWithOverpassMethods { // Generated class with methods containing condy ldc - Class gc; + static Class gc; public static Object bsm(MethodHandles.Lookup l, String name, Class type) { return name; } - @BeforeClass - public void generateClass() throws Exception { + @BeforeAll + public static void generateClass() throws Exception { // interface B extends A { // // Overpass for method A.a // diff --git a/test/jdk/java/lang/invoke/condy/CondyNameValidationTest.java b/test/jdk/java/lang/invoke/condy/CondyNameValidationTest.java index 6178b85236b..b380c28dc94 100644 --- a/test/jdk/java/lang/invoke/condy/CondyNameValidationTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyNameValidationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,13 +27,10 @@ * @summary Test invalid name in name and type * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyNameValidationTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNameValidationTest + * @run junit CondyNameValidationTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNameValidationTest */ -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.invoke.MethodHandle; @@ -43,12 +40,17 @@ import java.util.stream.Stream; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class CondyNameValidationTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); static final MethodType BSM_TYPE = methodType(Object.class, MethodHandles.Lookup.class, String.class, Object.class); - @DataProvider - public Object[][] invalidNamesProvider() { + public static Object[][] invalidNamesProvider() { return Stream.of( new Object[]{"", "zero-length member name"}, new Object[]{".", "Invalid member name"}, @@ -59,26 +61,24 @@ public class CondyNameValidationTest { .toArray(Object[][]::new); } - @Test(dataProvider = "invalidNamesProvider") + @ParameterizedTest + @MethodSource("invalidNamesProvider") public void testInvalidNames(String name, String errMessContent) throws Exception { - try { - MethodHandle mh = InstructionHelper.ldcDynamicConstant( - L, name, Object.class, - "bsm", BSM_TYPE - ); - } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage().contains(errMessContent)); - } + var e = assertThrows(IllegalArgumentException.class, () -> InstructionHelper.ldcDynamicConstant( + L, name, Object.class, + "bsm", BSM_TYPE + )); + assertTrue(e.getMessage().contains(errMessContent)); } - @DataProvider - public Object[][] validNamesProvider() throws Exception { + public static Object[][] validNamesProvider() throws Exception { return Stream.of("", "") .map(e -> new Object[]{e}).toArray(Object[][]::new); } - @Test(dataProvider = "validNamesProvider") + @ParameterizedTest + @MethodSource("validNamesProvider") public void testValidNames(String name) throws Exception { MethodHandle mh = InstructionHelper.ldcDynamicConstant( L, name, Object.class, diff --git a/test/jdk/java/lang/invoke/condy/CondyNestedTest.java b/test/jdk/java/lang/invoke/condy/CondyNestedTest.java index 8eb71ec93a3..192bbeaa46f 100644 --- a/test/jdk/java/lang/invoke/condy/CondyNestedTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyNestedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -26,24 +26,25 @@ * @bug 8186046 * @summary Test nested dynamic constant declarations that are recursive * @compile CondyNestedTest_Code.jcod - * @run testng CondyNestedTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNestedTest + * @run junit CondyNestedTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyNestedTest */ -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class CondyNestedTest { static final Class[] THROWABLES = {InvocationTargetException.class, StackOverflowError.class}; private static final MethodHandles.Lookup L = MethodHandles.lookup(); - Class c; + static Class c; // static final MethodHandles.Lookup L = MethodHandles.lookup(); // @@ -243,28 +244,17 @@ public class CondyNestedTest { // } static void test(Method m, Class... ts) { - Throwable caught = null; - try { - m.invoke(null); - } catch (Throwable t) { - caught = t; - } + Throwable caught = assertThrows(Throwable.class, () -> m.invoke(null)); - if (caught == null) { - Assert.fail("Throwable expected"); - } - - String actualMessage = null; for (int i = 0; i < ts.length; i++) { - actualMessage = caught.getMessage(); - Assert.assertNotNull(caught); - Assert.assertTrue(ts[i].isAssignableFrom(caught.getClass())); + int level = i; + assertInstanceOf(ts[i], caught, () -> "Level %d".formatted(level)); caught = caught.getCause(); } } - @BeforeClass - public void findClass() throws Exception { + @BeforeAll + public static void findClass() throws Exception { c = Class.forName("CondyNestedTest_Code"); } diff --git a/test/jdk/java/lang/invoke/condy/CondyRepeatFailedResolution.java b/test/jdk/java/lang/invoke/condy/CondyRepeatFailedResolution.java index 7ef5c610150..b7ccb4944fb 100644 --- a/test/jdk/java/lang/invoke/condy/CondyRepeatFailedResolution.java +++ b/test/jdk/java/lang/invoke/condy/CondyRepeatFailedResolution.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -26,28 +26,28 @@ * @bug 8186211 * @summary Test basic invocation of multiple ldc's of the same dynamic constant that fail resolution * @library /java/lang/invoke/common - * @run testng CondyRepeatFailedResolution - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyRepeatFailedResolution + * @run junit CondyRepeatFailedResolution + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyRepeatFailedResolution */ import java.lang.classfile.ClassFile; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - import java.lang.constant.*; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -@Test +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + public class CondyRepeatFailedResolution { // Counter used to determine if a given BSM is invoked more than once static int bsm_called = 0; // Generated class with methods containing condy ldc - Class gc; + static Class gc; // Bootstrap method used to represent primitive values // that cannot be represented directly in the constant pool, @@ -90,8 +90,8 @@ public class CondyRepeatFailedResolution { } } - @BeforeClass - public void generateClass() throws Exception { + @BeforeAll + public static void generateClass() throws Exception { String genClassName = CondyRepeatFailedResolution.class.getSimpleName() + "$Code"; String bsmClassDesc = CondyRepeatFailedResolution.class.descriptorString(); String bsmMethodName = "intConversion"; @@ -319,29 +319,21 @@ public class CondyRepeatFailedResolution { Method m = gc.getDeclaredMethod(name); bsm_called = 0; - try { + InvocationTargetException e1 = assertThrows(InvocationTargetException.class, () -> { Object r1 = m.invoke(null); - Assert.fail("InvocationTargetException expected to be thrown after first invocation"); - } catch (InvocationTargetException e1) { - // bsm_called should have been incremented prior to the exception - Assert.assertEquals(bsm_called, 1); - Assert.assertTrue(e1.getCause() instanceof BootstrapMethodError); - // Try invoking method again to ensure that the bootstrap - // method is not invoked twice and a resolution failure - // results. - try { - Object r2 = m.invoke(null); - Assert.fail("InvocationTargetException expected to be thrown after second invocation"); - } catch (InvocationTargetException e2) { - // bsm_called should remain at 1 since the bootstrap - // method should not have been invoked. - Assert.assertEquals(bsm_called, 1); - Assert.assertTrue(e2.getCause() instanceof BootstrapMethodError); - } catch (Throwable t2) { - Assert.fail("InvocationTargetException expected to be thrown"); - } - } catch (Throwable t1) { - Assert.fail("InvocationTargetException expected to be thrown"); - } + }); + // bsm_called should have been incremented prior to the exception + assertEquals(1, bsm_called); + assertInstanceOf(BootstrapMethodError.class, e1.getCause()); + // Try invoking method again to ensure that the bootstrap + // method is not invoked twice and a resolution failure + // results. + InvocationTargetException e2 = assertThrows(InvocationTargetException.class, () -> { + Object r2 = m.invoke(null); + }); + // bsm_called should remain at 1 since the bootstrap + // method should not have been invoked. + assertEquals(1, bsm_called); + assertInstanceOf(BootstrapMethodError.class, e2.getCause()); } } diff --git a/test/jdk/java/lang/invoke/condy/CondyReturnPrimitiveTest.java b/test/jdk/java/lang/invoke/condy/CondyReturnPrimitiveTest.java index d6c0748c97c..4c0dd42a1a2 100644 --- a/test/jdk/java/lang/invoke/condy/CondyReturnPrimitiveTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyReturnPrimitiveTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -25,22 +25,23 @@ * @test * @bug 8186046 * @summary Test for condy BSMs returning primitive values or null - * @run testng CondyReturnPrimitiveTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyReturnPrimitiveTest + * @run junit CondyReturnPrimitiveTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyReturnPrimitiveTest */ import java.lang.classfile.ClassFile; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - import java.lang.constant.*; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; -@Test +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class CondyReturnPrimitiveTest { // Counter for number of BSM calls // Use of an AtomicInteger is not strictly necessary in this test @@ -49,7 +50,7 @@ public class CondyReturnPrimitiveTest { // constant so care should be taken if a BSM operates on shared state static final AtomicInteger callCount = new AtomicInteger(); // Generated class with methods containing condy ldc - Class gc; + static Class gc; // Bootstrap method used to represent primitive values // that cannot be represented directly in the constant pool, @@ -90,8 +91,8 @@ public class CondyReturnPrimitiveTest { } } - @BeforeClass - public void generateClass() throws Exception { + @BeforeAll + public static void generateClass() throws Exception { String genClassName = CondyReturnPrimitiveTest.class.getSimpleName() + "$Code"; String bsmClassDesc = CondyReturnPrimitiveTest.class.descriptorString(); String bsmMethodName = "intConversion"; @@ -293,7 +294,7 @@ public class CondyReturnPrimitiveTest { // Ensure when run a second time that the bootstrap method is not // invoked and the constants are cached testConstants(); - Assert.assertEquals(callCount.get(), expectedCallCount); + assertEquals(expectedCallCount, callCount.get()); } @Test @@ -318,11 +319,16 @@ public class CondyReturnPrimitiveTest { testConstant("S", Short.MAX_VALUE); testConstant("Z_F", false); testConstant("Z_T", true); - testConstant("null", null); + testConstant("null", (Object) null); } void testConstant(String name, Object expected) throws Exception { Method m = gc.getDeclaredMethod(name); - Assert.assertEquals(m.invoke(null), expected); + assertEquals(expected, m.invoke(null)); + } + + void testConstant(String name, Object[] expected) throws Exception { + Method m = gc.getDeclaredMethod(name); + assertArrayEquals(expected, (Object[]) m.invoke(null)); } } diff --git a/test/jdk/java/lang/invoke/condy/CondyStaticArgumentsTest.java b/test/jdk/java/lang/invoke/condy/CondyStaticArgumentsTest.java index ba3d0e81488..075eaf4e844 100644 --- a/test/jdk/java/lang/invoke/condy/CondyStaticArgumentsTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyStaticArgumentsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,12 +27,10 @@ * @summary Test bootstrap arguments for condy * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyStaticArgumentsTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyStaticArgumentsTest + * @run junit CondyStaticArgumentsTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyStaticArgumentsTest */ -import org.testng.Assert; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.constant.*; @@ -44,6 +42,9 @@ import java.util.StringJoiner; import java.util.stream.Stream; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class CondyStaticArgumentsTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); @@ -109,7 +110,7 @@ public class CondyStaticArgumentsTest { mhi.getName(), MethodTypeDesc.ofDescriptor(mhi.getMethodType().descriptorString())) ); - Assert.assertEquals(mh.invoke(), "constant-name-String-1-2-3.0-4.0-Number-something-(int,long,float,double)void-11"); + assertEquals("constant-name-String-1-2-3.0-4.0-Number-something-(int,long,float,double)void-11", mh.invoke()); } static MathContext mathContext(MethodHandles.Lookup l, String value, Class type) { @@ -161,7 +162,7 @@ public class CondyStaticArgumentsTest { ) ) ); - Assert.assertEquals(mh.invoke(), "big-decimal-math-context-String-3.141593-7"); + assertEquals("big-decimal-math-context-String-3.141593-7", mh.invoke()); } @@ -194,7 +195,7 @@ public class CondyStaticArgumentsTest { InstructionHelper.classDesc(MathContext.class) ) )); - Assert.assertEquals(mh.invoke(), "big-decimal-math-context-()Ljava/lang/String;-3.141593-7"); + assertEquals("big-decimal-math-context-()Ljava/lang/String;-3.141593-7", mh.invoke()); } private static DirectMethodHandleDesc directMhDesc(String methodName) { diff --git a/test/jdk/java/lang/invoke/condy/CondyTypeValidationTest.java b/test/jdk/java/lang/invoke/condy/CondyTypeValidationTest.java index c44179ce13c..4429468bd34 100644 --- a/test/jdk/java/lang/invoke/condy/CondyTypeValidationTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyTypeValidationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,12 +27,9 @@ * @summary Test invalid name in name and type * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyTypeValidationTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyTypeValidationTest */ -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.invoke.MethodHandle; @@ -43,14 +40,18 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class CondyTypeValidationTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); static final String BSM_TYPE = methodType(Object.class, MethodHandles.Lookup.class, String.class, Object.class) .toMethodDescriptorString(); - @DataProvider - public Object[][] invalidTypesProvider() { + public static Object[][] invalidTypesProvider() { return Stream.of( // ByteCode API checks for the following invalid types // "", @@ -66,20 +67,19 @@ public class CondyTypeValidationTest { ).toArray(Object[][]::new); } - @Test(dataProvider = "invalidTypesProvider") + @ParameterizedTest + @MethodSource("invalidTypesProvider") public void testInvalidTypes(String type, String errMessContent) throws Exception { - try { + var e = assertThrows(IllegalArgumentException.class, () -> { MethodHandle mh = InstructionHelper.ldcDynamicConstant( L, "name", type, "bsm", BSM_TYPE ); - } catch (IllegalArgumentException e) { - Assert.assertTrue(e.getMessage().contains(errMessContent)); - } + }); + assertTrue(e.getMessage().contains(errMessContent)); } - @DataProvider - public Object[][] validTypesProvider() { + public static Object[][] validTypesProvider() { List t = new ArrayList<>(List.of("B", "C", "D", "F", "I", "J", "Ljava/lang/Object;", "S", "Z")); int l = t.size(); for (int i = 0; i < l; i++) { @@ -90,7 +90,8 @@ public class CondyTypeValidationTest { .map(e -> new Object[]{e}).toArray(Object[][]::new); } - @Test(dataProvider = "validTypesProvider") + @ParameterizedTest + @MethodSource("validTypesProvider") public void testValidTypes(String type) throws Exception { MethodHandle mh = InstructionHelper.ldcDynamicConstant( L, "name", type, diff --git a/test/jdk/java/lang/invoke/condy/CondyWithGarbageTest.java b/test/jdk/java/lang/invoke/condy/CondyWithGarbageTest.java index 5e301a193dd..a00f93b69b7 100644 --- a/test/jdk/java/lang/invoke/condy/CondyWithGarbageTest.java +++ b/test/jdk/java/lang/invoke/condy/CondyWithGarbageTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,21 +27,20 @@ * @summary Stress test ldc to ensure HotSpot correctly manages oop maps * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyWithGarbageTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyWithGarbageTest + * @run junit CondyWithGarbageTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyWithGarbageTest */ - import java.lang.classfile.ClassFile; import java.lang.classfile.CodeBuilder; -import org.testng.Assert; -import org.testng.annotations.Test; - import java.lang.constant.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; import static test.java.lang.invoke.lib.InstructionHelper.classDesc; public class CondyWithGarbageTest { @@ -54,7 +53,7 @@ public class CondyWithGarbageTest { for (int i = 0; i < 100000; i++) { l += +((String) mh.invoke()).length(); } - Assert.assertTrue(l > 0); + assertTrue(l > 0); } public static Object bsmString(MethodHandles.Lookup l, @@ -133,7 +132,7 @@ public class CondyWithGarbageTest { for (int i = 0; i < 100000; i++) { l += +((String) mh.invoke()).length(); } - Assert.assertTrue(l > 0); + assertTrue(l > 0); } public static Object bsmStringArray(MethodHandles.Lookup l, diff --git a/test/jdk/java/lang/invoke/condy/CondyWrongType.java b/test/jdk/java/lang/invoke/condy/CondyWrongType.java index 42c69e8ab7d..1c00da922fe 100644 --- a/test/jdk/java/lang/invoke/condy/CondyWrongType.java +++ b/test/jdk/java/lang/invoke/condy/CondyWrongType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -27,13 +27,10 @@ * @summary Test bootstrap methods returning the wrong type * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng CondyWrongType - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyWrongType + * @run junit CondyWrongType + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 CondyWrongType */ -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import test.java.lang.invoke.lib.InstructionHelper; import java.lang.invoke.MethodHandle; @@ -46,11 +43,15 @@ import java.util.List; import java.util.Map; import static java.lang.invoke.MethodType.methodType; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.*; public class CondyWrongType { - @DataProvider - public Object[][] primitivesProvider() throws Exception { + public static Object[][] primitivesProvider() throws Exception { Map> typeMap = Map.of( "B", byte.class, "C", char.class, @@ -81,7 +82,8 @@ public class CondyWrongType { return cases.stream().toArray(Object[][]::new); } - @Test(dataProvider = "primitivesProvider") + @ParameterizedTest + @MethodSource("primitivesProvider") public void testPrimitives(String name, String type, boolean pass) { test(name, type, pass); } @@ -106,27 +108,12 @@ public class CondyWrongType { static void test(String name, String type, boolean pass) { MethodHandle mh = caster(name, type); - Throwable caught = null; - try { - mh.invoke(); - } catch (Throwable t) { - caught = t; + if (pass) { + assertDoesNotThrow(() -> mh.invoke()); + } else { + Throwable caught = assertThrows(BootstrapMethodError.class, () -> mh.invoke()); + assertInstanceOf(ClassCastException.class, caught.getCause()); } - - if (caught == null) { - if (pass) { - return; - } else { - Assert.fail("Throwable expected"); - } - } else if (pass) { - Assert.fail("Throwable not expected"); - } - - Assert.assertTrue(BootstrapMethodError.class.isAssignableFrom(caught.getClass())); - caught = caught.getCause(); - Assert.assertNotNull(caught); - Assert.assertTrue(ClassCastException.class.isAssignableFrom(caught.getClass())); } static Object bsm(MethodHandles.Lookup l, String name, Class type) { diff --git a/test/jdk/java/lang/invoke/condy/ConstantBootstrapsTest.java b/test/jdk/java/lang/invoke/condy/ConstantBootstrapsTest.java index 829f26704f9..cef5a17eda1 100644 --- a/test/jdk/java/lang/invoke/condy/ConstantBootstrapsTest.java +++ b/test/jdk/java/lang/invoke/condy/ConstantBootstrapsTest.java @@ -27,27 +27,31 @@ * @summary Test dynamic constant bootstraps * @library /java/lang/invoke/common * @build test.java.lang.invoke.lib.InstructionHelper - * @run testng ConstantBootstrapsTest - * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 ConstantBootstrapsTest + * @run junit ConstantBootstrapsTest + * @run junit/othervm -XX:+UnlockDiagnosticVMOptions -XX:UseBootstrapCallInfo=3 ConstantBootstrapsTest */ -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import test.java.lang.invoke.lib.InstructionHelper; - import java.lang.constant.ConstantDescs; import java.lang.constant.DirectMethodHandleDesc; import java.lang.constant.MethodHandleDesc; -import java.lang.invoke.*; +import java.lang.invoke.ConstantBootstraps; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.invoke.VarHandle; +import java.lang.invoke.WrongMethodTypeException; import java.math.BigInteger; import java.util.Collection; import java.util.List; import java.util.Map; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import test.java.lang.invoke.lib.InstructionHelper; + +import static org.junit.jupiter.api.Assertions.*; -@Test public class ConstantBootstrapsTest { static final MethodHandles.Lookup L = MethodHandles.lookup(); @@ -56,6 +60,7 @@ public class ConstantBootstrapsTest { appendParameterTypes(params); } + @Test public void testNullConstant() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant(L, "_", Object.class, ConstantBootstraps.class, "nullConstant", lookupMT(Object.class)); @@ -66,12 +71,13 @@ public class ConstantBootstrapsTest { assertNull(handle.invoke()); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testNullConstantPrimitiveClass() { - ConstantBootstraps.nullConstant(MethodHandles.lookup(), null, int.class); + assertThrows(IllegalArgumentException.class, () -> ConstantBootstraps.nullConstant(MethodHandles.lookup(), null, int.class)); } + @Test public void testPrimitiveClass() throws Throwable { var pm = Map.of( "I", int.class, @@ -88,69 +94,73 @@ public class ConstantBootstrapsTest { for (var desc : pm.keySet()) { var handle = InstructionHelper.ldcDynamicConstant(L, desc, Class.class, ConstantBootstraps.class, "primitiveClass", lookupMT(Class.class)); - assertEquals(handle.invoke(), pm.get(desc)); + assertEquals(pm.get(desc), handle.invoke()); } } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testPrimitiveClassNullName() { - ConstantBootstraps.primitiveClass(MethodHandles.lookup(), null, Class.class); + assertThrows(NullPointerException.class, () -> ConstantBootstraps.primitiveClass(MethodHandles.lookup(), null, Class.class)); } - @Test(expectedExceptions = NullPointerException.class) + @Test public void testPrimitiveClassNullType() { - ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "I", null); + assertThrows(NullPointerException.class, () -> ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "I", null)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testPrimitiveClassEmptyName() { - ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "", Class.class); + assertThrows(IllegalArgumentException.class, () -> ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "", Class.class)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testPrimitiveClassWrongNameChar() { - ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "L", Class.class); + assertThrows(IllegalArgumentException.class, () -> ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "L", Class.class)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testPrimitiveClassWrongNameString() { - ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "Ljava/lang/Object;", Class.class); + assertThrows(IllegalArgumentException.class, () -> ConstantBootstraps.primitiveClass(MethodHandles.lookup(), "Ljava/lang/Object;", Class.class)); } + @Test public void testEnumConstant() throws Throwable { for (var v : StackWalker.Option.values()) { var handle = InstructionHelper.ldcDynamicConstant(L, v.name(), StackWalker.Option.class, ConstantBootstraps.class, "enumConstant", lookupMT(Enum.class)); - assertEquals(handle.invoke(), v); + assertEquals(v, handle.invoke()); } } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testEnumConstantUnknown() { - ConstantBootstraps.enumConstant(MethodHandles.lookup(), "DOES_NOT_EXIST", StackWalker.Option.class); + assertThrows(IllegalArgumentException.class, () -> ConstantBootstraps.enumConstant(MethodHandles.lookup(), "DOES_NOT_EXIST", StackWalker.Option.class)); } + @Test public void testGetStaticDecl() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant(L, "TYPE", Class.class, ConstantBootstraps.class, "getStaticFinal", lookupMT(Object.class, Class.class), InstructionHelper.classDesc(Integer.class)); - assertEquals(handle.invoke(), int.class); + assertEquals(int.class, handle.invoke()); } + @Test public void testGetStaticSelf() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant(L, "MAX_VALUE", int.class, ConstantBootstraps.class, "getStaticFinal", lookupMT(Object.class)); - assertEquals(handle.invoke(), Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE, handle.invoke()); handle = InstructionHelper.ldcDynamicConstant(L, "ZERO", BigInteger.class, ConstantBootstraps.class, "getStaticFinal", lookupMT(Object.class)); - assertEquals(handle.invoke(), BigInteger.ZERO); + assertEquals(BigInteger.ZERO, handle.invoke()); } + @Test public void testInvoke() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant( L, "_", List.class, @@ -159,9 +169,10 @@ public class ConstantBootstrapsTest { MethodType.methodType(List.class, Object[].class).toMethodDescriptorString()), 1, 2, 3, 4 ); - assertEquals(handle.invoke(), List.of(1, 2, 3, 4)); + assertEquals(List.of(1, 2, 3, 4), handle.invoke()); } + @Test public void testInvokeAsType() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant( L, "_", int.class, @@ -170,9 +181,10 @@ public class ConstantBootstrapsTest { MethodType.methodType(Integer.class, String.class).toMethodDescriptorString()), "42" ); - assertEquals(handle.invoke(), 42); + assertEquals(42, handle.invoke()); } + @Test public void testInvokeAsTypeVariableArity() throws Throwable { // The constant type is Collection but the invoke return type is List var handle = InstructionHelper.ldcDynamicConstant( @@ -182,21 +194,21 @@ public class ConstantBootstrapsTest { MethodType.methodType(List.class, Object[].class).toMethodDescriptorString()), 1, 2, 3, 4 ); - assertEquals(handle.invoke(), List.of(1, 2, 3, 4)); + assertEquals(List.of(1, 2, 3, 4), handle.invoke()); } - @Test(expectedExceptions = ClassCastException.class) + @Test public void testInvokeAsTypeClassCast() throws Throwable { - ConstantBootstraps.invoke(MethodHandles.lookup(), "_", String.class, + assertThrows(ClassCastException.class, () -> ConstantBootstraps.invoke(MethodHandles.lookup(), "_", String.class, MethodHandles.lookup().findStatic(Integer.class, "valueOf", MethodType.methodType(Integer.class, String.class)), - "42"); + "42")); } - @Test(expectedExceptions = WrongMethodTypeException.class) + @Test public void testInvokeAsTypeWrongReturnType() throws Throwable { - ConstantBootstraps.invoke(MethodHandles.lookup(), "_", short.class, + assertThrows(WrongMethodTypeException.class, () -> ConstantBootstraps.invoke(MethodHandles.lookup(), "_", short.class, MethodHandles.lookup().findStatic(Integer.class, "parseInt", MethodType.methodType(int.class, String.class)), - "42"); + "42")); } @@ -205,6 +217,7 @@ public class ConstantBootstrapsTest { public static String sf; } + @Test public void testVarHandleField() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant( L, "f", VarHandle.class, @@ -214,10 +227,11 @@ public class ConstantBootstrapsTest { ); var vhandle = (VarHandle) handle.invoke(); - assertEquals(vhandle.varType(), String.class); - assertEquals(vhandle.coordinateTypes(), List.of(X.class)); + assertEquals(String.class, vhandle.varType()); + assertEquals(List.of(X.class), vhandle.coordinateTypes()); } + @Test public void testVarHandleStaticField() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant( L, "sf", VarHandle.class, @@ -227,10 +241,11 @@ public class ConstantBootstrapsTest { ); var vhandle = (VarHandle) handle.invoke(); - assertEquals(vhandle.varType(), String.class); - assertEquals(vhandle.coordinateTypes(), List.of()); + assertEquals(String.class, vhandle.varType()); + assertEquals(List.of(), vhandle.coordinateTypes()); } + @Test public void testVarHandleArray() throws Throwable { var handle = InstructionHelper.ldcDynamicConstant( L, "_", VarHandle.class, @@ -239,11 +254,10 @@ public class ConstantBootstrapsTest { ); var vhandle = (VarHandle) handle.invoke(); - assertEquals(vhandle.varType(), String.class); - assertEquals(vhandle.coordinateTypes(), List.of(String[].class, int.class)); + assertEquals(String.class, vhandle.varType()); + assertEquals(List.of(String[].class, int.class), vhandle.coordinateTypes()); } - @DataProvider public static Object[][] cceCasts() { return new Object[][]{ { void.class, null }, @@ -252,12 +266,12 @@ public class ConstantBootstrapsTest { }; } - @Test(dataProvider = "cceCasts", expectedExceptions = ClassCastException.class) + @ParameterizedTest + @MethodSource("cceCasts") public void testBadCasts(Class dstType, Object value) { - ConstantBootstraps.explicitCast(null, null, dstType, value); + assertThrows(ClassCastException.class, () -> ConstantBootstraps.explicitCast(null, null, dstType, value)); } - @DataProvider public static Object[][] validCasts() { Object o = new Object(); return new Object[][]{ @@ -278,9 +292,10 @@ public class ConstantBootstrapsTest { }; } - @Test(dataProvider = "validCasts") + @ParameterizedTest + @MethodSource("validCasts") public void testSuccessfulCasts(Class dstType, Object value, Object expected) { Object actual = ConstantBootstraps.explicitCast(null, null, dstType, value); - assertEquals(actual, expected); + assertEquals(expected, actual); } } diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java b/test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java index 379ae765a6b..097e7c782a5 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -31,7 +31,7 @@ * BadClassFileVersion.jcod * @build jdk.test.lib.Utils * jdk.test.lib.compiler.CompilerUtils - * @run testng/othervm BasicTest + * @run junit/othervm BasicTest */ import java.io.File; @@ -52,16 +52,16 @@ import java.util.stream.Stream; import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.Utils; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import static java.lang.classfile.ClassFile.*; import static java.lang.constant.ConstantDescs.CD_Enum; import static java.lang.constant.ConstantDescs.CD_Object; import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.Lookup.ClassOption.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; interface HiddenTest { void test(); @@ -75,7 +75,7 @@ public class BasicTest { private static byte[] hiddenClassBytes; - @BeforeTest + @BeforeAll static void setup() throws IOException { compileSources(SRC_DIR, CLASSES_DIR); hiddenClassBytes = Files.readAllBytes(CLASSES_DIR.resolve("HiddenClass.class")); @@ -114,9 +114,9 @@ public class BasicTest { Class[] intfs = c.getInterfaces(); assertTrue(c.isHidden()); assertFalse(c.isPrimitive()); - assertTrue(intfs.length == 1); - assertTrue(intfs[0] == HiddenTest.class); - assertTrue(c.getCanonicalName() == null); + assertEquals(1, intfs.length); + assertSame(HiddenTest.class, intfs[0]); + assertNull(c.getCanonicalName()); String hcName = "HiddenClass"; String hcSuffix = "0x[0-9a-f]+"; @@ -143,7 +143,7 @@ public class BasicTest { Object array = Array.newInstance(type, 2); Class arrayType = array.getClass(); assertTrue(arrayType.isArray()); - assertTrue(Array.getLength(array) == 2); + assertEquals(2, Array.getLength(array)); assertFalse(arrayType.isHidden()); String hcName = "HiddenClass"; @@ -152,11 +152,11 @@ public class BasicTest { assertTrue(arrayType.descriptorString().matches("\\[" + "L" + hcName + "." + hcSuffix + ";")); assertTrue(arrayType.getComponentType().isHidden()); - assertTrue(arrayType.getComponentType() == type); + assertSame(type, arrayType.getComponentType()); Object t = type.newInstance(); Array.set(array, 0, t); Object o = Array.get(array, 0); - assertTrue(o == t); + assertSame(t, o); } private void checkSetAccessible(Class c, String name, Class... ptypes) throws Exception { @@ -170,13 +170,8 @@ public class BasicTest { @Test public void testLambda() throws Throwable { HiddenTest t = (HiddenTest)defineHiddenClass("Lambda").newInstance(); - try { - t.test(); - } catch (Error e) { - if (!e.getMessage().equals("thrown by " + t.getClass().getName())) { - throw e; - } - } + var e = assertThrows(Error.class, t::test); + assertEquals("thrown by " + t.getClass().getName(), e.getMessage()); } // Define a hidden class that uses lambda and contains its implementation @@ -184,13 +179,8 @@ public class BasicTest { @Test public void testHiddenLambda() throws Throwable { HiddenTest t = (HiddenTest)defineHiddenClass("HiddenLambda").newInstance(); - try { - t.test(); - } catch (Error e) { - if (!e.getMessage().equals("thrown by " + t.getClass().getName())) { - throw e; - } - } + var e = assertThrows(Error.class, t::test); + assertEquals("thrown by " + t.getClass().getName(), e.getMessage()); } // Verify the nest host and nest members of a hidden class and hidden nestmate class @@ -206,19 +196,18 @@ public class BasicTest { // test nest membership and reflection API assertTrue(host.isNestmateOf(member)); - assertTrue(host.getNestHost() == host); + assertSame(host, host.getNestHost()); // getNestHost and getNestMembers return the same value when calling // on a nest member and the nest host - assertTrue(member.getNestHost() == host.getNestHost()); - assertTrue(Arrays.equals(member.getNestMembers(), host.getNestMembers())); + assertSame(host.getNestHost(), member.getNestHost()); + assertArrayEquals(member.getNestMembers(), host.getNestMembers()); // getNestMembers includes the nest host that can be a hidden class but // only includes static nest members - assertTrue(host.getNestMembers().length == 1); - assertTrue(host.getNestMembers()[0] == host); + assertEquals(1, host.getNestMembers().length); + assertSame(host, host.getNestMembers()[0]); } - @DataProvider(name = "hiddenClasses") - private Object[][] hiddenClasses() { + private static Object[][] hiddenClasses() { return new Object[][] { new Object[] { "HiddenInterface", false }, new Object[] { "AbstractClass", false }, @@ -240,7 +229,8 @@ public class BasicTest { * is not useful as it cannot be referenced and an outer/inner class * when defined as a hidden effectively becomes a final top-level class. */ - @Test(dataProvider = "hiddenClasses") + @ParameterizedTest + @MethodSource("hiddenClasses") public void defineHiddenClass(String name, boolean nestmate) throws Exception { byte[] bytes = Files.readAllBytes(CLASSES_DIR.resolve(name + ".class")); Class hc; @@ -252,13 +242,12 @@ public class BasicTest { hc = lookup().defineHiddenClass(bytes, false).lookupClass(); host = hc; } - assertTrue(hc.getNestHost() == host); - assertTrue(hc.getNestMembers().length == 1); - assertTrue(hc.getNestMembers()[0] == host); + assertSame(host, hc.getNestHost()); + assertEquals(1, hc.getNestMembers().length); + assertSame(host, hc.getNestMembers()[0]); } - @DataProvider(name = "emptyClasses") - private Object[][] emptyClasses() { + private static Object[][] emptyClasses() { return new Object[][] { new Object[] { "EmptyHiddenSynthetic", ACC_SYNTHETIC }, new Object[] { "EmptyHiddenEnum", ACC_ENUM }, @@ -276,7 +265,8 @@ public class BasicTest { * enum class containing constants of its type should not be a hidden * class. */ - @Test(dataProvider = "emptyClasses") + @ParameterizedTest + @MethodSource("emptyClasses") public void emptyHiddenClass(String name, int accessFlags) throws Exception { byte[] bytes = (accessFlags == ACC_ENUM) ? classBytes(name, CD_Enum, accessFlags) : classBytes(name, accessFlags); @@ -316,7 +306,7 @@ public class BasicTest { throw new IllegalArgumentException("unexpected access flag: " + accessFlags); } assertTrue(hc.isHidden()); - assertTrue(hc.getModifiers() == (ACC_PUBLIC|accessFlags)); + assertEquals(hc.getModifiers(), ACC_PUBLIC | accessFlags); assertFalse(hc.isLocalClass()); assertFalse(hc.isMemberClass()); assertFalse(hc.isAnonymousClass()); @@ -324,8 +314,7 @@ public class BasicTest { } // These class files can't be defined as hidden classes - @DataProvider(name = "cantBeHiddenClasses") - private Object[][] cantBeHiddenClasses() { + private static Object[][] cantBeHiddenClasses() { return new Object[][] { // a hidden class can't be a field's declaring type // enum class with static final HiddenEnum[] $VALUES: @@ -342,10 +331,11 @@ public class BasicTest { /* * These class files */ - @Test(dataProvider = "cantBeHiddenClasses", expectedExceptions = NoClassDefFoundError.class) + @ParameterizedTest + @MethodSource("cantBeHiddenClasses") public void failToDeriveAsHiddenClass(String name) throws Exception { byte[] bytes = Files.readAllBytes(CLASSES_DIR.resolve(name + ".class")); - Class hc = lookup().defineHiddenClass(bytes, false).lookupClass(); + assertThrows(NoClassDefFoundError.class, () -> lookup().defineHiddenClass(bytes, false).lookupClass()); } /* @@ -361,22 +351,17 @@ public class BasicTest { Class c = t.getClass(); Class[] intfs = c.getInterfaces(); - assertTrue(intfs.length == 1); - assertTrue(intfs[0] == HiddenTest.class); + assertEquals(1, intfs.length); + assertSame(HiddenTest.class, intfs[0]); - try { - // this would cause loading of class HiddenCantReflect and NCDFE due - // to error during verification - c.getDeclaredMethods(); - } catch (NoClassDefFoundError e) { - Throwable x = e.getCause(); - if (x == null || !(x instanceof ClassNotFoundException && x.getMessage().contains("HiddenCantReflect"))) { - throw e; - } + var e = assertThrows(NoClassDefFoundError.class, c::getDeclaredMethods); + Throwable x = e.getCause(); + if (x == null || !(x instanceof ClassNotFoundException && x.getMessage().contains("HiddenCantReflect"))) { + throw e; } } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void cantDefineModule() throws Throwable { Path src = Paths.get("module-info.java"); Path dir = CLASSES_DIR.resolve("m"); @@ -384,35 +369,34 @@ public class BasicTest { compileSources(src, dir); byte[] bytes = Files.readAllBytes(dir.resolve("module-info.class")); - lookup().defineHiddenClass(bytes, false); + assertThrows(IllegalArgumentException.class, () -> lookup().defineHiddenClass(bytes, false)); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void cantDefineClassInAnotherPackage() throws Throwable { Path src = Paths.get("ClassInAnotherPackage.java"); Files.write(src, List.of("package p;", "public class ClassInAnotherPackage {}"), StandardCharsets.UTF_8); compileSources(src, CLASSES_DIR); byte[] bytes = Files.readAllBytes(CLASSES_DIR.resolve("p").resolve("ClassInAnotherPackage.class")); - lookup().defineHiddenClass(bytes, false); + assertThrows(IllegalArgumentException.class, () -> lookup().defineHiddenClass(bytes, false)); } - @Test(expectedExceptions = { IllegalAccessException.class }) + @Test public void lessPrivilegedLookup() throws Throwable { Lookup lookup = lookup().dropLookupMode(Lookup.PRIVATE); - lookup.defineHiddenClass(hiddenClassBytes, false); + assertThrows(IllegalAccessException.class, () -> lookup.defineHiddenClass(hiddenClassBytes, false)); } - @Test(expectedExceptions = { UnsupportedClassVersionError.class }) + @Test public void badClassFileVersion() throws Throwable { Path dir = Paths.get(System.getProperty("test.classes", ".")); byte[] bytes = Files.readAllBytes(dir.resolve("BadClassFileVersion.class")); - lookup().defineHiddenClass(bytes, false); + assertThrows(UnsupportedClassVersionError.class, () -> lookup().defineHiddenClass(bytes, false)); } // malformed class files - @DataProvider(name = "malformedClassFiles") - private Object[][] malformedClassFiles() throws IOException { + private static Object[][] malformedClassFiles() throws IOException { Path dir = Paths.get(System.getProperty("test.classes", ".")); return new Object[][] { // `this_class` has invalid CP entry @@ -424,13 +408,13 @@ public class BasicTest { }; } - @Test(dataProvider = "malformedClassFiles", expectedExceptions = ClassFormatError.class) + @ParameterizedTest + @MethodSource("malformedClassFiles") public void badClassFile(byte[] bytes) throws Throwable { - lookup().defineHiddenClass(bytes, false); + assertThrows(ClassFormatError.class, () -> lookup().defineHiddenClass(bytes, false)); } - @DataProvider(name = "nestedTypesOrAnonymousClass") - private Object[][] nestedTypesOrAnonymousClass() { + private static Object[][] nestedTypesOrAnonymousClass() { return new Object[][] { // class file with bad InnerClasses or EnclosingMethod attribute new Object[] { "Outer", null }, @@ -440,7 +424,8 @@ public class BasicTest { }; } - @Test(dataProvider = "nestedTypesOrAnonymousClass") + @ParameterizedTest + @MethodSource("nestedTypesOrAnonymousClass") public void hasInnerClassesOrEnclosingMethodAttribute(String className, String badDeclaringClassName) throws Throwable { byte[] bytes = Files.readAllBytes(CLASSES_10_DIR.resolve(className + ".class")); Class hc = lookup().defineHiddenClass(bytes, false).lookupClass(); @@ -460,21 +445,22 @@ public class BasicTest { byte[] bytes = Files.readAllBytes(CLASSES_DIR.resolve("Outer.class")); Class hc = lookup().defineHiddenClass(bytes, false).lookupClass(); assertHiddenClass(hc); - assertTrue(hc.getNestHost() == hc); + assertSame(hc, hc.getNestHost()); Class[] members = hc.getNestMembers(); - assertTrue(members.length == 1 && members[0] == hc); + assertEquals(1, members.length); + assertSame(hc, members[0]); } // a hidden class with bad InnerClasses or EnclosingMethod attribute private void hiddenClassWithBadAttribute(Class hc, String badDeclaringClassName) { assertTrue(hc.isHidden()); - assertTrue(hc.getCanonicalName() == null); + assertNull(hc.getCanonicalName()); assertTrue(hc.getName().contains("/")); if (badDeclaringClassName == null) { // the following reflection API assumes a good name in InnerClasses // or EnclosingMethod attribute can successfully be resolved. - assertTrue(hc.getSimpleName().length() > 0); + assertFalse(hc.getSimpleName().isEmpty()); assertFalse(hc.isAnonymousClass()); assertFalse(hc.isLocalClass()); assertFalse(hc.isMemberClass()); @@ -483,43 +469,34 @@ public class BasicTest { } // validation of nest membership - assertTrue(hc.getNestHost() == hc); + assertSame(hc, hc.getNestHost()); // validate the static nest membership Class[] members = hc.getNestMembers(); - assertTrue(members.length == 1 && members[0] == hc); + assertEquals(1, members.length); + assertSame(hc, members[0]); } // Class::getSimpleName, Class::isMemberClass private void declaringClassNotFound(Class c, String cn) { - try { - // fail to find declaring/enclosing class - c.isMemberClass(); - assertTrue(false); - } catch (NoClassDefFoundError e) { - if (!e.getMessage().equals(cn)) { - throw e; - } + var e = assertThrows(NoClassDefFoundError.class, c::isMemberClass); + if (!e.getMessage().equals(cn)) { + throw e; } - try { - // fail to find declaring/enclosing class - c.getSimpleName(); - assertTrue(false); - } catch (NoClassDefFoundError e) { - if (!e.getMessage().equals(cn)) { - throw e; - } + e = assertThrows(NoClassDefFoundError.class, c::getSimpleName); + if (!e.getMessage().equals(cn)) { + throw e; } } private static void singletonNest(Class hc) { - assertTrue(hc.getNestHost() == hc); - assertTrue(hc.getNestMembers().length == 1); - assertTrue(hc.getNestMembers()[0] == hc); + assertSame(hc, hc.getNestHost()); + assertEquals(1, hc.getNestMembers().length); + assertSame(hc, hc.getNestMembers()[0]); } private static void assertHiddenClass(Class hc) { assertTrue(hc.isHidden()); - assertTrue(hc.getCanonicalName() == null); + assertNull(hc.getCanonicalName()); assertTrue(hc.getName().contains("/")); assertFalse(hc.isAnonymousClass()); assertFalse(hc.isLocalClass()); diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/HiddenNestmateTest.java b/test/jdk/java/lang/invoke/defineHiddenClass/HiddenNestmateTest.java index e026a7a1387..a71029dd229 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/HiddenNestmateTest.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/HiddenNestmateTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -25,7 +25,7 @@ * @test * @library /test/lib * @build HiddenNestmateTest - * @run testng/othervm HiddenNestmateTest + * @run junit/othervm HiddenNestmateTest */ import java.lang.classfile.ClassFile; @@ -37,9 +37,6 @@ import java.lang.reflect.AccessFlag; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.stream.Stream; -import java.util.Arrays; - -import org.testng.annotations.Test; import static java.lang.constant.ConstantDescs.CD_Object; import static java.lang.constant.ConstantDescs.CD_int; @@ -48,7 +45,8 @@ import static java.lang.constant.ConstantDescs.MTD_void; import static java.lang.invoke.MethodHandles.Lookup.ClassOption.*; import static java.lang.invoke.MethodHandles.Lookup.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class HiddenNestmateTest { private static final ClassDesc CD_HiddenNestmateTest = HiddenNestmateTest.class.describeConstable().orElseThrow(); @@ -61,12 +59,12 @@ public class HiddenNestmateTest { Class hiddenClass = lookup.lookupClass(); Class nestHost = hiddenClass.getNestHost(); assertTrue(hiddenClass.isHidden()); - assertTrue(nestHost == MethodHandles.lookup().lookupClass()); + assertSame(MethodHandles.lookup().lookupClass(), nestHost); // hidden nestmate is not listed in the return array of getNestMembers assertTrue(Stream.of(nestHost.getNestMembers()).noneMatch(k -> k == hiddenClass)); assertTrue(hiddenClass.isNestmateOf(lookup.lookupClass())); - assertTrue(Arrays.equals(hiddenClass.getNestMembers(), nestHost.getNestMembers())); + assertArrayEquals(nestHost.getNestMembers(), hiddenClass.getNestMembers()); } /* @@ -78,23 +76,19 @@ public class HiddenNestmateTest { Lookup lookup = MethodHandles.lookup().defineHiddenClass(bytes, false); Class c = lookup.lookupClass(); assertTrue(lookup.hasFullPrivilegeAccess()); - assertTrue((lookup.lookupModes() & ORIGINAL) == ORIGINAL); - assertTrue(c.getNestHost() == c); // host of its own nest + assertEquals(ORIGINAL, lookup.lookupModes() & ORIGINAL); + assertSame(c, c.getNestHost()); // host of its own nest assertTrue(c.isHidden()); // invoke int test(HiddenNestmateTest o) via MethodHandle MethodHandle ctor = lookup.findConstructor(c, MethodType.methodType(void.class)); MethodHandle mh = lookup.findVirtual(c, "test", MethodType.methodType(int.class, HiddenNestmateTest.class)); - try { + assertThrows(IllegalAccessError.class, () -> { int x = (int) mh.bindTo(ctor.invoke()).invokeExact(this); - throw new RuntimeException("should fail when accessing HiddenNestmateTest.privMethod()"); - } catch (IllegalAccessError e) {} + }); // invoke int test(HiddenNestmateTest o) - try { - int x1 = testInjectedClass(c); - throw new RuntimeException("should fail when accessing HiddenNestmateTest.privMethod()"); - } catch (IllegalAccessError e) {} + assertThrows(IllegalAccessError.class, () -> testInjectedClass(c)); } /* @@ -111,11 +105,11 @@ public class HiddenNestmateTest { MethodHandle ctor = lookup.findConstructor(c, MethodType.methodType(void.class)); MethodHandle mh = lookup.findVirtual(c, "test", MethodType.methodType(int.class, HiddenNestmateTest.class)); int x = (int)mh.bindTo(ctor.invoke()).invokeExact( this); - assertTrue(x == privMethod()); + assertEquals(privMethod(), x); // invoke int test(HiddenNestmateTest o) int x1 = testInjectedClass(c); - assertTrue(x1 == privMethod()); + assertEquals(privMethod(), x1); } /* @@ -131,10 +125,10 @@ public class HiddenNestmateTest { /* * Fail to create a hidden class if dropping PRIVATE lookup mode */ - @Test(expectedExceptions = IllegalAccessException.class) + @Test public void noPrivateLookupAccess() throws Throwable { Lookup lookup = MethodHandles.lookup().dropLookupMode(Lookup.PRIVATE); - lookup.defineHiddenClass(bytes, false, NESTMATE); + assertThrows(IllegalAccessException.class, () -> lookup.defineHiddenClass(bytes, false, NESTMATE)); } public void teleportToNestmate() throws Throwable { @@ -143,8 +137,8 @@ public class HiddenNestmateTest { // Teleport to a hidden nestmate Lookup lc = MethodHandles.lookup().in(lookup.lookupClass()); - assertTrue((lc.lookupModes() & PRIVATE) != 0); - assertTrue((lc.lookupModes() & ORIGINAL) == 0); + assertNotEquals(0, lc.lookupModes() & PRIVATE); + assertEquals(0, lc.lookupModes() & ORIGINAL); Lookup lc2 = lc.defineHiddenClass(bytes, false, NESTMATE); assertNestmate(lc2); @@ -153,9 +147,9 @@ public class HiddenNestmateTest { /* * Fail to create a hidden class in a different package from the lookup class' package */ - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void notSamePackage() throws Throwable { - MethodHandles.lookup().defineHiddenClass(classBytes("p/HiddenInjected"), false, NESTMATE); + assertThrows(IllegalArgumentException.class, () -> MethodHandles.lookup().defineHiddenClass(classBytes("p/HiddenInjected"), false, NESTMATE)); } /* diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/LambdaNestedInnerTest.java b/test/jdk/java/lang/invoke/defineHiddenClass/LambdaNestedInnerTest.java index 9e3c8a8b318..7524e67bf9e 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/LambdaNestedInnerTest.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/LambdaNestedInnerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -25,7 +25,7 @@ * @test * @summary define a lambda proxy class whose target class has an invalid * nest membership - * @run testng/othervm p.LambdaNestedInnerTest + * @run junit/othervm p.LambdaNestedInnerTest */ package p; @@ -41,11 +41,10 @@ import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class LambdaNestedInnerTest { private static final String INNER_CLASSNAME = "p.LambdaNestedInnerTest$Inner"; @@ -68,7 +67,7 @@ public class LambdaNestedInnerTest { lambda1.run(); } - // testng may not be visible to this class + // junit may not be visible to this class private static void assertTrue(boolean x) { if (!x) { throw new AssertionError("expected true but found false"); @@ -79,8 +78,8 @@ public class LambdaNestedInnerTest { } } - @BeforeTest - public void setup() throws IOException { + @BeforeAll + public static void setup() throws IOException { String filename = INNER_CLASSNAME.replace('.', File.separatorChar) + ".class"; Path src = Paths.get(System.getProperty("test.classes"), filename); Path dest = Paths.get(DIR, filename); @@ -93,9 +92,9 @@ public class LambdaNestedInnerTest { Class inner = Class.forName(INNER_CLASSNAME); // inner class is a nest member of LambdaNestedInnerTest Class nestHost = inner.getNestHost(); - assertTrue(nestHost == LambdaNestedInnerTest.class); + assertSame(LambdaNestedInnerTest.class, nestHost); Set> members = Arrays.stream(nestHost.getNestMembers()).collect(Collectors.toSet()); - assertEquals(members, Set.of(nestHost, inner, TestLoader.class)); + assertEquals(Set.of(nestHost, inner, TestLoader.class), members); // spin lambda proxy hidden class Runnable runnable = (Runnable) inner.newInstance(); @@ -107,8 +106,8 @@ public class LambdaNestedInnerTest { URL[] urls = new URL[] { Paths.get(DIR).toUri().toURL() }; URLClassLoader loader = new URLClassLoader(urls, null); Class inner = loader.loadClass(INNER_CLASSNAME); - assertTrue(inner.getClassLoader() == loader); - assertTrue(inner.getNestHost() == inner); // linkage error ignored + assertSame(loader, inner.getClassLoader()); + assertSame(inner, inner.getNestHost()); // linkage error ignored Runnable runnable = (Runnable) inner.newInstance(); // this validates the lambda proxy class @@ -125,8 +124,8 @@ public class LambdaNestedInnerTest { TestLoader loader = new TestLoader(urls); Class inner = loader.loadClass(INNER_CLASSNAME); - assertTrue(inner.getClassLoader() == loader); - assertTrue(inner.getNestHost() == inner); // linkage error ignored. + assertSame(loader, inner.getClassLoader()); + assertSame(inner, inner.getNestHost()); // linkage error ignored. Runnable runnable = (Runnable) inner.newInstance(); // this validates the lambda proxy class diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/PreviewHiddenClass.java b/test/jdk/java/lang/invoke/defineHiddenClass/PreviewHiddenClass.java index fddbb348517..bd6c87808fe 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/PreviewHiddenClass.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/PreviewHiddenClass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -29,7 +29,7 @@ * @requires !java.enablePreview * @build jdk.test.lib.Utils * jdk.test.lib.compiler.CompilerUtils - * @run testng PreviewHiddenClass + * @run junit PreviewHiddenClass * @summary verify UnsupportedClassVersionError thrown when defining a hidden class * with preview minor version but --enable-preview is not set * @comment This test itself cannot enablePreview, or hidden class definition @@ -46,15 +46,15 @@ import java.nio.file.Paths; import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.Utils; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class PreviewHiddenClass { private static final Path SRC_DIR = Paths.get(Utils.TEST_SRC, "src"); private static final Path CLASSES_DIR = Paths.get("classes"); - @Test(expectedExceptions = { UnsupportedClassVersionError.class }) + @Test public void previewNotEnabled() throws Exception { // compile a class with --enable-preview Path sourceFile = SRC_DIR.resolve("HiddenInterface.java"); @@ -67,7 +67,7 @@ public class PreviewHiddenClass { byte[] bytes = Files.readAllBytes(CLASSES_DIR.resolve("HiddenInterface.class")); var dis = new DataInputStream(new ByteArrayInputStream(bytes)); dis.skipBytes(4); // 0xCAFEBABE - assertEquals(dis.readUnsignedShort(), 65535); // Minor version - MethodHandles.lookup().defineHiddenClass(bytes, false); + assertEquals(65535, dis.readUnsignedShort()); // Minor version + assertThrows(UnsupportedClassVersionError.class, () -> MethodHandles.lookup().defineHiddenClass(bytes, false)); } } diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/StaticInvocableTest.java b/test/jdk/java/lang/invoke/defineHiddenClass/StaticInvocableTest.java index 1c95caa97d3..ac0a29c247d 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/StaticInvocableTest.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/StaticInvocableTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, 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 @@ -27,7 +27,7 @@ * @summary hidden class members can't be statically invocable * @modules java.base/jdk.internal.misc * @build java.base/* - * @run testng StaticInvocableTest + * @run junit StaticInvocableTest */ import java.lang.classfile.ClassFile; @@ -38,7 +38,6 @@ import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; import java.lang.invoke.LookupHelper; import java.lang.reflect.AccessFlag; -import org.testng.annotations.Test; import static java.lang.classfile.ClassFile.ACC_PUBLIC; import static java.lang.classfile.ClassFile.ACC_STATIC; @@ -46,6 +45,7 @@ import static java.lang.constant.ConstantDescs.CD_Object; import static java.lang.constant.ConstantDescs.CD_int; import static java.lang.constant.ConstantDescs.INIT_NAME; import static java.lang.constant.ConstantDescs.MTD_void; +import org.junit.jupiter.api.Test; public class StaticInvocableTest { public static void main(String[] args) throws Throwable { diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/TypeDescriptorTest.java b/test/jdk/java/lang/invoke/defineHiddenClass/TypeDescriptorTest.java index e60cb8a5782..575eac1ccd1 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/TypeDescriptorTest.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/TypeDescriptorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -21,10 +21,10 @@ * questions. */ -/** +/* * @test * @bug 8242013 - * @run testng/othervm test.TypeDescriptorTest + * @run junit/othervm test.TypeDescriptorTest * @summary Test TypeDescriptor::descriptorString for hidden classes which * cannot be used to produce ConstantDesc via ClassDesc or * MethodTypeDesc factory methods @@ -42,9 +42,10 @@ import java.nio.file.Files; import java.nio.file.Paths; import static java.lang.invoke.MethodType.*; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class TypeDescriptorTest { private static final Lookup HC_LOOKUP = defineHiddenClass(); @@ -61,8 +62,7 @@ public class TypeDescriptorTest { } } - @DataProvider(name = "constables") - private Object[][] constables() throws Exception { + private static Object[][] constables() throws Exception { Class hcArray = Array.newInstance(HC, 1).getClass(); return new Object[][] { new Object[] { HC }, @@ -79,7 +79,8 @@ public class TypeDescriptorTest { * Hidden classes have no nominal descriptor. * Constable::describeConstable returns empty optional. */ - @Test(dataProvider = "constables") + @ParameterizedTest + @MethodSource("constables") public void noNominalDescriptor(Constable constable) { assertTrue(constable.describeConstable().isEmpty()); } @@ -90,27 +91,13 @@ public class TypeDescriptorTest { */ @Test public void testClassDesc() { - try { - ClassDesc.ofDescriptor(HC.descriptorString()); - assertFalse(true); - } catch (IllegalArgumentException e) {} - - try { - ClassDesc.ofDescriptor(HC.getName()); - assertFalse(true); - } catch (IllegalArgumentException e) {} - try { - ClassDesc.of(HC.getPackageName(), HC.getSimpleName()); - assertFalse(true); - } catch (IllegalArgumentException e) {} - try { - ClassDesc.of(HC.getName()); - assertFalse(true); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> ClassDesc.ofDescriptor(HC.descriptorString())); + assertThrows(IllegalArgumentException.class, () -> ClassDesc.ofDescriptor(HC.getName())); + assertThrows(IllegalArgumentException.class, () -> ClassDesc.of(HC.getPackageName(), HC.getSimpleName())); + assertThrows(IllegalArgumentException.class, () -> ClassDesc.of(HC.getName())); } - @DataProvider(name = "typeDescriptors") - private Object[][] typeDescriptors() throws Exception { + private static Object[][] typeDescriptors() throws Exception { Class hcArray = Array.newInstance(HC, 1, 1).getClass(); return new Object[][] { new Object[] { HC, "Ltest/HiddenClass.0x[0-9a-f]+;"}, @@ -124,26 +111,20 @@ public class TypeDescriptorTest { /* * Hidden classes have no nominal type descriptor */ - @Test(dataProvider = "typeDescriptors") + @ParameterizedTest + @MethodSource("typeDescriptors") public void testTypeDescriptor(TypeDescriptor td, String regex) throws Exception { String desc = td.descriptorString(); assertTrue(desc.matches(regex)); if (td instanceof Class) { - try { - ClassDesc.ofDescriptor(desc); - assertFalse(true); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> ClassDesc.ofDescriptor(desc)); } else if (td instanceof MethodType) { - try { - MethodTypeDesc.ofDescriptor(desc); - assertFalse(true); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> MethodTypeDesc.ofDescriptor(desc)); } } - @DataProvider(name = "methodTypes") - private Object[][] methodTypes() throws Exception { + private static Object[][] methodTypes() throws Exception { Class hcArray = Array.newInstance(HC, 1, 1).getClass(); return new Object[][] { new Object[] { methodType(HC), "\\(\\)Ltest/HiddenClass.0x[0-9a-f]+;" }, @@ -155,15 +136,13 @@ public class TypeDescriptorTest { /* * Test MethodType::toMethodDescriptorString with MethodType referencing to hidden class */ - @Test(dataProvider = "methodTypes") + @ParameterizedTest + @MethodSource("methodTypes") public void testToMethodDescriptorString(MethodType mtype, String regex) throws Exception { String desc = mtype.toMethodDescriptorString(); assertTrue(desc.matches(regex)); - try { - MethodType.fromMethodDescriptorString(desc, TypeDescriptorTest.class.getClassLoader()); - assertFalse(true); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> MethodType.fromMethodDescriptorString(desc, TypeDescriptorTest.class.getClassLoader())); } } diff --git a/test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java b/test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java index b016b2f6899..45728f2ed79 100644 --- a/test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java +++ b/test/jdk/java/lang/invoke/defineHiddenClass/UnloadingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -27,7 +27,7 @@ * @modules jdk.compiler * @library /test/lib/ * @build jdk.test.lib.util.ForceGC - * @run testng/othervm UnloadingTest + * @run junit/othervm UnloadingTest */ import java.io.IOException; @@ -48,18 +48,16 @@ import jdk.test.lib.util.ForceGC; import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.Utils; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import static java.lang.invoke.MethodHandles.lookup; import static java.lang.invoke.MethodHandles.Lookup.ClassOption.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class UnloadingTest { private static final Path CLASSES_DIR = Paths.get("classes"); private static byte[] hiddenClassBytes; - @BeforeTest + @BeforeAll static void setup() throws IOException { Path src = Paths.get(Utils.TEST_SRC, "src", "LookupHelper.java"); if (!CompilerUtils.compile(src, CLASSES_DIR)) { @@ -116,7 +114,7 @@ public class UnloadingTest { // keep a strong reference to the nest member class Class member = unloaders[1].weakRef.get(); - assertTrue(member != null); + assertNotNull(member); // nest host and member will not be unloaded assertFalse(unloaders[0].tryUnload()); assertFalse(unloaders[1].tryUnload()); @@ -180,7 +178,7 @@ public class UnloadingTest { } else { hc = lookup.defineHiddenClass(hiddenClassBytes, false).lookupClass(); } - assertTrue(hc.getClassLoader() == lookup.lookupClass().getClassLoader()); + assertSame(lookup.lookupClass().getClassLoader(), hc.getClassLoader()); return new HiddenClassUnloader(hc); } @@ -202,7 +200,7 @@ public class UnloadingTest { } else { member = hostLookup.defineHiddenClass(hiddenClassBytes, false, NESTMATE).lookupClass(); } - assertTrue(member.getNestHost() == host); + assertSame(host, member.getNestHost()); return new HiddenClassUnloader[] { new HiddenClassUnloader(host), new HiddenClassUnloader(member) }; } diff --git a/test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java b/test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java index 9b6622a7e9c..5bb7f67c000 100644 --- a/test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java +++ b/test/jdk/java/lang/invoke/findSpecial/FindSpecialTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -21,12 +21,12 @@ * questions. */ -/** +/* * @test * @bug 8209005 8209078 * @library /test/lib * @build m1/* FindSpecialTest - * @run testng/othervm FindSpecialTest + * @run junit/othervm FindSpecialTest * @summary Test findSpecial and unreflectSpecial of the declaring class * of the method and the special caller are not in the same module * as the lookup class. @@ -39,7 +39,7 @@ import java.nio.file.Paths; import static jdk.test.lib.process.ProcessTools.*; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class FindSpecialTest { static final String TEST_CLASSES = System.getProperty("test.classes", "."); @@ -51,7 +51,7 @@ public class FindSpecialTest { * Run test.FindSpecial in unnamed module */ @Test - public static void callerInUnnamedModule() throws Throwable { + public void callerInUnnamedModule() throws Throwable { Path m1 = Paths.get(TEST_CLASSES, "modules", TEST_MODULE); if (Files.notExists(m1)) { throw new Error(m1 + " not exist"); @@ -66,7 +66,7 @@ public class FindSpecialTest { * Run test.FindSpecial in a named module */ @Test - public static void callerInNamedModule() throws Throwable { + public void callerInNamedModule() throws Throwable { Path modules = Paths.get(TEST_CLASSES, "modules"); if (Files.notExists(modules)) { throw new Error(modules + " not exist"); diff --git a/test/jdk/java/lang/invoke/lambda/LambdaFileEncodingSerialization.java b/test/jdk/java/lang/invoke/lambda/LambdaFileEncodingSerialization.java index 1f950ffce7e..6c505ddf471 100644 --- a/test/jdk/java/lang/invoke/lambda/LambdaFileEncodingSerialization.java +++ b/test/jdk/java/lang/invoke/lambda/LambdaFileEncodingSerialization.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -21,36 +21,33 @@ * questions. */ -/** +/* * @test * @bug 8248231 * @summary Test to verify lambda serialization uses the correct UTF-8 encoding * @library /test/lib * @build jdk.test.lib.JDKToolFinder * jdk.test.lib.process.ProcessTools - * @run testng LambdaFileEncodingSerialization + * @run junit LambdaFileEncodingSerialization */ import java.io.File; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Arrays; import java.util.ArrayList; -import org.testng.annotations.Test; -import static org.testng.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import jdk.test.lib.JDKToolFinder; import jdk.test.lib.process.ProcessTools; +import org.junit.jupiter.api.Test; public class LambdaFileEncodingSerialization { private static final String TEST_NAME = "TestLambdaFileEncodingSerialization"; @Test - public static void testDeserializeLambdaEncoding() throws Throwable { + public void testDeserializeLambdaEncoding() throws Throwable { String javac = JDKToolFinder.getTestJDKTool("javac"); String java = JDKToolFinder.getTestJDKTool("java"); diff --git a/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java b/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java index aed19e6ca17..0dbdff79230 100644 --- a/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java +++ b/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java @@ -29,8 +29,7 @@ import java.util.function.IntSupplier; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /* * @test @@ -62,7 +61,7 @@ public class LambdaHiddenCaller { void testSerializableLambda() { var is = hiddenCaller.callSerializableLambda(); assertEquals(42, is.getAsInt()); - assertTrue(Serializable.class.isAssignableFrom(is.getClass())); + assertInstanceOf(Serializable.class, is); // We do not guarantee serialization functionalities yet } } diff --git a/test/jdk/java/lang/invoke/lambda/LogGeneratedClassesTest.java b/test/jdk/java/lang/invoke/lambda/LogGeneratedClassesTest.java index 60c85753d72..eb013bf01f3 100644 --- a/test/jdk/java/lang/invoke/lambda/LogGeneratedClassesTest.java +++ b/test/jdk/java/lang/invoke/lambda/LogGeneratedClassesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -29,7 +29,7 @@ * @library /java/nio/file * @modules jdk.compiler * jdk.zipfs - * @run testng LogGeneratedClassesTest + * @run junit LogGeneratedClassesTest * @summary tests logging generated classes for lambda */ import java.io.IOException; @@ -45,24 +45,24 @@ import java.nio.file.attribute.PosixFileAttributeView; import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.process.OutputAnalyzer; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.testng.SkipException; import static java.nio.file.attribute.PosixFilePermissions.*; import static jdk.test.lib.process.ProcessTools.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import org.junit.jupiter.api.AfterAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class LogGeneratedClassesTest { static final Path DUMP_LAMBDA_PROXY_CLASS_FILES = Path.of("DUMP_LAMBDA_PROXY_CLASS_FILES"); static final Path CLASSES = Path.of("classes").toAbsolutePath(); - String longFQCN; + static String longFQCN; - @BeforeClass - public void setup() throws IOException { + @BeforeAll + public static void setup() throws IOException { final List scratch = new ArrayList<>(); scratch.clear(); scratch.add("package com.example;"); @@ -102,8 +102,8 @@ public class LogGeneratedClassesTest { CompilerUtils.compile(Path.of("."), CLASSES); } - @AfterClass - public void cleanup() throws IOException { + @AfterAll + public static void cleanup() throws IOException { Files.delete(Paths.get("TestLambda.java")); Files.delete(Paths.get("LongPackageName.java")); TestUtil.removeAll(DUMP_LAMBDA_PROXY_CLASS_FILES); @@ -132,12 +132,11 @@ public class LogGeneratedClassesTest { executeProcess(pb).shouldHaveExitValue(0); // 2 our own class files. We don't care about the others - assertEquals(Files.find( - dumpDir, - 99, - (p, a) -> p.startsWith(dumpDir.resolve("com/example")) - && a.isRegularFile()).count(), - 2, "Two lambda captured"); + assertEquals(2, Files.find( + dumpDir, + 99, + (p, a) -> p.startsWith(dumpDir.resolve("com/example")) + && a.isRegularFile()).count(), "Two lambda captured"); } @Test @@ -155,12 +154,11 @@ public class LogGeneratedClassesTest { executeProcess(pb).shouldHaveExitValue(0); // The dump directory will be created if not exist - assertEquals(Files.find( - dumpDir, - 99, - (p, a) -> p.startsWith(dumpDir.resolve("com/example")) - && a.isRegularFile()).count(), - 2, "Two lambda captured"); + assertEquals(2, Files.find( + dumpDir, + 99, + (p, a) -> p.startsWith(dumpDir.resolve("com/example")) + && a.isRegularFile()).count(), "Two lambda captured"); } @Test @@ -208,12 +206,10 @@ public class LogGeneratedClassesTest { try { fs = Files.getFileStore(Paths.get(".")); } catch (IOException e) { - throw new SkipException("WARNING: IOException occurred: " + e + ", Skipping testDumpDirNotWritable test."); - } - if (!fs.supportsFileAttributeView(PosixFileAttributeView.class)) { - // No easy way to setup readonly directory without POSIX - throw new SkipException("WARNING: POSIX is not supported. Skipping testDumpDirNotWritable test."); + Assumptions.assumeTrue(false, "WARNING: IOException occurred: " + e + ", Skipping testDumpDirNotWritable test."); + return; } + Assumptions.assumeFalse(!fs.supportsFileAttributeView(PosixFileAttributeView.class), "WARNING: POSIX is not supported. Skipping testDumpDirNotWritable test."); // No easy way to setup readonly directory without POSIX Path testDir = Path.of("readOnly"); Path dumpDir = testDir.resolve(DUMP_LAMBDA_PROXY_CLASS_FILES); @@ -221,11 +217,8 @@ public class LogGeneratedClassesTest { Files.createDirectory(dumpDir, asFileAttribute(fromString("r-xr-xr-x"))); try { - if (isWriteableDirectory(dumpDir)) { - // Skipping the test: it's allowed to write into read-only directory - // (e.g. current user is super user). - throw new SkipException("WARNING: The dump directory is writeable. Skipping testDumpDirNotWritable test."); - } + Assumptions.assumeFalse(isWriteableDirectory(dumpDir), "WARNING: The dump directory is writeable. Skipping testDumpDirNotWritable test."); // Skipping the test: it's allowed to write into read-only directory + // (e.g. current user is super user). ProcessBuilder pb = createLimitedTestJavaProcessBuilder( "-cp", CLASSES.toString(), @@ -251,10 +244,9 @@ public class LogGeneratedClassesTest { longFQCN).directory(testDir.toFile()); OutputAnalyzer outputAnalyzer = executeProcess(pb); outputAnalyzer.shouldHaveExitValue(0); - assertEquals(outputAnalyzer.asLines().stream() - .filter(s -> s.startsWith("WARNING: Exception")) - .count(), - 2, "show error each capture"); + assertEquals(2, outputAnalyzer.asLines().stream() + .filter(s -> s.startsWith("WARNING: Exception")) + .count(), "show error each capture"); // dumpLong/DUMP_LAMBDA_PROXY_CLASS_FILES/com/example/nonsense/nonsense Path dumpPath = dumpDir.resolve("com/example/nonsense"); Predicate filter = p -> p.getParent() == null || dumpPath.startsWith(p) || p.startsWith(dumpPath); @@ -269,8 +261,8 @@ public class LogGeneratedClassesTest { } }); } - assertEquals(Files.walk(dumpDir) + assertEquals(5, Files.walk(dumpDir) .filter(filter) - .count(), 5, "Two lambda captured failed to log"); + .count(), "Two lambda captured failed to log"); } } diff --git a/test/jdk/java/lang/invoke/lambda/invokeSpecial/InvokeSpecialMethodTest.java b/test/jdk/java/lang/invoke/lambda/invokeSpecial/InvokeSpecialMethodTest.java index bf1db0f822e..4b74d05f270 100644 --- a/test/jdk/java/lang/invoke/lambda/invokeSpecial/InvokeSpecialMethodTest.java +++ b/test/jdk/java/lang/invoke/lambda/invokeSpecial/InvokeSpecialMethodTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, 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 @@ -24,22 +24,22 @@ /* * @test * @bug 8274848 - * @run testng InvokeSpecialMethodTest + * @run junit InvokeSpecialMethodTest * @summary ensure REF_invokeSpecial on a non-private implementation method * behaves as if `super::m` is invoked regardless of its access flag */ -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.CallSite; import java.lang.invoke.LambdaMetafactory; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import static java.lang.invoke.MethodType.methodType; +import static org.junit.jupiter.api.Assertions.assertEquals; public class InvokeSpecialMethodTest { static class MethodTest { @@ -95,8 +95,7 @@ public class InvokeSpecialMethodTest { String get(); } - @DataProvider - public Object[][] methodProvider() { + public static Object[][] methodProvider() { return new Object[][]{ {MethodTest.M_PUBLIC, "test_public"}, {MethodTest.M_PROTECTED, "test_protected"}, @@ -104,7 +103,8 @@ public class InvokeSpecialMethodTest { }; } - @Test(dataProvider = "methodProvider") + @ParameterizedTest + @MethodSource("methodProvider") void test(MethodHandle implMethod, String expected) throws Throwable { testMetafactory(implMethod, expected); testAltMetafactory(implMethod, expected); @@ -117,7 +117,7 @@ public class InvokeSpecialMethodTest { MethodTest o = new MethodTest.SubClass(); StringFactory factory = (StringFactory) cs.dynamicInvoker().invokeExact(o); String actual = factory.get(); - Assert.assertEquals(actual, expected); + assertEquals(expected, actual); } static void testAltMetafactory(MethodHandle implMethod, String expected) throws Throwable { @@ -128,6 +128,6 @@ public class InvokeSpecialMethodTest { MethodTest o = new MethodTest.SubClass(); StringFactory factory = (StringFactory) cs.dynamicInvoker().invokeExact(o); String actual = factory.get(); - Assert.assertEquals(actual, expected); + assertEquals(expected, actual); } } diff --git a/test/jdk/java/lang/invoke/lambda/superProtectedMethod/InheritedProtectedMethod.java b/test/jdk/java/lang/invoke/lambda/superProtectedMethod/InheritedProtectedMethod.java index a5cf6f68c50..fc730d790ac 100644 --- a/test/jdk/java/lang/invoke/lambda/superProtectedMethod/InheritedProtectedMethod.java +++ b/test/jdk/java/lang/invoke/lambda/superProtectedMethod/InheritedProtectedMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -28,7 +28,7 @@ * @library /test/lib * @build jdk.test.lib.Utils * jdk.test.lib.compiler.CompilerUtils - * @run testng/othervm InheritedProtectedMethod + * @run junit/othervm InheritedProtectedMethod * @summary Test method reference to a method inherited from its * superclass in a different package. Such method's modifier * is changed from public to protected. @@ -37,10 +37,6 @@ import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.Utils; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; @@ -48,13 +44,15 @@ import java.net.URLClassLoader; import java.nio.file.Path; import java.nio.file.Paths; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class InheritedProtectedMethod { private static final Path SRC_DIR = Paths.get(Utils.TEST_SRC, "src"); private static final Path CLASSES_DIR = Paths.get("classes"); - @BeforeTest + @BeforeAll static void setup() throws IOException { assertTrue(CompilerUtils.compile(SRC_DIR, CLASSES_DIR)); @@ -64,13 +62,13 @@ public class InheritedProtectedMethod { } @Test - public static void run() throws Exception { + public void run() throws Exception { URLClassLoader loader = new URLClassLoader("loader", new URL[]{ CLASSES_DIR.toUri().toURL()}, ClassLoader.getPlatformClassLoader()); Class methodInvokeClass = Class.forName("MethodInvoker", false, loader); Method invokeMethod = methodInvokeClass.getMethod("invoke"); String result = (String)invokeMethod.invoke(null); - assertEquals(result, "protected inherited method"); + assertEquals("protected inherited method", result); } } diff --git a/test/jdk/java/lang/invoke/lambda/superProtectedMethod/ProtectedMethodInOtherPackage.java b/test/jdk/java/lang/invoke/lambda/superProtectedMethod/ProtectedMethodInOtherPackage.java index 666ba5c254b..980114149a8 100644 --- a/test/jdk/java/lang/invoke/lambda/superProtectedMethod/ProtectedMethodInOtherPackage.java +++ b/test/jdk/java/lang/invoke/lambda/superProtectedMethod/ProtectedMethodInOtherPackage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -24,7 +24,7 @@ /* * @test * @bug 8227415 8254975 8270056 - * @run testng/othervm p.ProtectedMethodInOtherPackage + * @run junit/othervm p.ProtectedMethodInOtherPackage * @summary method reference to a protected method inherited from its * superclass in a different runtime package where * lambda proxy class has no access to it. @@ -47,12 +47,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.function.Function; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ProtectedMethodInOtherPackage { @Test - public static void remotePackageSameLoader() { + public void remotePackageSameLoader() { Sub_I sub = new Sub_I(); sub.test(Paths.get("test")); } @@ -76,14 +76,14 @@ public class ProtectedMethodInOtherPackage { } @Test - public static void splitPackage() throws Throwable { + public void splitPackage() throws Throwable { ClassLoader parent = new Loader("loader-A", null, A.class); ClassLoader loader = new Loader("loader-B", parent, B.class); Class aClass = Class.forName(A.class.getName(), false, loader); Class bClass = Class.forName(B.class.getName(), false, loader); - assertTrue(aClass.getClassLoader() == parent); - assertTrue(bClass.getClassLoader() == loader); - assertEquals(aClass.getPackageName(), bClass.getPackageName()); + assertSame(parent, aClass.getClassLoader()); + assertSame(loader, bClass.getClassLoader()); + assertEquals(bClass.getPackageName(), aClass.getPackageName()); Object b = bClass.getDeclaredConstructor().newInstance(); @@ -102,14 +102,14 @@ public class ProtectedMethodInOtherPackage { } @Test - public static void protectedStaticMethodInSplitPackage() throws Throwable { + public void protectedStaticMethodInSplitPackage() throws Throwable { ClassLoader parent = new Loader("loader-A1", null, A1.class); ClassLoader loader = new Loader("loader-B1", parent, B1.class); Class aClass1 = Class.forName(A1.class.getName(), false, loader); Class bClass1 = Class.forName(B1.class.getName(), false, loader); - assertTrue(aClass1.getClassLoader() == parent); - assertTrue(bClass1.getClassLoader() == loader); - assertEquals(aClass1.getPackageName(), bClass1.getPackageName()); + assertSame(parent, aClass1.getClassLoader()); + assertSame(loader, bClass1.getClassLoader()); + assertEquals(bClass1.getPackageName(), aClass1.getPackageName()); // verify subclass can access a static protected method inherited from // its superclass in a split package diff --git a/test/jdk/java/lang/invoke/lookup/ChainedLookupTest.java b/test/jdk/java/lang/invoke/lookup/ChainedLookupTest.java index 0e81c6a9eec..15a46e6ca2c 100644 --- a/test/jdk/java/lang/invoke/lookup/ChainedLookupTest.java +++ b/test/jdk/java/lang/invoke/lookup/ChainedLookupTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, 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 @@ -24,7 +24,7 @@ /* * @test * @bug 8013527 - * @run testng/othervm ChainedLookupTest + * @run junit/othervm ChainedLookupTest * @summary Test MethodHandles.lookup method to produce the Lookup object with * proper lookup class if invoked through reflection and method handle. */ @@ -33,11 +33,11 @@ import java.lang.invoke.*; import java.lang.invoke.MethodHandles.Lookup; import java.lang.reflect.Method; -import org.testng.annotations.Test; import static java.lang.invoke.MethodHandles.*; import static java.lang.invoke.MethodType.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class ChainedLookupTest { /** @@ -121,7 +121,7 @@ public class ChainedLookupTest { } void test(Lookup lookup, String msg) throws Throwable { - assertTrue(lookup.lookupClass() == ChainedLookupTest.class); + assertSame(ChainedLookupTest.class, lookup.lookupClass()); assertTrue(lookup.hasFullPrivilegeAccess()); MethodHandle mh = lookup.findStatic(lookup.lookupClass(), "say", methodType(void.class, String.class)); diff --git a/test/jdk/java/lang/invoke/lookup/LookupClassTest.java b/test/jdk/java/lang/invoke/lookup/LookupClassTest.java index 205bd3d893e..5970d0331dd 100644 --- a/test/jdk/java/lang/invoke/lookup/LookupClassTest.java +++ b/test/jdk/java/lang/invoke/lookup/LookupClassTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, 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 @@ -25,44 +25,44 @@ * @test * @bug 8173975 * @summary Lookup::in throws IAE if the target class is a primitive class or array class - * @run testng/othervm LookupClassTest + * @run junit/othervm LookupClassTest */ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class LookupClassTest { private static final LookupClassTest[] ARRAY = new LookupClassTest[0]; - @BeforeTest - public void test() { + @BeforeAll + public static void test() { assertTrue(ARRAY.getClass().isArray()); assertSamePackage(MethodHandles.lookup(), ARRAY.getClass()); assertSamePackage(MethodHandles.publicLookup(), int.class); } - private void assertSamePackage(Lookup lookup, Class targetClass) { - assertEquals(lookup.lookupClass().getPackageName(), targetClass.getPackageName()); + private static void assertSamePackage(Lookup lookup, Class targetClass) { + assertEquals(targetClass.getPackageName(), lookup.lookupClass().getPackageName()); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void arrayLookupClass() { Lookup lookup = MethodHandles.lookup(); - lookup.in(ARRAY.getClass()); + assertThrows(IllegalArgumentException.class, () -> lookup.in(ARRAY.getClass())); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void primitiveLookupClass() { Lookup lookup = MethodHandles.publicLookup(); - lookup.in(int.class); + assertThrows(IllegalArgumentException.class, () -> lookup.in(int.class)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void voidLookupClass() { Lookup lookup = MethodHandles.publicLookup(); - lookup.in(void.class); + assertThrows(IllegalArgumentException.class, () -> lookup.in(void.class)); } } diff --git a/test/jdk/java/lang/invoke/lookup/SpecialStatic.java b/test/jdk/java/lang/invoke/lookup/SpecialStatic.java index 31ded727d66..3ff99b9dfda 100644 --- a/test/jdk/java/lang/invoke/lookup/SpecialStatic.java +++ b/test/jdk/java/lang/invoke/lookup/SpecialStatic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2025, 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 @@ -25,7 +25,7 @@ * @bug 8032400 * @summary JSR292: invokeSpecial: InternalError attempting to lookup a method * @compile -XDignore.symbol.file SpecialStatic.java - * @run testng test.java.lang.invoke.lookup.SpecialStatic + * @run junit test.java.lang.invoke.lookup.SpecialStatic */ package test.java.lang.invoke.lookup; @@ -38,13 +38,13 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.AccessFlag; -import org.testng.annotations.*; import static java.lang.classfile.ClassFile.ACC_PUBLIC; import static java.lang.classfile.ClassFile.ACC_STATIC; import static java.lang.constant.ConstantDescs.*; import static java.lang.constant.DirectMethodHandleDesc.Kind.SPECIAL; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** * Test case: @@ -105,7 +105,7 @@ public class SpecialStatic { public void testConstant() throws Throwable { MethodHandle mh = (MethodHandle)t3.getDeclaredMethod("getMethodHandle").invoke(null); int result = (int)mh.invoke(t3.newInstance()); - assertEquals(result, 1); // T1.m should be invoked. + assertEquals(1, result); // T1.m should be invoked. } @Test @@ -113,7 +113,7 @@ public class SpecialStatic { MethodHandles.Lookup lookup = (MethodHandles.Lookup)t3.getDeclaredMethod("getLookup").invoke(null); MethodHandle mh = lookup.findSpecial(t1, "m", MethodType.methodType(int.class), t3); int result = (int)mh.invoke(t3.newInstance()); - assertEquals(result, 1); // T1.m should be invoked. + assertEquals(1, result); // T1.m should be invoked. } public static byte[] dumpT1() { diff --git a/test/jdk/java/lang/invoke/modules/Driver.java b/test/jdk/java/lang/invoke/modules/Driver.java index 5c00de3ad47..11c44280309 100644 --- a/test/jdk/java/lang/invoke/modules/Driver.java +++ b/test/jdk/java/lang/invoke/modules/Driver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, 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 @@ -21,9 +21,9 @@ * questions. */ -/** +/* * @test * @build m1/* m2/* Unnamed - * @run testng/othervm m1/p1.Main + * @run junit/othervm m1/p1.Main * @summary Basic test case for module access checks and Lookup.in. */ diff --git a/test/jdk/java/lang/invoke/modules/Driver1.java b/test/jdk/java/lang/invoke/modules/Driver1.java index 654ee04c9e0..4ef7130ff94 100644 --- a/test/jdk/java/lang/invoke/modules/Driver1.java +++ b/test/jdk/java/lang/invoke/modules/Driver1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -21,11 +21,11 @@ * questions. */ -/** +/* * @test * @bug 8173978 * @build m3/* m4/* m5/* Unnamed Unnamed1 - * @run testng/othervm m3/jdk.test.ModuleAccessTest + * @run junit/othervm m3/jdk.test.ModuleAccessTest * @summary Basic test case for module access checks and Lookup.in and * MethodHandles.privateLookupIn */ diff --git a/test/jdk/java/lang/invoke/modules/m1/module-info.java b/test/jdk/java/lang/invoke/modules/m1/module-info.java index db03841b4d0..ecd133ae6a1 100644 --- a/test/jdk/java/lang/invoke/modules/m1/module-info.java +++ b/test/jdk/java/lang/invoke/modules/m1/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -22,6 +22,6 @@ */ module m1 { requires m2; - requires org.testng; + requires org.junit.platform.console.standalone; exports p1; } diff --git a/test/jdk/java/lang/invoke/modules/m1/p1/Main.java b/test/jdk/java/lang/invoke/modules/m1/p1/Main.java index 0a4d2fff1db..5a2a7c91999 100644 --- a/test/jdk/java/lang/invoke/modules/m1/p1/Main.java +++ b/test/jdk/java/lang/invoke/modules/m1/p1/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -30,26 +30,24 @@ import java.lang.invoke.MethodType; import static java.lang.invoke.MethodHandles.Lookup.*; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** * Basic test case for module access checks and Lookup.in. */ - -@Test public class Main { - private Class p1_Type1; // m1, exported - private Class p2_Type2; // m1, not exported - private Class q1_Type1; // m2, exported - private Class q2_Type2; // m2, not exported - private Class signalClass; // java.base, not exported - private Class unnamedClass; // class in unnamed module + private static Class p1_Type1; // m1, exported + private static Class p2_Type2; // m1, not exported + private static Class q1_Type1; // m2, exported + private static Class q2_Type2; // m2, not exported + private static Class signalClass; // java.base, not exported + private static Class unnamedClass; // class in unnamed module - @BeforeTest - public void setup() throws Exception { + @BeforeAll + public static void setup() throws Exception { try { p1_Type1 = Class.forName("p1.Type1"); p2_Type2 = Class.forName("p2.Type2"); @@ -64,15 +62,15 @@ public class Main { // check setup Module m1 = ModuleLayer.boot().findModule("m1").orElse(null); assertNotNull(m1); - assertTrue(p1_Type1.getModule() == m1); - assertTrue(p2_Type2.getModule() == m1); + assertSame(m1, p1_Type1.getModule()); + assertSame(m1, p2_Type2.getModule()); assertTrue(m1.isExported("p1")); assertFalse(m1.isExported("p2")); Module m2 = ModuleLayer.boot().findModule("m2").orElse(null); assertNotNull(m2); - assertTrue(q1_Type1.getModule() == m2); - assertTrue(q2_Type2.getModule() == m2); + assertSame(m2, q1_Type1.getModule()); + assertSame(m2, q2_Type2.getModule()); assertTrue(m2.isExported("q1")); assertFalse(m2.isExported("q2")); @@ -91,9 +89,10 @@ public class Main { * [A2] can access public types in packages exported by modules that m1 reads * [A3] cannot access public types in non-exported modules of modules that m1 reads */ + @Test public void testLookup() throws Exception { Lookup lookup = MethodHandles.lookup(); - assertTrue((lookup.lookupModes() & MODULE) == MODULE); // [A0] + assertEquals(MODULE, lookup.lookupModes() & MODULE); // [A0] // m1 findConstructor(lookup, p1_Type1, void.class); // [A1] @@ -116,9 +115,10 @@ public class Main { * * [A0] module and public access is not lost */ + @Test public void testToSameModule() throws Exception { Lookup lookup = MethodHandles.lookup().in(p2_Type2); - assertTrue(lookup.lookupModes() == (MODULE|PUBLIC)); // [A0] + assertEquals(MODULE | PUBLIC, lookup.lookupModes()); // [A0] // m1 findConstructor(lookup, p1_Type1, void.class); @@ -142,15 +142,16 @@ public class Main { * [A0] has PUBLIC access if accessible; otherwise no access * [A1] old lookup class becomes previous lookup class */ + @Test public void testFromNamedToNamedModule() throws Exception { // m2/q1_Type1 is accessible to m1 whereas m2/q_Type2 is not accessible Lookup lookup = MethodHandles.lookup().in(q1_Type1); - assertTrue(lookup.lookupModes() == PUBLIC); // [A0] - assertTrue(lookup.previousLookupClass() == Main.class); // [A1] + assertEquals(PUBLIC, lookup.lookupModes()); // [A0] + assertSame(Main.class, lookup.previousLookupClass()); // [A1] Lookup lookup2 = MethodHandles.lookup().in(q2_Type2); - assertTrue(lookup2.lookupModes() == 0); // [A0] - assertTrue(lookup2.previousLookupClass() == Main.class); // [A1] + assertEquals(0, lookup2.lookupModes()); // [A0] + assertSame(Main.class, lookup2.previousLookupClass()); // [A1] // m1 findConstructorExpectingIAE(lookup, p1_Type1, void.class); @@ -185,9 +186,10 @@ public class Main { * * [A0] has PUBLIC access */ + @Test public void testFromNamedToUnnamedModule() throws Exception { Lookup lookup = MethodHandles.lookup().in(unnamedClass); - assertTrue(lookup.lookupModes() == PUBLIC); // [A0] + assertEquals(PUBLIC, lookup.lookupModes()); // [A0] // m1 findConstructor(lookup, p1_Type1, void.class); // p1 is exported @@ -210,10 +212,11 @@ public class Main { * * [A0] retains PUBLIC access */ + @Test public void testFromUnnamedToNamedModule() throws Exception { Lookup lookup = MethodHandles.lookup(); lookup = MethodHandles.privateLookupIn(unnamedClass, lookup).in(p1_Type1); - assertTrue(lookup.lookupModes() == PUBLIC); // A0 + assertEquals(PUBLIC, lookup.lookupModes()); // A0 // m1 findConstructor(lookup, p1_Type1, void.class); @@ -236,9 +239,10 @@ public class Main { * * [A0] has UNCONDITIONAL access */ + @Test public void testPublicLookup() throws Exception { Lookup lookup = MethodHandles.publicLookup(); - assertTrue(lookup.lookupModes() == UNCONDITIONAL); // A0 + assertEquals(UNCONDITIONAL, lookup.lookupModes()); // A0 // m1 findConstructor(lookup, p1_Type1, void.class); @@ -261,9 +265,10 @@ public class Main { * * [A0] has UNCONDITIONAL access */ + @Test public void testPublicLookupToBaseModule() throws Exception { Lookup lookup = MethodHandles.publicLookup().in(String.class); - assertTrue(lookup.lookupModes() == UNCONDITIONAL); // A0 + assertEquals(UNCONDITIONAL, lookup.lookupModes()); // A0 // m1 findConstructor(lookup, p1_Type1, void.class); @@ -287,9 +292,10 @@ public class Main { * * [A0] has UNCONDITIONAL access */ + @Test public void testPublicLookupToAccessibleTypeInNamedModule() throws Exception { Lookup lookup = MethodHandles.publicLookup().in(p1_Type1); - assertTrue(lookup.lookupModes() == UNCONDITIONAL); // A0 + assertEquals(UNCONDITIONAL, lookup.lookupModes()); // A0 // m1 findConstructor(lookup, p1_Type1, void.class); @@ -312,9 +318,10 @@ public class Main { * * [A0] has no access */ + @Test public void testPublicLookupToInaccessibleTypeInNamedModule() throws Exception { Lookup lookup = MethodHandles.publicLookup().in(p2_Type2); - assertTrue(lookup.lookupModes() == 0); // A0 + assertEquals(0, lookup.lookupModes()); // A0 // m1 findConstructorExpectingIAE(lookup, p1_Type1, void.class); @@ -337,9 +344,10 @@ public class Main { * * [A0] has UNCONDITIONAL access */ + @Test public void testPublicLookupToUnnamedModule() throws Exception { Lookup lookup = MethodHandles.publicLookup().in(unnamedClass); - assertTrue(lookup.lookupModes() == UNCONDITIONAL); // A0 + assertEquals(UNCONDITIONAL, lookup.lookupModes()); // A0 // m1 findConstructor(lookup, p1_Type1, void.class); @@ -366,10 +374,7 @@ public class Main { Class clazz, Class rtype, Class... ptypes) throws Exception { - try { - findConstructor(lookup, clazz, rtype, ptypes); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> findConstructor(lookup, clazz, rtype, ptypes)); } /** diff --git a/test/jdk/java/lang/invoke/modules/m3/jdk/test/ModuleAccessTest.java b/test/jdk/java/lang/invoke/modules/m3/jdk/test/ModuleAccessTest.java index 6a1e8efe103..235c712926d 100644 --- a/test/jdk/java/lang/invoke/modules/m3/jdk/test/ModuleAccessTest.java +++ b/test/jdk/java/lang/invoke/modules/m3/jdk/test/ModuleAccessTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -23,15 +23,12 @@ package jdk.test; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; +import java.lang.management.ThreadMXBean; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -42,7 +39,11 @@ import java.util.stream.Stream; import e1.CrackM5Access; import static java.lang.invoke.MethodHandles.Lookup.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class ModuleAccessTest { static ModuleLookup m3; @@ -55,8 +56,8 @@ public class ModuleAccessTest { static Class unnamed; static Class unnamed1; - @BeforeTest - public void setup() throws Exception { + @BeforeAll + public static void setup() throws Exception { m3 = new ModuleLookup("m3", 'C'); m4 = new ModuleLookup("m4", 'D'); m5 = new ModuleLookup("m5", 'E'); @@ -76,8 +77,7 @@ public class ModuleAccessTest { CrackM5Access.addReads(unnamed.getModule()); } - @DataProvider(name = "samePackage") - public Object[][] samePackage() throws Exception { + public static Object[][] samePackage() throws Exception { return new Object[][] { { m3.lookup, m3.type2 }, { privLookupIn, m3.type1 }, @@ -93,7 +93,8 @@ public class ModuleAccessTest { * [A1] no change in previous lookup class * [A2] PROTECTED, PRIVATE and ORIGINAL are dropped */ - @Test(dataProvider = "samePackage") + @ParameterizedTest + @MethodSource("samePackage") public void testLookupInSamePackage(Lookup lookup, Class targetClass) throws Exception { Class lookupClass = lookup.lookupClass(); Lookup lookup2 = lookup.in(targetClass); @@ -105,8 +106,7 @@ public class ModuleAccessTest { assertTrue(lookup2.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|ORIGINAL))); // [A2] } - @DataProvider(name = "sameModule") - public Object[][] sameModule() throws Exception { + public static Object[][] sameModule() throws Exception { return new Object[][] { { m3.lookup, m3.type3}, { privLookupIn, m3.type3}, @@ -121,20 +121,20 @@ public class ModuleAccessTest { * [A1] no change in previous lookup class * [A2] PROTECTED, PRIVATE, PACKAGE and ORIGINAL are dropped */ - @Test(dataProvider = "sameModule") + @ParameterizedTest + @MethodSource("sameModule") public void testLookupInSameModule(Lookup lookup, Class targetClass) throws Exception { Class lookupClass = lookup.lookupClass(); Lookup lookup2 = lookup.in(targetClass); - assertTrue(lookupClass.getPackage() != targetClass.getPackage()); - assertTrue(lookupClass.getModule() == targetClass.getModule()); - assertTrue(lookup2.lookupClass() == targetClass); // [A0] - assertTrue(lookup2.previousLookupClass() == lookup.previousLookupClass()); // [A1] - assertTrue(lookup2.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE|ORIGINAL))); // [A2] + assertNotSame(targetClass.getPackage(), lookupClass.getPackage()); + assertSame(targetClass.getModule(), lookupClass.getModule()); + assertSame(targetClass, lookup2.lookupClass()); // [A0] + assertSame(lookup.previousLookupClass(), lookup2.previousLookupClass()); // [A1] + assertEquals(lookup.lookupModes() & ~(PROTECTED | PRIVATE | PACKAGE | ORIGINAL), lookup2.lookupModes()); // [A2] } - @DataProvider(name = "anotherModule") - public Object[][] anotherModule() throws Exception { + public static Object[][] anotherModule() throws Exception { return new Object[][] { { m3.lookup, m4.type1, m5, m5.accessibleTypesTo(m3.module, m4.module) }, { m4.lookup, m5.type2, m3, m3.accessibleTypesTo(m4.module, m5.module) }, @@ -154,21 +154,22 @@ public class ModuleAccessTest { * [A5] can access public types in m1 exported to m0 * [A6] can access public types in m2 exported to m0 and m1 */ - @Test(dataProvider = "anotherModule") + @ParameterizedTest + @MethodSource("anotherModule") public void testLookupInAnotherModule(Lookup lookup, Class targetClass, ModuleLookup m2, Set> otherTypes) throws Exception { Class lookupClass = lookup.lookupClass(); Module m0 = lookupClass.getModule(); Module m1 = targetClass.getModule(); - assertTrue(m0 != m1); + assertNotSame(m1, m0); assertTrue(m0.canRead(m1)); assertTrue(m1.isExported(targetClass.getPackageName(), m0)); Lookup lookup2 = lookup.in(targetClass); - assertTrue(lookup2.lookupClass() == targetClass); // [A0] - assertTrue(lookup2.previousLookupClass() == lookup.lookupClass()); // [A1] - assertTrue(lookup2.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE|MODULE|ORIGINAL))); // [A2] + assertSame(targetClass, lookup2.lookupClass()); // [A0] + assertSame(lookup.lookupClass(), lookup2.previousLookupClass()); // [A1] + assertEquals(lookup.lookupModes() & ~(PROTECTED | PRIVATE | PACKAGE | MODULE | ORIGINAL), lookup2.lookupModes()); // [A2] // [A3] no access to module internal type in m0 // [A4] if m1 reads m0, @@ -207,7 +208,7 @@ public class ModuleAccessTest { // [A5] can access public types exported from m2 unconditionally // [A5] can access public types exported from m2 to m0 and m1 for (Class type : otherTypes) { - assertTrue(type.getModule() == m2.module); + assertSame(m2.module, type.getModule()); testAccess(lookup2, type); } @@ -215,10 +216,7 @@ public class ModuleAccessTest { for (Class type : Set.of(m2.type1, m2.type2, m2.type3)) { if (!otherTypes.contains(type)) { // type is accessible to this lookup - try { - lookup2.accessClass(type); - assertTrue(false); - } catch (IllegalAccessException e) {} + assertThrows(IllegalAccessException.class, () -> lookup2.accessClass(type)); findConstructorExpectingIAE(lookup2, type, void.class); } @@ -227,7 +225,7 @@ public class ModuleAccessTest { public void testAccess(Lookup lookup, Class type) throws Exception { // type is accessible to this lookup - assertTrue(lookup.accessClass(type) == type); + assertSame(type, lookup.accessClass(type)); // can find constructor findConstructor(lookup, type, void.class); @@ -237,28 +235,27 @@ public class ModuleAccessTest { Module m2 = type.getModule(); assertTrue(m0 != m1 && m0 != null); - assertTrue((lookup.lookupModes() & MODULE) == 0); + assertEquals(0, lookup.lookupModes() & MODULE); assertTrue(m0 != m2 || m1 != m2); MethodHandles.Lookup lookup2 = lookup.in(type); if (m2 == m1) { // the same module of the lookup class - assertTrue(lookup2.lookupClass() == type); - assertTrue(lookup2.previousLookupClass() == lookup.previousLookupClass()); + assertSame(type, lookup2.lookupClass()); + assertSame(lookup.previousLookupClass(), lookup2.previousLookupClass()); } else if (m2 == m0) { // hop back to the module of the previous lookup class - assertTrue(lookup2.lookupClass() == type); - assertTrue(lookup2.previousLookupClass() == lookup.lookupClass()); + assertSame(type, lookup2.lookupClass()); + assertSame(lookup.lookupClass(), lookup2.previousLookupClass()); } else { // hop to a third module - assertTrue(lookup2.lookupClass() == type); - assertTrue(lookup2.previousLookupClass() == lookup.lookupClass()); - assertTrue(lookup2.lookupModes() == 0); + assertSame(type, lookup2.lookupClass()); + assertSame(lookup.lookupClass(), lookup2.previousLookupClass()); + assertEquals(0, lookup2.lookupModes()); } } - @DataProvider(name = "thirdModule") - public Object[][] thirdModule() throws Exception { + public static Object[][] thirdModule() throws Exception { return new Object[][] { { m3.lookup, m4.type1, m5.type1}, { m3.lookup, m4.type2, m5.type1}, @@ -273,7 +270,8 @@ public class ModuleAccessTest { * [A1] c1 becomes previous lookup class * [A2] all access bits are dropped */ - @Test(dataProvider = "thirdModule") + @ParameterizedTest + @MethodSource("thirdModule") public void testLookupInThirdModule(Lookup lookup, Class c1, Class c2) throws Exception { Class c0 = lookup.lookupClass(); Module m0 = c0.getModule(); @@ -287,18 +285,17 @@ public class ModuleAccessTest { assertTrue(m2.isExported(c2.getPackageName(), m0) && m2.isExported(c2.getPackageName(), m1)); Lookup lookup1 = lookup.in(c1); - assertTrue(lookup1.lookupClass() == c1); - assertTrue(lookup1.previousLookupClass() == c0); - assertTrue(lookup1.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE|MODULE|ORIGINAL))); + assertSame(c1, lookup1.lookupClass()); + assertSame(c0, lookup1.previousLookupClass()); + assertEquals(lookup.lookupModes() & ~(PROTECTED | PRIVATE | PACKAGE | MODULE | ORIGINAL), lookup1.lookupModes()); Lookup lookup2 = lookup1.in(c2); - assertTrue(lookup2.lookupClass() == c2); // [A0] - assertTrue(lookup2.previousLookupClass() == c1); // [A1] - assertTrue(lookup2.lookupModes() == 0, lookup2.toString()); // [A2] + assertSame(c2, lookup2.lookupClass()); // [A0] + assertSame(c1, lookup2.previousLookupClass()); // [A1] + assertEquals(0, lookup2.lookupModes(), lookup2.toString()); // [A2] } - @DataProvider(name = "privLookupIn") - public Object[][] privLookupIn() throws Exception { + public static Object[][] privLookupIn() throws Exception { return new Object[][] { { m3.lookup, m4.type1 }, { m3.lookup, m5.type1 }, @@ -316,24 +313,22 @@ public class ModuleAccessTest { * [A2] the lookup class becomes previous lookup class * [A3] IAE thrown if lookup has no MODULE access */ - @Test(dataProvider = "privLookupIn") + @ParameterizedTest + @MethodSource("privLookupIn") public void testPrivateLookupIn(Lookup lookup, Class targetClass) throws Exception { Module m0 = lookup.lookupClass().getModule(); Module m1 = targetClass.getModule(); // privateLookupIn from m0 to m1 - assertTrue(m0 != m1); + assertNotSame(m1, m0); assertTrue(m1.isOpen(targetClass.getPackageName(), m0)); Lookup privLookup1 = MethodHandles.privateLookupIn(targetClass, lookup); - assertTrue(privLookup1.lookupModes() == (PROTECTED|PRIVATE|PACKAGE|PUBLIC)); // [A0] - assertTrue(privLookup1.lookupClass() == targetClass); // [A1] - assertTrue(privLookup1.previousLookupClass() == lookup.lookupClass()); // [A2] + assertEquals(PROTECTED | PRIVATE | PACKAGE | PUBLIC, privLookup1.lookupModes()); // [A0] + assertSame(targetClass, privLookup1.lookupClass()); // [A1] + assertSame(lookup.lookupClass(), privLookup1.previousLookupClass()); // [A2] // privLookup1 has no MODULE access; can't do privateLookupIn - try { - Lookup privLookup2 = MethodHandles.privateLookupIn(targetClass, privLookup1); // [A3] - assertFalse(privLookup2 != null); - } catch (IllegalAccessException e) {} + assertThrows(IllegalAccessException.class, () -> MethodHandles.privateLookupIn(targetClass, privLookup1)); // [A3] } /** @@ -343,9 +338,9 @@ public class ModuleAccessTest { public void testPrivateLookupAccess() throws Exception { Class staticsClass = e1.Statics.class; Lookup privLookup1 = MethodHandles.privateLookupIn(staticsClass, m4.lookup); - assertTrue((privLookup1.lookupModes() & MODULE) == 0); - assertTrue(privLookup1.lookupClass() == staticsClass); - assertTrue(privLookup1.previousLookupClass() == m4.lookup.lookupClass()); + assertEquals(0, (privLookup1.lookupModes() & MODULE)); + assertSame(staticsClass, privLookup1.lookupClass()); + assertSame(m4.lookup.lookupClass(), privLookup1.previousLookupClass()); // access private member and default package member in m5 MethodType mtype = MethodType.methodType(void.class); @@ -365,12 +360,9 @@ public class ModuleAccessTest { // lose private access Lookup privLookup2 = MethodHandles.privateLookupIn(m5.type1, m4.lookup); Lookup lookup = privLookup2.in(staticsClass); - assertTrue((lookup.lookupModes() & PRIVATE) == 0); + assertEquals(0, lookup.lookupModes() & PRIVATE); MethodHandle mh3 = lookup.findStatic(staticsClass, "packageMethod", mtype); - try { - lookup.findStatic(staticsClass, "privateMethod", mtype); - assertTrue(false); - } catch (IllegalAccessException e) {} + assertThrows(IllegalAccessException.class, () -> lookup.findStatic(staticsClass, "privateMethod", mtype)); } /** @@ -380,16 +372,16 @@ public class ModuleAccessTest { @Test public void testDropLookupMode() throws Exception { Lookup lookup = MethodHandles.privateLookupIn(m5.type1, m4.lookup); - assertTrue((lookup.lookupModes() & MODULE) == 0); + assertEquals(0, lookup.lookupModes() & MODULE); Lookup lookup1 = lookup.dropLookupMode(PRIVATE); - assertTrue(lookup1.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE))); + assertEquals(lookup1.lookupModes(), lookup.lookupModes() & ~(PROTECTED | PRIVATE)); Lookup lookup2 = lookup.dropLookupMode(PACKAGE); - assertTrue(lookup2.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE))); + assertEquals(lookup2.lookupModes(), lookup.lookupModes() & ~(PROTECTED | PRIVATE | PACKAGE)); Lookup lookup3 = lookup.dropLookupMode(MODULE); - assertTrue(lookup3.lookupModes() == (lookup.lookupModes() & ~(PROTECTED|PRIVATE|PACKAGE))); + assertEquals(lookup3.lookupModes(), lookup.lookupModes() & ~(PROTECTED | PRIVATE | PACKAGE)); Lookup lookup4 = lookup.dropLookupMode(PUBLIC); - assertTrue(lookup4.lookupModes() == 0); + assertEquals(0, lookup4.lookupModes()); } @@ -406,11 +398,8 @@ public class ModuleAccessTest { // drop MODULE access i.e. only PUBLIC access Lookup lookup = privLookup.dropLookupMode(MODULE); - assertTrue(lookup.lookupModes() == PUBLIC); - try { - MethodHandle mh2 = lookup.findStatic(nonPUblicType, "publicStatic", mtype); - assertFalse(mh2 != null); - } catch (IllegalAccessException e) {} + assertEquals(PUBLIC, lookup.lookupModes()); + assertThrows(IllegalAccessException.class, () -> lookup.findStatic(nonPUblicType, "publicStatic", mtype)); } @Test @@ -421,21 +410,18 @@ public class ModuleAccessTest { Lookup pub3 = pub2.in(java.lang.management.ThreadMXBean.class); Lookup pub4 = pub3.dropLookupMode(UNCONDITIONAL); - assertTrue(publicLookup.lookupClass() == Object.class); - assertTrue(publicLookup.lookupModes() == UNCONDITIONAL); - assertTrue(pub1.lookupClass() == m3.type1); - assertTrue(pub1.lookupModes() == UNCONDITIONAL); - assertTrue(pub2.lookupClass() == String.class); - assertTrue(pub2.lookupModes() == UNCONDITIONAL); - assertTrue(pub3.lookupClass() == java.lang.management.ThreadMXBean.class); - assertTrue(pub3.lookupModes() == UNCONDITIONAL); - assertTrue(pub4.lookupModes() == 0); + assertSame(Object.class, publicLookup.lookupClass()); + assertEquals(UNCONDITIONAL, publicLookup.lookupModes()); + assertSame(m3.type1, pub1.lookupClass()); + assertEquals(UNCONDITIONAL, pub1.lookupModes()); + assertSame(String.class, pub2.lookupClass()); + assertEquals(UNCONDITIONAL, pub2.lookupModes()); + assertSame(ThreadMXBean.class, pub3.lookupClass()); + assertEquals(UNCONDITIONAL, pub3.lookupModes()); + assertEquals(0, pub4.lookupModes()); // publicLookup has no MODULE access; can't do privateLookupIn - try { - Lookup pub5 = MethodHandles.privateLookupIn(m4.type1, pub1); - assertFalse(pub5 != null); - } catch (IllegalAccessException e) {} + assertThrows(IllegalAccessException.class, () -> MethodHandles.privateLookupIn(m4.type1, pub1)); } static class ModuleLookup { @@ -548,10 +534,7 @@ public class ModuleAccessTest { Class clazz, Class rtype, Class... ptypes) throws Exception { - try { - MethodHandle mh = findConstructor(lookup, clazz, rtype, ptypes); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> findConstructor(lookup, clazz, rtype, ptypes)); } /** diff --git a/test/jdk/java/lang/invoke/modules/m3/module-info.java b/test/jdk/java/lang/invoke/modules/m3/module-info.java index 1f47c42c196..c9d8fab20a5 100644 --- a/test/jdk/java/lang/invoke/modules/m3/module-info.java +++ b/test/jdk/java/lang/invoke/modules/m3/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2025, 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 @@ -24,7 +24,7 @@ module m3 { requires m4; requires m5; - requires org.testng; + requires org.junit.platform.console.standalone; requires java.management; exports c1; opens c2 to m5; diff --git a/test/jdk/java/lang/reflect/AccessibleObject/CanAccessTest.java b/test/jdk/java/lang/reflect/AccessibleObject/CanAccessTest.java index 45e2502b601..ac7a1bad31b 100644 --- a/test/jdk/java/lang/reflect/AccessibleObject/CanAccessTest.java +++ b/test/jdk/java/lang/reflect/AccessibleObject/CanAccessTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -21,11 +21,11 @@ * questions. */ -/** +/* * @test * @build CanAccessTest * @modules java.base/jdk.internal.misc:+open - * @run testng/othervm CanAccessTest + * @run junit/othervm CanAccessTest * @summary Test AccessibleObject::canAccess method */ @@ -34,31 +34,29 @@ import java.lang.reflect.Method; import java.security.SecureClassLoader; import jdk.internal.misc.Unsafe; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; -@Test public class CanAccessTest { private static Unsafe INSTANCE = Unsafe.getUnsafe(); /** * null object parameter for Constructor */ + @Test public void testConstructor() throws Exception { Constructor ctor = Unsafe.class.getDeclaredConstructor(); assertFalse(ctor.canAccess(null)); assertTrue(ctor.trySetAccessible()); - try { - // non-null object parameter - ctor.canAccess(INSTANCE); - assertTrue(false); - } catch (IllegalArgumentException expected) {} + // non-null object parameter + assertThrows(IllegalArgumentException.class, () -> ctor.canAccess(INSTANCE)); } /** * Test protected constructors */ + @Test public void testProtectedConstructor() throws Exception { TestLoader.testProtectedConstructorNonOpenedPackage(); @@ -69,21 +67,20 @@ public class CanAccessTest { /** * null object parameter for static members */ + @Test public void testStaticMember() throws Exception { Method m = Unsafe.class.getDeclaredMethod("throwIllegalAccessError"); assertFalse(m.canAccess(null)); assertTrue(m.trySetAccessible()); - try { - // non-null object parameter - m.canAccess(INSTANCE); - assertTrue(false); - } catch (IllegalArgumentException expected) { } + // non-null object parameter + assertThrows(IllegalArgumentException.class, () -> m.canAccess(INSTANCE)); } /** * Test protected static */ + @Test public void testProtectedStatic() throws Exception { Method m = TestLoader.testProtectedStatic(); assertFalse(m.canAccess(null)); @@ -93,28 +90,24 @@ public class CanAccessTest { * the specified object must be an instance of the declaring class * for instance members */ + @Test public void testInstanceMethod() throws Exception { Method m = Unsafe.class.getDeclaredMethod("allocateMemory0", long.class); assertFalse(m.canAccess(INSTANCE)); - try { - m.canAccess(null); - assertTrue(false); - } catch (IllegalArgumentException expected) { } + assertThrows(IllegalArgumentException.class, () -> m.canAccess(null)); } /** * the specified object must be an instance of the declaring class * for instance members */ + @Test public void testInvalidInstanceObject() throws Exception { Class clazz = Class.forName("sun.security.x509.X500Name"); Method m = clazz.getDeclaredMethod("size"); - try { - m.canAccess(INSTANCE); - assertTrue(false); - } catch (IllegalArgumentException expected) { } + assertThrows(IllegalArgumentException.class, () -> m.canAccess(INSTANCE)); } diff --git a/test/jdk/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java b/test/jdk/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java index 45cebdb552b..7d79a1ac49b 100644 --- a/test/jdk/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java +++ b/test/jdk/java/lang/reflect/AccessibleObject/ModuleSetAccessibleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -21,12 +21,12 @@ * questions. */ -/** +/* * @test * @build ModuleSetAccessibleTest * @modules java.base/java.lang:open * java.base/jdk.internal.misc:+open - * @run testng/othervm ModuleSetAccessibleTest + * @run junit/othervm ModuleSetAccessibleTest * @summary Test java.lang.reflect.AccessibleObject with modules */ @@ -40,22 +40,19 @@ import java.security.ProtectionDomain; import jdk.internal.misc.Unsafe; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; -@Test public class ModuleSetAccessibleTest { /** * Invoke a private constructor on a public class in an exported package */ + @Test public void testPrivateConstructorInExportedPackage() throws Exception { Constructor ctor = Unsafe.class.getDeclaredConstructor(); - try { - ctor.newInstance(); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> ctor.newInstance()); ctor.setAccessible(true); Unsafe unsafe = (Unsafe) ctor.newInstance(); @@ -65,34 +62,26 @@ public class ModuleSetAccessibleTest { /** * Invoke a private method on a public class in an exported package */ + @Test public void testPrivateMethodInExportedPackage() throws Exception { Method m = Unsafe.class.getDeclaredMethod("throwIllegalAccessError"); - try { - m.invoke(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> m.invoke(null)); m.setAccessible(true); - try { - m.invoke(null); - assertTrue(false); - } catch (InvocationTargetException e) { - // thrown by throwIllegalAccessError - assertTrue(e.getCause() instanceof IllegalAccessError); - } + InvocationTargetException e = assertThrows(InvocationTargetException.class, () -> + m.invoke(null)); + // thrown by throwIllegalAccessError + assertInstanceOf(IllegalAccessError.class, e.getCause()); } /** * Access a private field in a public class that is an exported package */ + @Test public void testPrivateFieldInExportedPackage() throws Exception { Field f = Unsafe.class.getDeclaredField("theUnsafe"); - - try { - f.get(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> f.get(null)); f.setAccessible(true); Unsafe unsafe = (Unsafe) f.get(null); @@ -102,19 +91,14 @@ public class ModuleSetAccessibleTest { /** * Invoke a public constructor on a public class in a non-exported package */ + @Test public void testPublicConstructorInNonExportedPackage() throws Exception { Class clazz = Class.forName("sun.security.x509.X500Name"); Constructor ctor = clazz.getConstructor(String.class); - try { - ctor.newInstance("cn=duke"); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> ctor.newInstance("cn=duke")); - try { - ctor.setAccessible(true); - assertTrue(false); - } catch (InaccessibleObjectException expected) { } + assertThrows(InaccessibleObjectException.class, () -> ctor.setAccessible(true)); ctor.setAccessible(false); // should succeed } @@ -123,19 +107,14 @@ public class ModuleSetAccessibleTest { /** * Access a public field in a public class that in a non-exported package */ + @Test public void testPublicFieldInNonExportedPackage() throws Exception { Class clazz = Class.forName("sun.security.x509.X500Name"); Field f = clazz.getField("SERIALNUMBER_OID"); - try { - f.get(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> f.get(null)); - try { - f.setAccessible(true); - assertTrue(false); - } catch (InaccessibleObjectException expected) { } + assertThrows(InaccessibleObjectException.class, () -> f.setAccessible(true)); f.setAccessible(false); // should succeed } @@ -144,6 +123,7 @@ public class ModuleSetAccessibleTest { /** * Test that the Class constructor cannot be make accessible. */ + @Test public void testJavaLangClass() throws Exception { // non-public constructor @@ -152,15 +132,8 @@ public class ModuleSetAccessibleTest { ProtectionDomain.class, boolean.class, char.class); AccessibleObject[] ctors = { ctor }; - try { - ctor.setAccessible(true); - assertTrue(false); - } catch (SecurityException expected) { } - - try { - AccessibleObject.setAccessible(ctors, true); - assertTrue(false); - } catch (SecurityException expected) { } + assertThrows(SecurityException.class, () -> ctor.setAccessible(true)); + assertThrows(SecurityException.class, () -> AccessibleObject.setAccessible(ctors, true)); // should succeed ctor.setAccessible(false); diff --git a/test/jdk/java/lang/reflect/AccessibleObject/TrySetAccessibleTest.java b/test/jdk/java/lang/reflect/AccessibleObject/TrySetAccessibleTest.java index 774ee4d1dad..bd4d0fab23f 100644 --- a/test/jdk/java/lang/reflect/AccessibleObject/TrySetAccessibleTest.java +++ b/test/jdk/java/lang/reflect/AccessibleObject/TrySetAccessibleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -21,14 +21,14 @@ * questions. */ -/** +/* * @test * @build TrySetAccessibleTest * @modules java.base/java.lang:open * java.base/jdk.internal.module * java.base/jdk.internal.perf * java.base/jdk.internal.misc:+open - * @run testng/othervm TrySetAccessibleTest + * @run junit/othervm TrySetAccessibleTest * @summary Test AccessibleObject::trySetAccessible method */ @@ -43,21 +43,18 @@ import jdk.internal.module.ModulePath; import jdk.internal.perf.Perf; import java.security.ProtectionDomain; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; -@Test public class TrySetAccessibleTest { /** * Invoke a private constructor on a public class in an exported package */ + @Test public void testPrivateConstructorInExportedPackage() throws Exception { Constructor ctor = Perf.class.getDeclaredConstructor(); - try { - ctor.newInstance(); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> ctor.newInstance()); assertFalse(ctor.trySetAccessible()); assertFalse(ctor.canAccess(null)); @@ -66,13 +63,11 @@ public class TrySetAccessibleTest { /** * Invoke a private constructor on a public class in an open package */ + @Test public void testPrivateConstructorInOpenedPackage() throws Exception { Constructor ctor = Unsafe.class.getDeclaredConstructor(); - try { - ctor.newInstance(); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> ctor.newInstance()); assertTrue(ctor.trySetAccessible()); assertTrue(ctor.canAccess(null)); @@ -82,12 +77,10 @@ public class TrySetAccessibleTest { /** * Invoke a private method on a public class in an exported package */ + @Test public void testPrivateMethodInExportedPackage() throws Exception { Method m = ModulePath.class.getDeclaredMethod("packageName", String.class); - try { - m.invoke(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> m.invoke(null)); assertFalse(m.trySetAccessible()); assertFalse(m.canAccess(null)); @@ -97,54 +90,42 @@ public class TrySetAccessibleTest { /** * Invoke a private method on a public class in an open package */ + @Test public void testPrivateMethodInOpenedPackage() throws Exception { Method m = Unsafe.class.getDeclaredMethod("throwIllegalAccessError"); assertFalse(m.canAccess(null)); - try { - m.invoke(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> m.invoke(null)); assertTrue(m.trySetAccessible()); assertTrue(m.canAccess(null)); - try { - m.invoke(null); - assertTrue(false); - } catch (InvocationTargetException e) { - // thrown by throwIllegalAccessError - assertTrue(e.getCause() instanceof IllegalAccessError); - } + + InvocationTargetException e = assertThrows(InvocationTargetException.class, () -> + m.invoke(null)); + assertInstanceOf(IllegalAccessError.class, e.getCause()); } /** * Invoke a private method on a public class in an exported package */ + @Test public void testPrivateFieldInExportedPackage() throws Exception { Field f = Perf.class.getDeclaredField("instance"); - try { - f.get(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> f.get(null)); assertFalse(f.trySetAccessible()); assertFalse(f.canAccess(null)); - try { - f.get(null); - assertTrue(false); - } catch (IllegalAccessException expected) {} + assertThrows(IllegalAccessException.class, () -> f.get(null)); } /** * Access a private field in a public class that is an exported package */ + @Test public void testPrivateFieldInOpenedPackage() throws Exception { Field f = Unsafe.class.getDeclaredField("theUnsafe"); - try { - f.get(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> f.get(null)); assertTrue(f.trySetAccessible()); assertTrue(f.canAccess(null)); @@ -155,32 +136,29 @@ public class TrySetAccessibleTest { /** * Invoke a public constructor on a public class in a non-exported package */ + @Test public void testPublicConstructorInNonExportedPackage() throws Exception { Class clazz = Class.forName("sun.security.x509.X500Name"); Constructor ctor = clazz.getConstructor(String.class); - try { - ctor.newInstance("cn=duke"); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> ctor.newInstance("cn=duke")); assertFalse(ctor.trySetAccessible()); assertFalse(ctor.canAccess(null)); - assertTrue(ctor.trySetAccessible() == ctor.isAccessible()); + assertFalse(ctor.trySetAccessible()); + assertFalse(ctor.isAccessible()); // should match trySetAccessible } /** * Access a public field in a public class that in a non-exported package */ + @Test public void testPublicFieldInNonExportedPackage() throws Exception { Class clazz = Class.forName("sun.security.x509.X500Name"); Field f = clazz.getField("SERIALNUMBER_OID"); - try { - f.get(null); - assertTrue(false); - } catch (IllegalAccessException expected) { } + assertThrows(IllegalAccessException.class, () -> f.get(null)); assertFalse(f.trySetAccessible()); assertFalse(f.canAccess(null)); @@ -190,6 +168,7 @@ public class TrySetAccessibleTest { /** * Test that the Class constructor cannot be make accessible. */ + @Test public void testJavaLangClass() throws Exception { // non-public constructor diff --git a/test/jdk/java/lang/reflect/ChainedReflection.java b/test/jdk/java/lang/reflect/ChainedReflection.java index 212a70345cd..bd76cd13fc8 100644 --- a/test/jdk/java/lang/reflect/ChainedReflection.java +++ b/test/jdk/java/lang/reflect/ChainedReflection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -23,9 +23,11 @@ /* * @test - * @run testng/othervm ChainedReflection + * @run junit/othervm ChainedReflection * @summary Test Method::invoke and Constructor::newInstance chained calls that * should wrap NPE in InvocationTargetException properly + * @comment This test is not using assertThrows given lambdas may affect the + * exception stack trace and therefore test anticipations */ import java.lang.reflect.Constructor; @@ -33,24 +35,28 @@ import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.util.Optional; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class ChainedReflection { - public ChainedReflection() {} - ChainedReflection(Void dummy) throws ReflectiveOperationException { - Method m = ChainedReflection.class.getMethod("throwNPE"); - try { - m.invoke(null); - } catch (InvocationTargetException e) { - Throwable t = e.getTargetException(); - if (t instanceof NullPointerException npe) { - throw npe; - } else { - throw new RuntimeException("Test failed (InvocationTargetException didn't wrap NullPointerException)"); + // This inner class is declared with a constructor that ctorCallMethodInvoke + // reflects on. Such a constructor cannot be declared in ChainedReflection + // because JUnit does not allow a test class to declare multiple constructors. + class Inner { + Inner() throws ReflectiveOperationException { + Method m = ChainedReflection.class.getMethod("throwNPE"); + try { + m.invoke(null); + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + if (t instanceof NullPointerException npe) { + throw npe; + } else { + throw new RuntimeException("Test failed (InvocationTargetException didn't wrap NullPointerException)"); + } + } catch (Throwable t) { + throw new RuntimeException("Test failed (Unexpected exception)", t); } - } catch (Throwable t) { - throw new RuntimeException("Test failed (Unexpected exception)", t); } } @@ -105,9 +111,9 @@ public class ChainedReflection { */ @Test public void ctorCallMethodInvoke() throws ReflectiveOperationException { - Constructor ctor = ChainedReflection.class.getDeclaredConstructor(Void.class); + Constructor ctor = ChainedReflection.Inner.class.getDeclaredConstructor(ChainedReflection.class); try { - ctor.newInstance((Void)null); + ctor.newInstance(this); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (!(t instanceof NullPointerException)) { diff --git a/test/jdk/java/lang/reflect/DefaultMethodMembers/FilterNotMostSpecific.java b/test/jdk/java/lang/reflect/DefaultMethodMembers/FilterNotMostSpecific.java index 1992f31d5de..b8738a383b0 100644 --- a/test/jdk/java/lang/reflect/DefaultMethodMembers/FilterNotMostSpecific.java +++ b/test/jdk/java/lang/reflect/DefaultMethodMembers/FilterNotMostSpecific.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -26,7 +26,7 @@ * @bug 8029674 * @summary Verify that the right interface methods are returned by * Class.getMethod() and Class.getMethods() - * @run testng FilterNotMostSpecific + * @run junit FilterNotMostSpecific */ import java.lang.reflect.*; @@ -39,14 +39,14 @@ import java.util.HashMap; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class FilterNotMostSpecific { - @Test(dataProvider="getCases") + @ParameterizedTest + @MethodSource("getCases") public void testGetMethod(Class iface) { boolean match = false; MethodDesc[] expectedMethods = iface.getAnnotationsByType(MethodDesc.class); @@ -67,7 +67,8 @@ public class FilterNotMostSpecific { assert(match); } - @Test(dataProvider="getCases") + @ParameterizedTest + @MethodSource("getCases") public void testGetMethods(Class iface) { List foundMethods = filterObjectMethods(iface.getMethods()); MethodDesc[] expectedMethods = iface.getAnnotationsByType(MethodDesc.class); @@ -84,7 +85,7 @@ public class FilterNotMostSpecific { fail("On: "+ iface +"\nDid not find " + toMethodString(expected) + " among " + foundMethods); } - assertEquals(foundMethods.size(), expectedMethods.length, + assertEquals(expectedMethods.length, foundMethods.size(), "\non: " + iface + "\nexpected: " + toMethodStrings(expectedMethods) + "\nfound: " + foundMethods + "\n"); @@ -565,8 +566,7 @@ public class FilterNotMostSpecific { @MethodDesc(name="m", declaringClass=F.class, isGetMethodReturn=true) abstract class H extends G implements F {} - @DataProvider - public Object[][] getCases() { return CASES; } + public static Object[][] getCases() { return CASES; } public static final Class[][] CASES = { { K1.class }, { K1M.class }, diff --git a/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticInvokeTest.java b/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticInvokeTest.java index 215ee3dd66a..ff7d12502b3 100644 --- a/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticInvokeTest.java +++ b/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticInvokeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, 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 @@ -27,7 +27,7 @@ * in interfaces and/or in inheritance * @bug 7184826 * @build helper.Mod helper.Declared DefaultStaticTestData - * @run testng DefaultStaticInvokeTest + * @run junit DefaultStaticInvokeTest * @author Yong Lu */ @@ -40,23 +40,19 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; -import org.testng.annotations.Test; - import static helper.Mod.*; import static helper.Declared.*; -import helper.Mod; +import static org.junit.jupiter.api.Assertions.*; +import helper.Mod; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class DefaultStaticInvokeTest { // getMethods(): Make sure getMethods returns the expected methods. - @Test(dataProvider = "testCasesAll", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource({"DefaultStaticTestData#testClasses", "DefaultStaticTestData#testInterfaces"}) public void testGetMethods(String testTarget, Object param) throws Exception { testMethods(ALL_METHODS, testTarget, param); @@ -64,8 +60,8 @@ public class DefaultStaticInvokeTest { // getDeclaredMethods(): Make sure getDeclaredMethods returns the expected methods. - @Test(dataProvider = "testCasesAll", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource({"DefaultStaticTestData#testClasses", "DefaultStaticTestData#testInterfaces"}) public void testGetDeclaredMethods(String testTarget, Object param) throws Exception { testMethods(DECLARED_ONLY, testTarget, param); @@ -73,8 +69,8 @@ public class DefaultStaticInvokeTest { // getMethod(): Make sure that getMethod finds all methods it should find. - @Test(dataProvider = "testCasesAll", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource({"DefaultStaticTestData#testClasses", "DefaultStaticTestData#testInterfaces"}) public void testGetMethod(String testTarget, Object param) throws Exception { @@ -91,8 +87,8 @@ public class DefaultStaticInvokeTest { // getMethod(): Make sure that getMethod does *not* find certain methods. - @Test(dataProvider = "testCasesAll", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource({"DefaultStaticTestData#testClasses", "DefaultStaticTestData#testInterfaces"}) public void testGetMethodSuperInterfaces(String testTarget, Object param) throws Exception { @@ -124,8 +120,8 @@ public class DefaultStaticInvokeTest { // Method.invoke(): Make sure Method.invoke returns the expected value. - @Test(dataProvider = "testCasesAll", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource({"DefaultStaticTestData#testClasses", "DefaultStaticTestData#testInterfaces"}) public void testMethodInvoke(String testTarget, Object param) throws Exception { Class typeUnderTest = Class.forName(testTarget); @@ -141,8 +137,8 @@ public class DefaultStaticInvokeTest { // MethodHandle.invoke(): Make sure MethodHandle.invoke returns the expected value. - @Test(dataProvider = "testCasesAll", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource({"DefaultStaticTestData#testClasses", "DefaultStaticTestData#testInterfaces"}) public void testMethodHandleInvoke(String testTarget, Object param) throws Throwable { Class typeUnderTest = Class.forName(testTarget); @@ -169,14 +165,14 @@ public class DefaultStaticInvokeTest { : (String) methodHandle.invoke(typeUnderTest.newInstance(), param); } - assertEquals(result, expectedReturn); + assertEquals(expectedReturn, result); } } // Lookup.findStatic / .findVirtual: Make sure IllegalAccessException is thrown as expected. - @Test(dataProvider = "testClasses", - dataProviderClass = DefaultStaticTestData.class) + @ParameterizedTest + @MethodSource("DefaultStaticTestData#testClasses") public void testIAE(String testTarget, Object param) throws ClassNotFoundException { @@ -189,14 +185,8 @@ public class DefaultStaticInvokeTest { if (mod != STATIC && typeUnderTest.isInterface()) { continue; } - Exception caught = null; - try { - getTestMH(typeUnderTest, mName, param, true); - } catch (Exception e) { - caught = e; - } - assertNotNull(caught); - assertEquals(caught.getClass(), IllegalAccessException.class); + assertThrowsExactly(IllegalAccessException.class, () -> + getTestMH(typeUnderTest, mName, param, true)); } } @@ -254,7 +244,7 @@ public class DefaultStaticInvokeTest { } } - assertEquals(myMethods.size(), expectedMethods.length); + assertEquals(expectedMethods.length, myMethods.size()); for (MethodDesc toTest : expectedMethods) { @@ -284,16 +274,15 @@ public class DefaultStaticInvokeTest { assertFalse(method.isDefault()); // Test invoke it - assertEquals(tryInvoke(method, null, param), expectedReturn); + assertEquals(expectedReturn, tryInvoke(method, null, param)); break; case DEFAULT: // if typeUnderTest is a class then instantiate and invoke if (!typeUnderTest.isInterface()) { - assertEquals(tryInvoke( + assertEquals(expectedReturn, tryInvoke( method, typeUnderTest, - param), - expectedReturn); + param)); } //assert candidate is default @@ -302,11 +291,10 @@ public class DefaultStaticInvokeTest { break; case REGULAR: // if typeUnderTest must be a class - assertEquals(tryInvoke( + assertEquals(expectedReturn, tryInvoke( method, typeUnderTest, - param), - expectedReturn); + param)); //assert candidate is neither default nor static assertFalse(Modifier.isStatic(method.getModifiers())); diff --git a/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticTestData.java b/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticTestData.java index 8049712569b..add991e3493 100644 --- a/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticTestData.java +++ b/test/jdk/java/lang/reflect/DefaultStaticTest/DefaultStaticTestData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, 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 @@ -27,12 +27,10 @@ * @author Yong Lu */ +import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.testng.annotations.DataProvider; -import org.testng.collections.Lists; - import static helper.Mod.*; import static helper.Declared.*; import helper.Mod; @@ -379,7 +377,6 @@ public class DefaultStaticTestData { * data is the name of the class under test Second data used in test as the * arguments used for the method call. */ - @DataProvider static Object[][] testClasses() { return new Object[][]{ {"TestClass1", null}, @@ -408,7 +405,6 @@ public class DefaultStaticTestData { * data is the name of the interface under test Second data used in test as * the arguments used for the method call. */ - @DataProvider static Object[][] testInterfaces() { return new Object[][]{ {"TestIF1", null}, @@ -438,12 +434,4 @@ public class DefaultStaticTestData { {"TestIF21", null}, }; } - - @DataProvider - static Object[][] testCasesAll() { - List result = Lists.newArrayList(); - result.addAll(Arrays.asList(testClasses())); - result.addAll(Arrays.asList(testInterfaces())); - return result.toArray(new Object[result.size()][]); - } } diff --git a/test/jdk/java/lang/reflect/Field/NegativeTest.java b/test/jdk/java/lang/reflect/Field/NegativeTest.java index fe1f2dd7480..186267f4458 100644 --- a/test/jdk/java/lang/reflect/Field/NegativeTest.java +++ b/test/jdk/java/lang/reflect/Field/NegativeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -21,20 +21,20 @@ * questions. */ -/** +/* * @test * @bug 8277451 * @summary Test exception thrown due to bad receiver and bad value on * Field with and without setAccessible(true) - * @run testng/othervm --enable-final-field-mutation=ALL-UNNAMED NegativeTest + * @run junit/othervm --enable-final-field-mutation=ALL-UNNAMED NegativeTest */ import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class NegativeTest { static class Fields { @@ -167,8 +167,7 @@ public class NegativeTest { } } - @DataProvider(name = "instanceFields") - private Object[][] instanceFields() { + private static Object[][] instanceFields() { return new Object[][]{ new Object[]{i_field}, new Object[]{c_field}, @@ -217,7 +216,8 @@ public class NegativeTest { * IllegalArgumentException is thrown if the receiver is of * a bad type. NullPointerException is thrown if the receiver is null. */ - @Test(dataProvider = "instanceFields") + @ParameterizedTest + @MethodSource("instanceFields") public void testReceiver(Field f) throws ReflectiveOperationException { f.get(INSTANCE); // good receiver @@ -231,15 +231,10 @@ public class NegativeTest { private void testBadReceiver(Field f) throws ReflectiveOperationException { assertFalse(Modifier.isStatic(f.getModifiers())); // instance field Object badObj = new NegativeTest(); - try { - f.get(badObj); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> f.get(badObj)); Class fType = f.getType(); if (fType.isPrimitive()) { - try { + assertThrows(IllegalArgumentException.class, () -> { switch (fType.descriptorString()) { case "B" -> f.getByte(badObj); case "C" -> f.getChar(badObj); @@ -250,10 +245,7 @@ public class NegativeTest { case "S" -> f.getShort(badObj); case "Z" -> f.getBoolean(badObj); } - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } + }); } } @@ -262,16 +254,11 @@ public class NegativeTest { */ private void testNullReceiver(Field f) throws ReflectiveOperationException { assertFalse(Modifier.isStatic(f.getModifiers())); // instance field - try { - f.get(null); - fail("expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } + assertThrows(NullPointerException.class, () -> f.get(null)); Class fType = f.getType(); if (fType.isPrimitive()) { - try { + assertThrows(NullPointerException.class, () -> { switch (fType.descriptorString()) { case "B" -> f.getByte(null); case "C" -> f.getChar(null); @@ -282,15 +269,11 @@ public class NegativeTest { case "S" -> f.getShort(null); case "Z" -> f.getBoolean(null); } - fail("expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } + }); } } - @DataProvider(name = "writeableFields") - private Object[][] writeableFields() { + private static Object[][] writeableFields() { Fields obj = new Fields(); return new Object[][]{ // instance fields with and without setAccessible(true) @@ -352,7 +335,8 @@ public class NegativeTest { * NullPointerException is thrown if the receiver of an instance field is null. * The receiver is checked */ - @Test(dataProvider = "writeableFields") + @ParameterizedTest + @MethodSource("writeableFields") public void testSetValue(Field f, Object obj, Object value) throws IllegalAccessException { f.set(obj, value); Class fType = f.getType(); @@ -369,25 +353,14 @@ public class NegativeTest { } // test null value only if it's primitive type - try { - f.set(obj, null); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> f.set(obj, null)); } Object badValue = new NegativeTest(); - try { - f.set(obj, badValue); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> f.set(obj, badValue)); } - @DataProvider(name = "readOnlyFinalFields") - private Object[][] readOnlyFinalFields() { + private static Object[][] readOnlyFinalFields() { Object obj = INSTANCE; return new Object[][]{ // instance final fields @@ -427,19 +400,15 @@ public class NegativeTest { * IllegalAccessException is thrown regardless of whether the value * is of a bad type or not. */ - @Test(dataProvider = "readOnlyFinalFields") + @ParameterizedTest + @MethodSource("readOnlyFinalFields") public void testSetValueOnFinalField(Field f, Object obj, Object value) { assertTrue(Modifier.isFinal(f.getModifiers())); - try { - f.set(obj, value); - fail("expected IllegalAccessException"); - } catch (IllegalAccessException e) { - // expected - } + assertThrows(IllegalAccessException.class, () -> f.set(obj, value)); Class fType = f.getType(); if (fType.isPrimitive()) { - try { + assertThrows(IllegalAccessException.class, () -> { switch (fType.descriptorString()) { case "B" -> f.setByte(obj, ((Byte)value).byteValue()); case "C" -> f.setChar(obj, ((Character)value).charValue()); @@ -450,33 +419,17 @@ public class NegativeTest { case "S" -> f.setShort(obj, ((Short)value).shortValue()); case "Z" -> f.setBoolean(obj, ((Boolean)value).booleanValue()); } - fail("expected IllegalAccessException"); - } catch (IllegalAccessException e) { - // expected - } + }); // test null value only if it's primitive type - try { - f.set(obj, null); - fail("expected IllegalAccessException"); - } catch (IllegalAccessException e) { - // expected - } + assertThrows(IllegalAccessException.class, () -> f.set(obj, null)); } Object badValue = new NegativeTest(); - try { - f.set(obj, badValue); - fail("expected IllegalAccessException"); - } catch (IllegalAccessException e) { - // expected - } + assertThrows(IllegalAccessException.class, () -> f.set(obj, badValue)); } - - - @DataProvider(name = "finalInstanceFields") - private Object[][] finalInstanceFields() { + private static Object[][] finalInstanceFields() { return new Object[][]{ new Object[]{fi_field, Integer.valueOf(10)}, new Object[]{fc_field, Character.valueOf('c')}, @@ -497,54 +450,27 @@ public class NegativeTest { * The receiver is checked before the access check is performed and * also before the value is checked. */ - @Test(dataProvider = "finalInstanceFields") + @ParameterizedTest + @MethodSource("finalInstanceFields") public void testReceiverOnFinalField(Field f, Object value) { assertTrue(Modifier.isFinal(f.getModifiers())); Object badReceiver = new NegativeTest(); // set the field with a bad receiver with a good value - try { - f.set(badReceiver, value); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } catch (IllegalAccessException e) { - throw new RuntimeException("Expected IllegalArgumentException but got: " + e.getMessage(), e); - } + assertThrows(IllegalArgumentException.class, () -> f.set(badReceiver, value)); // set the field with a bad receiver with a bad value Object badValue = new NegativeTest(); - try { - f.set(badReceiver, badValue); - fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // expected - } catch (IllegalAccessException e) { - throw new RuntimeException("Expected IllegalArgumentException but got: " + e.getMessage(), e); - } + assertThrows(IllegalArgumentException.class, () -> f.set(badReceiver, badValue)); // set the field with a null receiver with a good value - try { - f.set(null, value); - fail("expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } catch (IllegalAccessException e) { - throw new RuntimeException("Expected NullPointerException but got: " + e.getMessage(), e); - } + assertThrows(NullPointerException.class, () -> f.set(null, value)); // set the field with a null receiver with a bad value - try { - f.set(null, badValue); - fail("expected NullPointerException"); - } catch (NullPointerException e) { - // expected - } catch (IllegalAccessException e) { - throw new RuntimeException("Expected NullPointerException but got: " + e.getMessage(), e); - } + assertThrows(NullPointerException.class, () -> f.set(null, badValue)); Class fType = f.getType(); if (fType.isPrimitive()) { // test bad receiver - try { + assertThrows(IllegalArgumentException.class, () -> { switch (fType.descriptorString()) { case "B" -> f.setByte(badReceiver, ((Byte) value).byteValue()); case "C" -> f.setChar(badReceiver, ((Character) value).charValue()); @@ -555,12 +481,9 @@ public class NegativeTest { case "S" -> f.setShort(badReceiver, ((Short) value).shortValue()); case "Z" -> f.setBoolean(badReceiver, ((Boolean) value).booleanValue()); } - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - throw new RuntimeException("Expected IllegalArgumentException but got: " + e.getMessage(), e); - } + }); // test null receiver - try { + assertThrows(NullPointerException.class, () -> { switch (fType.descriptorString()) { case "B" -> f.setByte(null, ((Byte) value).byteValue()); case "C" -> f.setChar(null, ((Character) value).charValue()); @@ -571,11 +494,7 @@ public class NegativeTest { case "S" -> f.setShort(null, ((Short) value).shortValue()); case "Z" -> f.setBoolean(null, ((Boolean) value).booleanValue()); } - } catch (NullPointerException e) { - // expected - } catch (IllegalAccessException e) { - throw new RuntimeException("Expected NullPointerException but got: " + e.getMessage(), e); - } + }); } } } diff --git a/test/jdk/java/lang/reflect/Generics/ThreadSafety.java b/test/jdk/java/lang/reflect/Generics/ThreadSafety.java index 1aa1a4e9386..81ca2ae488a 100644 --- a/test/jdk/java/lang/reflect/Generics/ThreadSafety.java +++ b/test/jdk/java/lang/reflect/Generics/ThreadSafety.java @@ -21,17 +21,16 @@ * questions. */ -/** +/* * @test * @bug 8062771 8016236 * @summary Test publication of Class objects via a data race - * @run testng ThreadSafety + * @run junit ThreadSafety */ import java.io.File; import java.net.URL; import java.net.URLClassLoader; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.concurrent.BrokenBarrierException; @@ -43,8 +42,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.testng.Assert.*; -import org.testng.annotations.Test; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; /** * A test resulting from an attempt to repro this failure (in guice): diff --git a/test/jdk/java/lang/reflect/IllegalArgumentsTest.java b/test/jdk/java/lang/reflect/IllegalArgumentsTest.java index 7260c04c10a..58115523a3d 100644 --- a/test/jdk/java/lang/reflect/IllegalArgumentsTest.java +++ b/test/jdk/java/lang/reflect/IllegalArgumentsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -25,12 +25,14 @@ * @test * @bug 8277964 * @summary Test IllegalArgumentException be thrown when an argument is invalid - * @run testng/othervm/timeout=720 IllegalArgumentsTest + * @comment Avoid using framework utilities; this is effectively a runtime test + * sensitive to stack traces + * @run junit/othervm/timeout=720 IllegalArgumentsTest */ import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class IllegalArgumentsTest { static class T { diff --git a/test/jdk/java/lang/reflect/Method/MethodArityLimit.java b/test/jdk/java/lang/reflect/Method/MethodArityLimit.java index 536b3a5e317..05d4ef609ef 100644 --- a/test/jdk/java/lang/reflect/Method/MethodArityLimit.java +++ b/test/jdk/java/lang/reflect/Method/MethodArityLimit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -24,18 +24,16 @@ /* * @test * @bug 8271820 - * @run testng/othervm MethodArityLimit + * @run junit/othervm MethodArityLimit * @summary Method exceeds the method handle arity limit (255). */ -import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.reflect.Method; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class MethodArityLimit { @Test @@ -74,12 +72,10 @@ public class MethodArityLimit { 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127); - assertEquals(resultViaMethod, 127); + assertEquals(127, resultViaMethod); - try { - MethodHandle mh = MethodHandles.lookup().unreflect(m); - fail("should fail in creating the method handle"); - } catch (IllegalArgumentException e) {} + var lookup = MethodHandles.lookup(); + assertThrows(IllegalArgumentException.class, () -> lookup.unreflect(m)); } public static long f(long a0, long a1, long a2, long a3, long a4, long a5, diff --git a/test/jdk/java/lang/reflect/MethodHandleAccessorsTest.java b/test/jdk/java/lang/reflect/MethodHandleAccessorsTest.java index b7e6b52b5dc..af72d8dec58 100644 --- a/test/jdk/java/lang/reflect/MethodHandleAccessorsTest.java +++ b/test/jdk/java/lang/reflect/MethodHandleAccessorsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -26,7 +26,7 @@ * @bug 8271820 8300924 * @modules java.base/jdk.internal.reflect * @summary Test compliance of ConstructorAccessor, FieldAccessor, MethodAccessor implementations - * @run testng/othervm --add-exports java.base/jdk.internal.reflect=ALL-UNNAMED -XX:-ShowCodeDetailsInExceptionMessages MethodHandleAccessorsTest + * @run junit/othervm -XX:-ShowCodeDetailsInExceptionMessages MethodHandleAccessorsTest */ import jdk.internal.reflect.ConstructorAccessor; @@ -44,8 +44,11 @@ import java.util.Objects; import java.util.function.IntUnaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertThrows; public class MethodHandleAccessorsTest { public static void public_static_V() {} @@ -446,9 +449,7 @@ public class MethodHandleAccessorsTest { new InvocationTargetException(new IllegalArgumentException("IAE")) }; - - @DataProvider(name = "testNoArgMethods") - private Object[][] testNoArgMethods() { + private static Object[][] testNoArgMethods() { MethodHandleAccessorsTest inst = new MethodHandleAccessorsTest(); Object[] emptyArgs = new Object[]{}; return new Object[][] { @@ -468,8 +469,7 @@ public class MethodHandleAccessorsTest { }; } - @DataProvider(name = "testOneArgMethods") - private Object[][] testOneArgMethods() { + private static Object[][] testOneArgMethods() { MethodHandleAccessorsTest inst = new MethodHandleAccessorsTest(); Object wrongInst = new Object(); return new Object[][]{ @@ -497,8 +497,7 @@ public class MethodHandleAccessorsTest { }; } - @DataProvider(name = "testMultiArgMethods") - private Object[][] testMultiArgMethods() { + private static Object[][] testMultiArgMethods() { MethodHandleAccessorsTest inst = new MethodHandleAccessorsTest(); Class[] params_L3 = new Class[] { Object.class, Object.class, Object.class}; Class[] params_L4 = new Class[] { Object.class, Object.class, Object.class, Object.class}; @@ -515,8 +514,7 @@ public class MethodHandleAccessorsTest { }; } - @DataProvider(name = "testMethodsWithVarargs") - private Object[][] testMethodsWithVarargs() { + private static Object[][] testMethodsWithVarargs() { Class[] paramTypes = new Class[] { int[].class }; Class[] I_paramTypes = new Class[] { int.class, int[].class }; Class[] L_paramTypes = new Class[] { String.class, String[].class }; @@ -533,32 +531,35 @@ public class MethodHandleAccessorsTest { }; } - @Test(dataProvider = "testNoArgMethods") + @ParameterizedTest + @MethodSource("testNoArgMethods") public void testNoArgMethod(String methodname, Object target, Object[] args, Object expectedReturn, Throwable[] expectedExpections) throws Exception { doTest(MethodHandleAccessorsTest.class.getDeclaredMethod(methodname), target, args, expectedReturn, expectedExpections); } - @Test(dataProvider = "testOneArgMethods") + @ParameterizedTest + @MethodSource("testOneArgMethods") public void testOneArgMethod(String methodname, Class paramType, Object target, Object[] args, Object expectedReturn, Throwable[] expectedExpections) throws Exception { doTest(MethodHandleAccessorsTest.class.getDeclaredMethod(methodname, paramType), target, args, expectedReturn, expectedExpections); } - @Test(dataProvider = "testMultiArgMethods") + @ParameterizedTest + @MethodSource("testMultiArgMethods") public void testMultiArgMethod(String methodname, Class[] paramTypes, Object target, Object[] args, Object expectedReturn, Throwable[] expectedExpections) throws Exception { doTest(MethodHandleAccessorsTest.class.getDeclaredMethod(methodname, paramTypes), target, args, expectedReturn, expectedExpections); } - @Test(dataProvider = "testMethodsWithVarargs") + @ParameterizedTest + @MethodSource("testMethodsWithVarargs") public void testMethodsWithVarargs(String methodname, Class[] paramTypes, Object target, Object[] args, Object expectedReturn, Throwable[] expectedExpections) throws Exception { doTest(MethodHandleAccessorsTest.class.getDeclaredMethod(methodname, paramTypes), target, args, expectedReturn, expectedExpections); } - @DataProvider(name = "testConstructors") - private Object[][] testConstructors() { + private static Object[][] testConstructors() { return new Object[][]{ new Object[]{null, new Object[]{}, new Public(), noException}, new Object[]{null, null, new Public(), noException}, @@ -584,13 +585,13 @@ public class MethodHandleAccessorsTest { }; } - @Test(dataProvider = "testConstructors") + @ParameterizedTest + @MethodSource("testConstructors") public void testPublicConstructors(Class[] paramTypes, Object[] args, Object expectedReturn, Throwable[] expectedExpections) throws Exception { doTest(Public.class.getDeclaredConstructor(paramTypes), args, expectedReturn, expectedExpections); } - @DataProvider(name = "testMultiArgConstructors") - private Object[][] testMultiArgConstructors() { + private static Object[][] testMultiArgConstructors() { Class[] params_L3 = new Class[] { Object.class, Object.class, Object.class}; Class[] params_L4 = new Class[] { Object.class, Object.class, Object.class, Object.class}; Object o = "arg"; @@ -602,7 +603,8 @@ public class MethodHandleAccessorsTest { }; } - @Test(dataProvider = "testMultiArgConstructors") + @ParameterizedTest + @MethodSource("testMultiArgConstructors") public void testMultiArgConstructors(Class[] paramTypes, Object[] args, Object expectedReturn, Throwable[] expectedExpections) throws Exception { doTest(Public.class.getDeclaredConstructor(paramTypes), args, expectedReturn, expectedExpections); } @@ -616,8 +618,7 @@ public class MethodHandleAccessorsTest { doTest(Abstract.class.getDeclaredConstructor(), null, null, new InstantiationException()); } - @DataProvider(name = "throwException") - private Object[][] throwException() { + private static Object[][] throwException() { return new Object[][]{ new Object[] {new NullPointerException("NPE"), wrapped_npe}, new Object[] {new IllegalArgumentException("IAE"), wrapped_iae}, @@ -629,7 +630,8 @@ public class MethodHandleAccessorsTest { * Test Method::invoke and Constructor::newInstance to wrap NPE/CCE/IAE * thrown by the member */ - @Test(dataProvider = "throwException") + @ParameterizedTest + @MethodSource("throwException") public void testInvocationTargetException(Throwable ex, Throwable[] expectedExpections) throws Exception { Object[] args = new Object[] { ex }; // test static method @@ -646,8 +648,7 @@ public class MethodHandleAccessorsTest { doTest(applyAsIntMethod, intUnaryOp, new Object[]{12}, 12); } - @DataProvider(name = "readAccess") - private Object[][] readAccess() { + private static Object[][] readAccess() { String wrongInst = new String(); return new Object[][]{ new Object[]{"i", new Public(100), 100, noException}, @@ -657,8 +658,7 @@ public class MethodHandleAccessorsTest { new Object[]{"b", wrongInst, 0, cannot_get_field}, }; } - @DataProvider(name = "writeAccess") - private Object[][] writeAccess() { + private static Object[][] writeAccess() { Object o = new Object(); byte b = 1; return new Object[][]{ @@ -673,14 +673,16 @@ public class MethodHandleAccessorsTest { }; } - @Test(dataProvider = "readAccess") + @ParameterizedTest + @MethodSource("readAccess") public void testFieldReadAccess(String name, Object target, Object expectedValue, Throwable[] expectedExpections) throws Exception { Field f = Public.class.getDeclaredField(name); f.setAccessible(true); doTest(f, target, expectedValue, expectedExpections); } - @Test(dataProvider = "writeAccess") + @ParameterizedTest + @MethodSource("writeAccess") public void testFieldWriteAccess(String name, Object target, Object oldValue, Object newValue, Throwable[] expectedExpections) throws Exception { Field f = Public.class.getDeclaredField(name); f.setAccessible(true); @@ -693,8 +695,6 @@ public class MethodHandleAccessorsTest { Field f = Public.class.getDeclaredField("STATIC_FINAL"); doTest(f, new Public(), 1, noException); - try { - f.setInt(null, 100); - } catch (IllegalAccessException e) { } + assertThrows(IllegalAccessException.class, () -> f.setInt(null, 100)); } } diff --git a/test/jdk/java/lang/reflect/Proxy/DefaultMethods.java b/test/jdk/java/lang/reflect/Proxy/DefaultMethods.java index 48bb67f405e..e494e623119 100644 --- a/test/jdk/java/lang/reflect/Proxy/DefaultMethods.java +++ b/test/jdk/java/lang/reflect/Proxy/DefaultMethods.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -23,19 +23,19 @@ import java.io.IOException; import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Arrays; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -/** +/* * @test * @bug 8159746 - * @run testng DefaultMethods + * @run junit DefaultMethods * @summary Basic tests for Proxy::invokeSuper default method */ @@ -96,15 +96,11 @@ public class DefaultMethods { } private static Method findDefaultMethod(Class refc, Method m) { - try { - assertTrue(refc.isInterface()); + assertTrue(refc.isInterface()); - Method method = refc.getMethod(m.getName(), m.getParameterTypes()); - assertTrue(method.isDefault()); - return method; - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } + Method method = assertDoesNotThrow(() -> refc.getMethod(m.getName(), m.getParameterTypes())); + assertTrue(method.isDefault()); + return method; } @Test @@ -115,12 +111,11 @@ public class DefaultMethods { return InvocationHandler.invokeDefault(o, findDefaultMethod(I2.class, method), params); }); I1 i1 = (I1) proxy; - assertEquals(i1.m(), 20); + assertEquals(20, i1.m()); } // a default method is declared in one of the proxy interfaces - @DataProvider(name = "defaultMethods") - private Object[][] defaultMethods() { + private static Object[][] defaultMethods() { return new Object[][]{ new Object[]{new Class[]{I1.class, I2.class}, true, 10}, new Object[]{new Class[]{I1.class, I3.class}, true, 10}, @@ -133,13 +128,14 @@ public class DefaultMethods { }; } - @Test(dataProvider = "defaultMethods") + @ParameterizedTest + @MethodSource("defaultMethods") public void testDefaultMethod(Class[] intfs, boolean isDefault, int expected) throws Throwable { InvocationHandler ih = (proxy, method, params) -> { System.out.format("invoking %s with parameters: %s%n", method, Arrays.toString(params)); switch (method.getName()) { case "m": - assertTrue(method.isDefault() == isDefault); + assertEquals(isDefault, method.isDefault()); assertTrue(Arrays.stream(proxy.getClass().getInterfaces()) .anyMatch(intf -> method.getDeclaringClass() == intf), Arrays.toString(proxy.getClass().getInterfaces())); @@ -156,13 +152,12 @@ public class DefaultMethods { Object proxy = Proxy.newProxyInstance(DefaultMethods.class.getClassLoader(), intfs, ih); Method m = proxy.getClass().getMethod("m"); int result = (int)m.invoke(proxy); - assertEquals(result, expected); + assertEquals(expected, result); } // a default method may be declared in a proxy interface or // inherited from a superinterface of a proxy interface - @DataProvider(name = "supers") - private Object[][] supers() { + private static Object[][] supers() { return new Object[][]{ // invoke "m" implemented in the first proxy interface // same as the method passed to InvocationHandler::invoke @@ -188,7 +183,8 @@ public class DefaultMethods { }; } - @Test(dataProvider = "supers") + @ParameterizedTest + @MethodSource("supers") public void testSuper(Class[] intfs, Class proxyInterface, int expected) throws Throwable { final InvocationHandler ih = (proxy, method, params) -> { switch (method.getName()) { @@ -203,21 +199,21 @@ public class DefaultMethods { Object proxy = Proxy.newProxyInstance(loader, intfs, ih); if (proxyInterface == I1.class) { I1 i1 = (I1) proxy; - assertEquals(i1.m(), expected); + assertEquals(expected, i1.m()); } else if (proxyInterface == I2.class) { I2 i2 = (I2) proxy; - assertEquals(i2.m(), expected); + assertEquals(expected, i2.m()); } else if (proxyInterface == I3.class) { I3 i3 = (I3) proxy; - assertEquals(i3.m(), expected); + assertEquals(expected, i3.m()); } else if (proxyInterface == I4.class) { I4 i4 = (I4) proxy; - assertEquals(i4.m(), expected); + assertEquals(expected, i4.m()); } else { throw new UnsupportedOperationException(proxyInterface.toString()); } // invoke via InvocationHandler.invokeDefaultMethod directly - assertEquals(InvocationHandler.invokeDefault(proxy, proxyInterface.getMethod("m")), expected); + assertEquals(expected, InvocationHandler.invokeDefault(proxy, proxyInterface.getMethod("m"))); } // invoke I12 default methods with parameters and var args @@ -236,12 +232,12 @@ public class DefaultMethods { }; ClassLoader loader = DefaultMethods.class.getClassLoader(); I12 i12 = (I12) Proxy.newProxyInstance(loader, new Class[] { I12.class }, ih); - assertEquals(i12.sum(1, 2), 3); - assertEquals(i12.concat(1, 2, 3, 4), new Object[]{1, 2, 3, 4}); + assertEquals(3, i12.sum(1, 2)); + assertArrayEquals(new Object[]{1, 2, 3, 4}, i12.concat(1, 2, 3, 4)); Method m = I12.class.getMethod("concat", Object.class, Object[].class); assertTrue(m.isDefault()); - assertEquals(InvocationHandler.invokeDefault(i12, m, 100, new Object[] {"foo", true, "bar"}), - new Object[] {100, "foo", true, "bar"}); + assertArrayEquals(new Object[] {100, "foo", true, "bar"}, (Object[]) + InvocationHandler.invokeDefault(i12, m, 100, new Object[] {"foo", true, "bar"})); } // test a no-arg default method with and without arguments passed in the invocation @@ -250,13 +246,13 @@ public class DefaultMethods { ClassLoader loader = DefaultMethods.class.getClassLoader(); Object proxy = Proxy.newProxyInstance(loader, new Class[]{I4.class}, HANDLER); Method m1 = I4.class.getMethod("m"); - assertTrue(m1.getDeclaringClass() == I4.class); + assertSame(I4.class, m1.getDeclaringClass()); assertTrue(m1.isDefault()); InvocationHandler.invokeDefault(proxy, m1); InvocationHandler.invokeDefault(proxy, m1, new Object[0]); Method m2 = I4.class.getMethod("mix", int.class, String.class); - assertTrue(m1.getDeclaringClass() == I4.class); + assertSame(I4.class, m1.getDeclaringClass()); assertTrue(m1.isDefault()); InvocationHandler.invokeDefault(proxy, m2, Integer.valueOf(100), "foo"); } @@ -267,38 +263,37 @@ public class DefaultMethods { I3 proxy = (I3)Proxy.newProxyInstance(loader, new Class[]{I3.class}, HANDLER); Method m = I3.class.getMethod("m3", String[].class); assertTrue(m.isVarArgs() && m.isDefault()); - assertEquals(proxy.m3("a", "b", "cde"), 5); - assertEquals(InvocationHandler.invokeDefault(proxy, m, (Object)new String[] { "a", "bc" }), 3); + assertEquals(5, proxy.m3("a", "b", "cde")); + assertEquals(3, InvocationHandler.invokeDefault(proxy, m, (Object)new String[] { "a", "bc" })); } /* * Invoke I12::m which is an abstract method */ - @Test(expectedExceptions = {IllegalArgumentException.class}) + @Test public void invokeAbstractMethod() throws Exception { ClassLoader loader = DefaultMethods.class.getClassLoader(); I12 proxy = (I12) Proxy.newProxyInstance(loader, new Class[]{I12.class}, HANDLER); Method method = I12.class.getMethod("m"); - assertTrue(method.getDeclaringClass() == I12.class); + assertSame(I12.class, method.getDeclaringClass()); assertFalse(method.isDefault()); - proxy.m(); + assertThrows(IllegalArgumentException.class, () -> proxy.m()); } /* * Invoke a non proxy (default) method with parameters */ - @Test(expectedExceptions = {IllegalArgumentException.class}) + @Test public void invokeNonProxyMethod() throws Throwable { ClassLoader loader = DefaultMethods.class.getClassLoader(); I3 proxy = (I3) Proxy.newProxyInstance(loader, new Class[]{I3.class}, HANDLER); Method m = I4.class.getMethod("mix", int.class, String.class); assertTrue(m.isDefault()); - InvocationHandler.invokeDefault(proxy, m); + assertThrows(IllegalArgumentException.class, () -> InvocationHandler.invokeDefault(proxy, m)); } // negative cases - @DataProvider(name = "negativeCases") - private Object[][] negativeCases() { + private static Object[][] negativeCases() { return new Object[][]{ // I4::m overrides I1::m and I2::m new Object[] { new Class[]{I4.class}, I1.class, "m" }, @@ -315,25 +310,20 @@ public class DefaultMethods { }; } - @Test(dataProvider = "negativeCases", expectedExceptions = {IllegalArgumentException.class}) + @ParameterizedTest + @MethodSource("negativeCases") public void testNegativeCase(Class[] interfaces, Class defc, String name) throws Throwable { ClassLoader loader = DefaultMethods.class.getClassLoader(); Object proxy = Proxy.newProxyInstance(loader, interfaces, HANDLER); - try { - Method method = defc.getDeclaredMethod(name); - InvocationHandler.invokeDefault(proxy, method); - } catch (Throwable e) { - System.out.format("%s method %s::%s exception thrown: %s%n", - Arrays.toString(interfaces), defc.getName(), name, e.getMessage()); - throw e; - } + Method method = defc.getDeclaredMethod(name); + assertThrows(IllegalArgumentException.class, () -> + InvocationHandler.invokeDefault(proxy, method)); } - @DataProvider(name = "illegalArguments") - private Object[][] illegalArguments() { - return new Object[][] { - new Object[] { new Object[0]}, + private static Object[] illegalArguments() { + return new Object[] { + new Object[] { null }, new Object[] { new Object[] { 100 }}, new Object[] { new Object[] { 100, "foo", 100 }}, new Object[] { new Object[] { 100L, "foo" }}, @@ -342,21 +332,18 @@ public class DefaultMethods { }; } - @Test(dataProvider = "illegalArguments", expectedExceptions = {IllegalArgumentException.class}) + @ParameterizedTest + @MethodSource("illegalArguments") public void testIllegalArgument(Object[] args) throws Throwable { ClassLoader loader = DefaultMethods.class.getClassLoader(); I4 proxy = (I4)Proxy.newProxyInstance(loader, new Class[]{I4.class}, HANDLER); Method m = I4.class.getMethod("mix", int.class, String.class); assertTrue(m.isDefault()); - if (args.length == 0) { - // substitute empty args with null since @DataProvider doesn't allow null array - args = null; - } - InvocationHandler.invokeDefault(proxy, m, args); + assertThrows(IllegalArgumentException.class, () -> + InvocationHandler.invokeDefault(proxy, m, args)); } - @DataProvider(name = "throwables") - private Object[][] throwables() { + private static Object[][] throwables() { return new Object[][] { new Object[] { new IOException() }, new Object[] { new IllegalArgumentException() }, @@ -367,16 +354,14 @@ public class DefaultMethods { }; } - @Test(dataProvider = "throwables") + @ParameterizedTest + @MethodSource("throwables") public void testInvocationException(Throwable exception) throws Throwable { ClassLoader loader = DefaultMethods.class.getClassLoader(); IX proxy = (IX)Proxy.newProxyInstance(loader, new Class[]{IX.class}, HANDLER); Method m = IX.class.getMethod("doThrow", Throwable.class); - try { - InvocationHandler.invokeDefault(proxy, m, exception); - } catch (Throwable e) { - assertEquals(e, exception); - } + assertSame(exception, assertThrows(Throwable.class, () -> + InvocationHandler.invokeDefault(proxy, m, exception))); } private static final InvocationHandler HANDLER = (proxy, method, params) -> { diff --git a/test/jdk/java/lang/reflect/Proxy/HiddenProxyInterface.java b/test/jdk/java/lang/reflect/Proxy/HiddenProxyInterface.java index e52d3671ab6..fbaf9db6325 100644 --- a/test/jdk/java/lang/reflect/Proxy/HiddenProxyInterface.java +++ b/test/jdk/java/lang/reflect/Proxy/HiddenProxyInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -24,7 +24,7 @@ /* * @test * @bug 8250219 - * @run testng HiddenProxyInterface + * @run junit HiddenProxyInterface */ import java.lang.invoke.MethodHandles; @@ -35,8 +35,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class HiddenProxyInterface { private static final Path CLASSES_DIR = Paths.get(System.getProperty("test.classes")); @@ -45,18 +45,19 @@ public class HiddenProxyInterface { void m(); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void testHiddenInterface() throws Exception { Path classFile = CLASSES_DIR.resolve("HiddenProxyInterface$Intf.class"); byte[] bytes = Files.readAllBytes(classFile); Class hiddenIntf = MethodHandles.lookup().defineHiddenClass(bytes, false).lookupClass(); - Proxy.newProxyInstance(HiddenProxyInterface.class.getClassLoader(), + assertThrows(IllegalArgumentException.class, () -> Proxy.newProxyInstance( + HiddenProxyInterface.class.getClassLoader(), new Class[]{ hiddenIntf }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return null; } - }); + })); } } diff --git a/test/jdk/java/lang/reflect/Proxy/LazyInitializationTest.java b/test/jdk/java/lang/reflect/Proxy/LazyInitializationTest.java index cb65904cfdb..2a223873275 100644 --- a/test/jdk/java/lang/reflect/Proxy/LazyInitializationTest.java +++ b/test/jdk/java/lang/reflect/Proxy/LazyInitializationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,14 +23,15 @@ import java.lang.reflect.Proxy; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; /* * @test * @bug 8285401 * @summary Avoid initialization of parameter types in proxy construction - * @run testng LazyInitializationTest + * @run junit LazyInitializationTest */ public final class LazyInitializationTest { private static volatile boolean initialized = false; @@ -50,9 +51,9 @@ public final class LazyInitializationTest { Intf value = (Intf) Proxy.newProxyInstance(LazyInitializationTest.class.getClassLoader(), new Class[]{ Intf.class }, (proxy, method, args) -> null); - Assert.assertFalse(initialized, "parameter type initialized unnecessarily"); + assertFalse(initialized, "parameter type initialized unnecessarily"); value.m(new Parameter()); - Assert.assertTrue(initialized, "parameter type initialized after instantiation"); + assertTrue(initialized, "parameter type initialized after instantiation"); } } diff --git a/test/jdk/java/lang/reflect/Proxy/ProxyClassAccessTest.java b/test/jdk/java/lang/reflect/Proxy/ProxyClassAccessTest.java index 50fbd150ec7..265f9ce7104 100644 --- a/test/jdk/java/lang/reflect/Proxy/ProxyClassAccessTest.java +++ b/test/jdk/java/lang/reflect/Proxy/ProxyClassAccessTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -32,17 +32,17 @@ import java.util.List; import jdk.test.lib.compiler.CompilerUtils; import static jdk.test.lib.process.ProcessTools.executeTestJava; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -/** +/* * @test * @library /test/lib * @modules jdk.compiler * @build ProxyClassAccessTest q.NP * jdk.test.lib.compiler.CompilerUtils - * @run testng ProxyClassAccessTest + * @run junit ProxyClassAccessTest * @summary Driver for testing proxy class doesn't have access to * types referenced by proxy interfaces */ @@ -61,8 +61,8 @@ public class ProxyClassAccessTest { /** * Compiles all modules used by the test */ - @BeforeTest - public void compileAll() throws Exception { + @BeforeAll + public static void compileAll() throws Exception { for (String mn : modules) { Path msrc = SRC_DIR.resolve(mn); assertTrue(CompilerUtils.compile(msrc, MODS_DIR, "--module-source-path", SRC_DIR.toString())); @@ -80,7 +80,7 @@ public class ProxyClassAccessTest { .errorTo(System.out) .getExitValue(); - assertTrue(exitValue == 0); + assertEquals(0, exitValue); } /** @@ -105,16 +105,10 @@ public class ProxyClassAccessTest { } private void checkIAE(ClassLoader loader, Class[] interfaces) throws Throwable { - try { - Proxy.getProxyClass(loader, interfaces); - throw new RuntimeException("Expected IllegalArgumentException thrown"); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> Proxy.getProxyClass(loader, interfaces)); - try { - Proxy.newProxyInstance(loader, interfaces, - (proxy, m, params) -> { throw new RuntimeException(m.toString()); }); - throw new RuntimeException("Expected IllegalArgumentException thrown"); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> Proxy.newProxyInstance(loader, interfaces, + (proxy, m, params) -> { throw new RuntimeException(m.toString()); })); } } diff --git a/test/jdk/java/lang/reflect/Proxy/ProxyLayerTest.java b/test/jdk/java/lang/reflect/Proxy/ProxyLayerTest.java index 85ebf922a20..d2708e18c0e 100644 --- a/test/jdk/java/lang/reflect/Proxy/ProxyLayerTest.java +++ b/test/jdk/java/lang/reflect/Proxy/ProxyLayerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -32,17 +32,18 @@ import java.util.Arrays; import jdk.test.lib.compiler.CompilerUtils; import static jdk.test.lib.process.ProcessTools.executeTestJava; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; -/** +/* * @test * @library /test/lib * @modules jdk.compiler * @build ProxyTest jdk.test.lib.process.ProcessTools * jdk.test.lib.compiler.CompilerUtils - * @run testng ProxyLayerTest + * @run junit ProxyLayerTest * @summary Test proxies to implement interfaces in a layer */ @@ -62,8 +63,8 @@ public class ProxyLayerTest { /** * Compiles all modules used by the test */ - @BeforeTest - public void compileAll() throws Exception { + @BeforeAll + public static void compileAll() throws Exception { for (String mn : modules) { Path msrc = SRC_DIR.resolve(mn); assertTrue(CompilerUtils.compile(msrc, MODS_DIR, "--module-source-path", SRC_DIR.toString())); @@ -102,7 +103,7 @@ public class ProxyLayerTest { assertTrue(proxyClass.getModule().isNamed()); assertTrue(pkg.isSealed()); assertTrue(proxyClass.getModule().isExported(pkg.getName())); - assertEquals(proxyClass.getModule().getLayer(), null); + assertNull(proxyClass.getModule().getLayer()); } /** @@ -134,7 +135,7 @@ public class ProxyLayerTest { assertTrue(proxyClass.getModule().isNamed()); assertTrue(pkg.isSealed()); assertFalse(proxyClass.getModule().isExported(pkg.getName())); - assertEquals(proxyClass.getModule().getLayer(), null); + assertNull(proxyClass.getModule().getLayer()); } /** @@ -164,15 +165,8 @@ public class ProxyLayerTest { } private void checkIAE(ClassLoader loader, Class[] interfaces) { - try { - Proxy.getProxyClass(loader, interfaces); - throw new RuntimeException("Expected IllegalArgumentException thrown"); - } catch (IllegalArgumentException e) {} - - try { - Proxy.newProxyInstance(loader, interfaces, handler); - throw new RuntimeException("Expected IllegalArgumentException thrown"); - } catch (IllegalArgumentException e) {} + assertThrows(IllegalArgumentException.class, () -> Proxy.getProxyClass(loader, interfaces)); + assertThrows(IllegalArgumentException.class, () -> Proxy.newProxyInstance(loader, interfaces, handler)); } private final static InvocationHandler handler = diff --git a/test/jdk/java/lang/reflect/Proxy/ProxyTest.java b/test/jdk/java/lang/reflect/Proxy/ProxyTest.java index 811471585a9..1da6a10260a 100644 --- a/test/jdk/java/lang/reflect/Proxy/ProxyTest.java +++ b/test/jdk/java/lang/reflect/Proxy/ProxyTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -29,17 +29,17 @@ import java.util.List; import jdk.test.lib.compiler.CompilerUtils; import static jdk.test.lib.process.ProcessTools.executeTestJava; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -/** +/* * @test * @library /test/lib * @modules jdk.compiler * @build ProxyTest q.U * jdk.test.lib.compiler.CompilerUtils - * @run testng ProxyTest + * @run junit ProxyTest * @summary Driver for testing proxies accessing interfaces in named modules */ @@ -59,8 +59,8 @@ public class ProxyTest { /** * Compiles all modules used by the test */ - @BeforeTest - public void compileAll() throws Exception { + @BeforeAll + public static void compileAll() throws Exception { for (String mn : modules) { Path msrc = SRC_DIR.resolve(mn); assertTrue(CompilerUtils.compile(msrc, MODS_DIR, "--module-source-path", SRC_DIR.toString())); @@ -79,7 +79,7 @@ public class ProxyTest { .errorTo(System.out) .getExitValue(); - assertTrue(exitValue == 0); + assertEquals(0, exitValue); } /** @@ -95,6 +95,6 @@ public class ProxyTest { .errorTo(System.out) .getExitValue(); - assertTrue(exitValue == 0); + assertEquals(0, exitValue); } } diff --git a/test/jdk/java/lang/reflect/Proxy/SealedInterfaceTest.java b/test/jdk/java/lang/reflect/Proxy/SealedInterfaceTest.java index 1337248f817..822c5d83319 100644 --- a/test/jdk/java/lang/reflect/Proxy/SealedInterfaceTest.java +++ b/test/jdk/java/lang/reflect/Proxy/SealedInterfaceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -24,15 +24,15 @@ /* * @test * @bug 8269351 - * @run testng SealedInterfaceTest + * @run junit SealedInterfaceTest */ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; public class SealedInterfaceTest { sealed interface Intf permits NonSealedInterface { @@ -43,16 +43,17 @@ public class SealedInterfaceTest { void m2(); } - @Test(expectedExceptions = { IllegalArgumentException.class }) + @Test public void testSealedInterface() { - Proxy.newProxyInstance(SealedInterfaceTest.class.getClassLoader(), + assertThrows(IllegalArgumentException.class, () -> Proxy.newProxyInstance( + SealedInterfaceTest.class.getClassLoader(), new Class[]{ Intf.class }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return null; } - }); + })); } @Test diff --git a/test/jdk/java/lang/reflect/Proxy/TestVarArgs.java b/test/jdk/java/lang/reflect/Proxy/TestVarArgs.java index a472f75d4b7..b16831c7867 100644 --- a/test/jdk/java/lang/reflect/Proxy/TestVarArgs.java +++ b/test/jdk/java/lang/reflect/Proxy/TestVarArgs.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -21,10 +21,10 @@ * questions. */ -/** +/* * @test * @bug 8022795 - * @run testng TestVarArgs + * @run junit TestVarArgs * @summary Verify if a method defined in a proxy interface has ACC_VARARGS set */ @@ -34,11 +34,10 @@ import java.lang.invoke.MethodType; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.util.Arrays; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class TestVarArgs { interface I { @@ -48,8 +47,7 @@ public class TestVarArgs { Object call(Object[] values); } - @DataProvider(name = "proxyInterfaces") - public Object[][] proxyInterfaces() { + public static Object[][] proxyInterfaces() { return new Object[][] { { new Class[] { I.class }, true}, { new Class[] { J.class }, false}, @@ -58,11 +56,12 @@ public class TestVarArgs { }; } - @Test(dataProvider = "proxyInterfaces") + @ParameterizedTest + @MethodSource("proxyInterfaces") public void testMethod(Class[] proxyInterfaces, boolean isVarArgs) throws Throwable { // check if the first proxy interface with the method named "call" declares var result Method m = proxyInterfaces[0].getMethod("call", Object[].class); - assertTrue(m.isVarArgs() == isVarArgs); + assertEquals(isVarArgs, m.isVarArgs()); // the method in the generated proxy class should match the method // declared in the proxy interface @@ -71,19 +70,19 @@ public class TestVarArgs { Class proxyClass = proxy.getClass(); assertTrue(Proxy.isProxyClass(proxyClass)); Method method = proxyClass.getMethod("call", Object[].class); - assertTrue(method.isVarArgs() == isVarArgs); + assertEquals(isVarArgs, method.isVarArgs()); - Object params = new Object[] { "foo", "bar", "goo" }; - Object result; + Object[] params = new Object[] { "foo", "bar", "goo" }; + Object[] result; // test reflection - result = method.invoke(proxy, params); - assertEquals(result, params); + result = (Object[]) method.invoke(proxy, new Object[] {params}); + assertEquals(params, result); // test method handle MethodHandle mh = MethodHandles.lookup().findVirtual(proxyClass, "call", MethodType.methodType(Object.class, Object[].class)); - assertTrue(mh.isVarargsCollector() == isVarArgs); + assertEquals(isVarArgs, mh.isVarargsCollector()); MethodHandle mhVarArity = mh; MethodHandle mhFixedArity = mh; if (isVarArgs) { @@ -91,18 +90,18 @@ public class TestVarArgs { } else { mhVarArity = mh.asVarargsCollector(Object[].class); } - result = mhVarArity.invoke(proxy, "foo", "bar", "goo"); - assertEquals(result, params); + result = (Object[]) mhVarArity.invoke(proxy, "foo", "bar", "goo"); + assertArrayEquals(params, result); - result = mhFixedArity.invoke(proxy, params); - assertEquals(result, params); + result = (Object[]) mhFixedArity.invoke(proxy, params); + assertArrayEquals(params, result); if (!isVarArgs) { MethodType mt = MethodType.methodType(Object.class, Object.class, String.class, String.class, String.class); mh = mh.asVarargsCollector(Object[].class).asType(mt); } - result = mh.invoke(proxy, "foo", "bar", "goo"); - assertEquals(result, params); + result = (Object[]) mh.invoke(proxy, "foo", "bar", "goo"); + assertArrayEquals(params, result); } private static final InvocationHandler IH = new InvocationHandler() { diff --git a/test/jdk/java/lang/reflect/Proxy/nonPublicProxy/DefaultMethodProxy.java b/test/jdk/java/lang/reflect/Proxy/nonPublicProxy/DefaultMethodProxy.java index daf6f656aab..a304063638c 100644 --- a/test/jdk/java/lang/reflect/Proxy/nonPublicProxy/DefaultMethodProxy.java +++ b/test/jdk/java/lang/reflect/Proxy/nonPublicProxy/DefaultMethodProxy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -25,16 +25,17 @@ import java.lang.reflect.*; import java.util.Arrays; import java.util.stream.Collectors; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /* * @test * @bug 8159746 * @summary Test invoking a default method in a non-public proxy interface * @build p.Foo p.Bar p.ProxyMaker - * @run testng DefaultMethodProxy + * @run junit DefaultMethodProxy */ public class DefaultMethodProxy { public interface I { @@ -42,7 +43,7 @@ public class DefaultMethodProxy { } @Test - public static void publicInterface() throws ReflectiveOperationException { + public void publicInterface() throws ReflectiveOperationException { // create a proxy instance of a public proxy interface should succeed Proxy proxy = (Proxy)Proxy.newProxyInstance(DefaultMethodProxy.class.getClassLoader(), new Class[] { I.class }, IH); @@ -50,11 +51,9 @@ public class DefaultMethodProxy { testDefaultMethod(proxy, "I"); // can get the invocation handler - assertTrue(Proxy.getInvocationHandler(proxy) == IH); + assertSame(IH, Proxy.getInvocationHandler(proxy)); } - - @DataProvider(name = "nonPublicIntfs") private static Object[][] nonPublicIntfs() throws ClassNotFoundException { Class fooClass = Class.forName("p.Foo"); Class barClass = Class.forName("p.Bar"); @@ -65,8 +64,9 @@ public class DefaultMethodProxy { }; } - @Test(dataProvider = "nonPublicIntfs") - public static void hasPackageAccess(Class[] intfs, String expected) throws ReflectiveOperationException { + @ParameterizedTest + @MethodSource("nonPublicIntfs") + public void hasPackageAccess(Class[] intfs, String expected) throws ReflectiveOperationException { Proxy proxy = (Proxy)Proxy.newProxyInstance(DefaultMethodProxy.class.getClassLoader(), intfs, IH); testDefaultMethod(proxy, expected); @@ -75,19 +75,13 @@ public class DefaultMethodProxy { } // IAE thrown at invocation time - @Test(dataProvider = "nonPublicIntfs", expectedExceptions = {IllegalAccessException.class}) - public static void noPackageAccess(Class[] intfs, String ignored) throws Throwable { + @ParameterizedTest + @MethodSource("nonPublicIntfs") + public void noPackageAccess(Class[] intfs, String ignored) throws Throwable { Proxy proxy = (Proxy)Proxy.newProxyInstance(DefaultMethodProxy.class.getClassLoader(), intfs, IH_NO_ACCESS); - try { - testDefaultMethod(proxy, "dummy"); - } catch (InvocationTargetException e) { - // unwrap the exception - if (e.getCause() instanceof UndeclaredThrowableException) { - Throwable cause = e.getCause(); - throw cause.getCause(); - } - throw e; - } + InvocationTargetException ite = assertThrows(InvocationTargetException.class, () -> testDefaultMethod(proxy, "dummy")); + var ute = assertInstanceOf(UndeclaredThrowableException.class, ite.getCause(), "unwrap the InvocationTargetException"); + assertInstanceOf(IllegalAccessException.class, ute.getCause(), "unwrap the UndeclaredThrowableException"); } /* diff --git a/test/jdk/java/lang/reflect/annotationSharing/AnnotationSharing.java b/test/jdk/java/lang/reflect/annotationSharing/AnnotationSharing.java index 98a13d6416c..b29c74637d6 100644 --- a/test/jdk/java/lang/reflect/annotationSharing/AnnotationSharing.java +++ b/test/jdk/java/lang/reflect/annotationSharing/AnnotationSharing.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -27,13 +27,13 @@ * @summary Test sharing of annotations between Executable/Field instances. * Sharing should not be noticeable when performing mutating * operations. - * @run testng AnnotationSharing + * @run junit AnnotationSharing */ import java.lang.annotation.*; import java.lang.reflect.*; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; public class AnnotationSharing { @Test diff --git a/test/jdk/java/lang/reflect/callerCache/CustomLoaderTest.java b/test/jdk/java/lang/reflect/callerCache/CustomLoaderTest.java index f3a429027d9..6951cc0829c 100644 --- a/test/jdk/java/lang/reflect/callerCache/CustomLoaderTest.java +++ b/test/jdk/java/lang/reflect/callerCache/CustomLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -27,7 +27,7 @@ * @library /test/lib/ * @modules jdk.compiler * @build CustomLoaderTest jdk.test.lib.compiler.CompilerUtils - * @run testng/othervm CustomLoaderTest + * @run junit/othervm CustomLoaderTest * * @summary Test method whose parameter types and return type are not visible to the caller. */ @@ -42,27 +42,23 @@ import java.nio.file.Paths; import java.util.concurrent.atomic.AtomicInteger; import jdk.test.lib.compiler.CompilerUtils; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class CustomLoaderTest { private static final Path CLASSES = Paths.get("classes"); - @BeforeTest - public void setup() throws IOException { + @BeforeAll + public static void setup() throws IOException { String src = System.getProperty("test.src", "."); String classpath = System.getProperty("test.classes", "."); boolean rc = CompilerUtils.compile(Paths.get(src, "ReflectTest.java"), CLASSES, "-cp", classpath); if (!rc) { - throw new RuntimeException("fail compilation"); - } - try { - Class p = Class.forName("ReflectTest$P"); - fail("should not be visible to this loader"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + fail("fail compilation"); } + assertThrows(ClassNotFoundException.class, () -> Class.forName("ReflectTest$P"), + "should not be visible to this loader"); } @Test @@ -72,17 +68,17 @@ public class CustomLoaderTest { Method m1 = loader1.findMethod(); Method m2 = loader2.findMethod(); - assertTrue(m1.getDeclaringClass() != m2.getDeclaringClass()); + assertNotSame(m1.getDeclaringClass(), m2.getDeclaringClass()); - assertTrue(m1.getDeclaringClass() == loader1.c); - assertTrue(m2.getDeclaringClass() == loader2.c); + assertSame(loader1.c, m1.getDeclaringClass()); + assertSame(loader2.c, m2.getDeclaringClass()); Object o1 = m1.invoke(loader1.c.newInstance(), loader1.p.newInstance(), loader1.q.newInstance()); Object o2 = m2.invoke(loader2.c.newInstance(), loader2.p.newInstance(), loader2.q.newInstance()); - assertTrue(o1.getClass() != o2.getClass()); - assertTrue(o1.getClass() == loader1.r); - assertTrue(o2.getClass() == loader2.r); + assertNotSame(o1.getClass(), o2.getClass()); + assertSame(loader1.r, o1.getClass()); + assertSame(loader2.r, o2.getClass()); } static class TestLoader extends URLClassLoader { diff --git a/test/jdk/java/lang/reflect/callerCache/ReflectionCallerCacheTest.java b/test/jdk/java/lang/reflect/callerCache/ReflectionCallerCacheTest.java index b640a5e2150..4513c698a54 100644 --- a/test/jdk/java/lang/reflect/callerCache/ReflectionCallerCacheTest.java +++ b/test/jdk/java/lang/reflect/callerCache/ReflectionCallerCacheTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -29,7 +29,7 @@ * @library /test/lib/ * @modules jdk.compiler * @build ReflectionCallerCacheTest Members jdk.test.lib.compiler.CompilerUtils - * @run testng/othervm ReflectionCallerCacheTest + * @run junit/othervm ReflectionCallerCacheTest */ import java.io.IOException; @@ -44,16 +44,16 @@ import java.util.concurrent.Callable; import jdk.test.lib.compiler.CompilerUtils; import jdk.test.lib.util.ForceGC; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class ReflectionCallerCacheTest { private static final Path CLASSES = Paths.get("classes"); private static final ReflectionCallerCacheTest TEST = new ReflectionCallerCacheTest(); - @BeforeTest - public void setup() throws IOException { + @BeforeAll + public static void setup() throws IOException { String src = System.getProperty("test.src", "."); String classpath = System.getProperty("test.classes", "."); boolean rc = CompilerUtils.compile(Paths.get(src, "AccessTest.java"), CLASSES, "-cp", classpath); @@ -61,8 +61,8 @@ public class ReflectionCallerCacheTest { throw new RuntimeException("fail compilation"); } } - @DataProvider(name = "memberAccess") - public Object[][] memberAccess() { + + public static Object[][] memberAccess() { return new Object[][] { { "AccessTest$PublicConstructor" }, { "AccessTest$PublicMethod" }, @@ -102,8 +102,9 @@ public class ReflectionCallerCacheTest { } } - @Test(dataProvider = "memberAccess") - private void load(String classname) throws Exception { + @ParameterizedTest + @MethodSource("memberAccess") + void load(String classname) throws Exception { WeakReference weakLoader = loadAndRunClass(classname); // Force garbage collection to trigger unloading of class loader diff --git a/test/jdk/java/lang/reflect/records/CheckEqualityIsBasedOnFields.java b/test/jdk/java/lang/reflect/records/CheckEqualityIsBasedOnFields.java index b5c438e4f9a..c3e4431bd84 100644 --- a/test/jdk/java/lang/reflect/records/CheckEqualityIsBasedOnFields.java +++ b/test/jdk/java/lang/reflect/records/CheckEqualityIsBasedOnFields.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -25,17 +25,15 @@ * @test * @bug 8257598 * @summary check that Record::equals uses the fields and not the accessors for the comparison - * @run testng CheckEqualityIsBasedOnFields + * @run junit CheckEqualityIsBasedOnFields */ import java.lang.reflect.Constructor; -import java.lang.reflect.Field; import java.lang.reflect.Method; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; public class CheckEqualityIsBasedOnFields { public record R01(boolean x) { @@ -91,8 +89,7 @@ public class CheckEqualityIsBasedOnFields { } } - @DataProvider(name = "recordData") - public Object[][] recordTypeAndExpectedValue() { + public static Object[][] recordTypeAndExpectedValue() { return new Object[][] { new Object[] { R01.class, boolean.class, new Object[]{true, false} }, new Object[] { R02.class, byte.class, new Object[]{(byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)5, @@ -112,7 +109,8 @@ public class CheckEqualityIsBasedOnFields { }; } - @Test(dataProvider = "recordData") + @ParameterizedTest + @MethodSource("recordTypeAndExpectedValue") public void testEqualsDoesntUseAccessors(Class clazz, Class componentClass, Object[] expectedXValues) throws Exception { Constructor ctor; Method getter, equalsMethod; @@ -125,8 +123,8 @@ public class CheckEqualityIsBasedOnFields { System.out.println(rec1.toString()); System.out.println(rec2.toString()); assertFalse((boolean) equalsMethod.invoke(rec1, rec2)); - assertNotEquals(expectedXValues[i], expectedXValues[i + expectedXValues.length / 2]); - assertEquals(getter.invoke(rec1), getter.invoke(rec2)); + assertNotEquals(expectedXValues[i + expectedXValues.length / 2], expectedXValues[i]); + assertEquals(getter.invoke(rec2), getter.invoke(rec1)); } } } diff --git a/test/jdk/java/lang/reflect/records/IsRecordTest.java b/test/jdk/java/lang/reflect/records/IsRecordTest.java index 4888e6d506e..153329a7832 100644 --- a/test/jdk/java/lang/reflect/records/IsRecordTest.java +++ b/test/jdk/java/lang/reflect/records/IsRecordTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -26,32 +26,31 @@ * @bug 8255560 * @summary Class::isRecord should check that the current class is final and not abstract * @library /test/lib - * @run testng/othervm IsRecordTest + * @run junit/othervm IsRecordTest */ import java.lang.classfile.ClassFile; import java.lang.constant.ClassDesc; -import java.lang.reflect.AccessFlag; import java.util.List; import java.util.Map; import java.lang.classfile.attribute.RecordAttribute; import java.lang.classfile.attribute.RecordComponentInfo; import jdk.test.lib.ByteCodeLoader; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.System.out; import static java.lang.classfile.ClassFile.ACC_ABSTRACT; import static java.lang.classfile.ClassFile.ACC_FINAL; import static java.lang.constant.ConstantDescs.CD_int; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.*; public class IsRecordTest { - @DataProvider(name = "scenarios") - public Object[][] scenarios() { + public static Object[][] scenarios() { return new Object[][] { // isFinal, isAbstract, extendJLR, withRecAttr, expectIsRecord { false, false, false, true, false }, @@ -75,7 +74,8 @@ public class IsRecordTest { * iii) direct subclass of j.l.Record (or not), along with the presence or * absence of a record attribute. */ - @Test(dataProvider = "scenarios") + @ParameterizedTest + @MethodSource("scenarios") public void testDirectSubClass(boolean isFinal, boolean isAbstract, boolean extendsJLR, @@ -92,9 +92,8 @@ public class IsRecordTest { Class cls = ByteCodeLoader.load("C", classBytes); out.println("cls=%s, Record::isAssignable=%s, isRecord=%s" .formatted(cls, Record.class.isAssignableFrom(cls), cls.isRecord())); - assertEquals(cls.isRecord(), expectIsRecord); - var getRecordComponents = cls.getRecordComponents(); - assertTrue(expectIsRecord ? getRecordComponents != null : getRecordComponents == null); + assertEquals(expectIsRecord, cls.isRecord()); + assertEquals(expectIsRecord, cls.getRecordComponents() != null); } /** @@ -102,7 +101,8 @@ public class IsRecordTest { * along with the presence or absence of a record attribute, where the class has * a superclass whose superclass is j.l.Record. */ - @Test(dataProvider = "scenarios") + @ParameterizedTest + @MethodSource("scenarios") public void testIndirectSubClass(boolean isFinal, boolean isAbstract, boolean unused1, @@ -127,8 +127,8 @@ public class IsRecordTest { .formatted(cls, Record.class.isAssignableFrom(cls), cls.isRecord())); assertFalse(supFooCls.isRecord()); assertFalse(subFooCls.isRecord()); - assertEquals(supFooCls.getRecordComponents(), null); - assertEquals(subFooCls.getRecordComponents(), null); + assertNull(supFooCls.getRecordComponents()); + assertNull(subFooCls.getRecordComponents()); } /** Tests record-ness properties of traditionally compiled classes. */ @@ -137,23 +137,23 @@ public class IsRecordTest { out.println("\n--- testBasicRecords ---"); record EmptyRecord () { } assertTrue(EmptyRecord.class.isRecord()); - assertEquals(EmptyRecord.class.getRecordComponents().length, 0); + assertEquals(0, EmptyRecord.class.getRecordComponents().length); record FooRecord (int x) { } assertTrue(FooRecord.class.isRecord()); - assertTrue(FooRecord.class.getRecordComponents() != null); + assertNotNull(FooRecord.class.getRecordComponents()); final record FinalFooRecord (int x) { } assertTrue(FinalFooRecord.class.isRecord()); - assertTrue(FinalFooRecord.class.getRecordComponents() != null); + assertNotNull(FinalFooRecord.class.getRecordComponents()); class A { } assertFalse(A.class.isRecord()); - assertFalse(A.class.getRecordComponents() != null); + assertNull(A.class.getRecordComponents()); final class B { } assertFalse(B.class.isRecord()); - assertFalse(B.class.getRecordComponents() != null); + assertNull(B.class.getRecordComponents()); } // -- infra diff --git a/test/jdk/java/lang/reflect/records/RecordReflectionTest.java b/test/jdk/java/lang/reflect/records/RecordReflectionTest.java index 0598e88f0c1..5cc2fd4f8eb 100644 --- a/test/jdk/java/lang/reflect/records/RecordReflectionTest.java +++ b/test/jdk/java/lang/reflect/records/RecordReflectionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, 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 @@ -27,16 +27,17 @@ * @summary reflection test for records * @build R10 * @compile RecordReflectionTest.java - * @run testng/othervm RecordReflectionTest + * @run junit/othervm RecordReflectionTest */ import java.lang.annotation.*; import java.lang.reflect.*; import java.util.List; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@Test public class RecordReflectionTest { class NoRecord {} @@ -78,8 +79,7 @@ public class RecordReflectionTest { R13 {} // compact constructor, will contain mandated parameters } - @DataProvider(name = "recordClasses") - public Object[][] recordClassData() { + public static Object[][] recordClassData() { return List.of(R1.class, R2.class, R3.class, @@ -96,17 +96,17 @@ public class RecordReflectionTest { ).stream().map(c -> new Object[] {c}).toArray(Object[][]::new); } - @Test(dataProvider = "recordClasses") + @ParameterizedTest + @MethodSource("recordClassData") public void testIsRecord(Class cls) { String message = cls.toGenericString(); assertTrue(cls.isRecord()); - assertTrue(cls.getSuperclass() == java.lang.Record.class); - assertTrue(cls.getRecordComponents() != null); + assertSame(Record.class, cls.getSuperclass()); + assertNotNull(cls.getRecordComponents()); assertTrue(message.contains("record"), message); } - @DataProvider(name = "notRecordClasses") - public Object[][] notRecordClasses() { + public static List> notRecordClasses() { return List.of(NoRecord.class, NoRecord[].class, Record.class, // java.lang.Record is not itself a record class @@ -116,19 +116,18 @@ public class RecordReflectionTest { int.class, int[].class, long.class, - long[].class) - .stream().map(c -> new Object[] {c}).toArray(Object[][]::new); + long[].class); } - @Test(dataProvider = "notRecordClasses") + @ParameterizedTest + @MethodSource("notRecordClasses") public void testNotARecordClass(Class cls) { assertFalse(cls.isRecord()); - assertFalse(cls.getSuperclass() == java.lang.Record.class); - assertTrue(cls.getRecordComponents() == null); + assertNotSame(Record.class, cls.getSuperclass()); + assertNull(cls.getRecordComponents()); } - @DataProvider(name = "reflectionData") - public Object[][] reflectionData() { + public static Object[][] reflectionData() { return new Object[][] { new Object[] { new R1(), 0, @@ -181,7 +180,8 @@ public class RecordReflectionTest { }; } - @Test(dataProvider = "reflectionData") + @ParameterizedTest + @MethodSource("reflectionData") public void testRecordReflection(Object recordOb, int numberOfComponents, Object[] values, @@ -192,13 +192,13 @@ public class RecordReflectionTest { Class recordClass = recordOb.getClass(); assertTrue(recordClass.isRecord()); RecordComponent[] recordComponents = recordClass.getRecordComponents(); - assertEquals(recordComponents.length, numberOfComponents); + assertEquals(numberOfComponents, recordComponents.length); int i = 0; for (RecordComponent rc : recordComponents) { - assertEquals(rc.getName(), names[i]); - assertEquals(rc.getType(), rc.getAccessor().getReturnType()); - assertEquals(rc.getAccessor().invoke(recordOb), values[i]); - assertEquals(rc.getAccessor().getGenericReturnType().toString(), signatures[i], + assertEquals(names[i], rc.getName()); + assertEquals(rc.getAccessor().getReturnType(), rc.getType()); + assertEquals(values[i], rc.getAccessor().invoke(recordOb)); + assertEquals(signatures[i], rc.getAccessor().getGenericReturnType().toString(), String.format("signature of method \"%s\" different from expected signature \"%s\"", rc.getAccessor().getGenericReturnType(), signatures[i])); i++; @@ -207,7 +207,7 @@ public class RecordReflectionTest { var constructor = recordClass.getDeclaredConstructors()[0]; i = 0; for (var p: constructor.getParameters()) { - assertEquals(p.getParameterizedType().toString(), signatures[i], + assertEquals(signatures[i], p.getParameterizedType().toString(), String.format("signature of method \"%s\" different from expected signature \"%s\"", p.getType().toString(), signatures[i])); i++; @@ -215,7 +215,7 @@ public class RecordReflectionTest { // similar as above but testing another API i = 0; for (var p : constructor.getGenericParameterTypes()) { - assertEquals(p.toString(), signatures[i], + assertEquals(signatures[i], p.toString(), String.format("signature of method \"%s\" different from expected signature \"%s\"", p.toString(), signatures[i])); i++; @@ -228,16 +228,17 @@ public class RecordReflectionTest { record AnnotatedRec(@RCA int i) {} + @Test public void testDeclAnnotationsInRecordComp() throws Throwable { Class recordClass = AnnotatedRec.class; RecordComponent rc = recordClass.getRecordComponents()[0]; Annotation[] annos = rc.getAnnotations(); - assertEquals(annos.length, 1); - assertEquals(annos[0].toString(), "@RecordReflectionTest.RCA()"); + assertEquals(1, annos.length); + assertEquals("@RecordReflectionTest.RCA()", annos[0].toString()); Field f = recordClass.getDeclaredField("i"); - assertEquals(f.getAnnotations().length, 1); - assertEquals(f.getAnnotations()[0].toString(), annos[0].toString()); + assertEquals(1, f.getAnnotations().length); + assertEquals(annos[0].toString(), f.getAnnotations()[0].toString()); } @Retention(RetentionPolicy.RUNTIME) @@ -246,30 +247,28 @@ public class RecordReflectionTest { record TypeAnnotatedRec(@TYPE_USE int i) {} + @Test public void testTypeAnnotationsInRecordComp() throws Throwable { Class recordClass = TypeAnnotatedRec.class; RecordComponent rc = recordClass.getRecordComponents()[0]; AnnotatedType at = rc.getAnnotatedType(); Annotation[] annos = at.getAnnotations(); - assertEquals(annos.length, 1); - assertEquals(annos[0].toString(), "@RecordReflectionTest.TYPE_USE()"); + assertEquals(1, annos.length); + assertEquals("@RecordReflectionTest.TYPE_USE()", annos[0].toString()); Field f = recordClass.getDeclaredField("i"); - assertEquals(f.getAnnotatedType().getAnnotations().length, 1); - assertEquals(f.getAnnotatedType().getAnnotations()[0].toString(), annos[0].toString()); + assertEquals(1, f.getAnnotatedType().getAnnotations().length); + assertEquals(annos[0].toString(), f.getAnnotatedType().getAnnotations()[0].toString()); } + @Test public void testReadOnlyFieldInRecord() throws Throwable { R2 o = new R2(1, 2); Class recordClass = R2.class; String fieldName = "i"; Field f = recordClass.getDeclaredField(fieldName); assertTrue(f.trySetAccessible()); - assertTrue(f.get(o) != null); - try { - f.set(o, null); - assertTrue(false, "should fail to set " + fieldName); - } catch (IllegalAccessException e) { - } + assertNotNull(f.get(o)); + assertThrows(IllegalAccessException.class, () -> f.set(o, null)); } } diff --git a/test/jdk/java/lang/reflect/sealed_classes/SealedClassesReflectionTest.java b/test/jdk/java/lang/reflect/sealed_classes/SealedClassesReflectionTest.java index 03caebb49e8..6e14a5d540e 100644 --- a/test/jdk/java/lang/reflect/sealed_classes/SealedClassesReflectionTest.java +++ b/test/jdk/java/lang/reflect/sealed_classes/SealedClassesReflectionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, 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 @@ -26,18 +26,17 @@ * @bug 8227046 * @summary reflection test for sealed classes * @compile SealedClassesReflectionTest.java - * @run testng/othervm SealedClassesReflectionTest + * @run junit/othervm SealedClassesReflectionTest */ import java.lang.annotation.*; -import java.lang.constant.ClassDesc; import java.lang.reflect.*; import java.util.Arrays; import java.util.List; -import org.testng.annotations.*; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -@Test public class SealedClassesReflectionTest { sealed class SealedClass1 permits FinalSubclass1, NonSealedSubclass1 {} @@ -68,8 +67,7 @@ public class SealedClassesReflectionTest { sealed class SealedSubclass2 implements SealedInt3 permits NonSealedSubclass2 {} non-sealed class NonSealedSubclass2 extends SealedSubclass2 {} - @DataProvider(name = "sealedClasses") - public Object[][] sealedClassesData() { + public static List> sealedClassesData() { return List.of( SealedClass1.class, SealedClass2.class, @@ -79,19 +77,19 @@ public class SealedClassesReflectionTest { SealedInt2.class, SealedInt3.class, SealedSubInt1.class - ).stream().map(c -> new Object[] {c}).toArray(Object[][]::new); + ); } - @Test(dataProvider = "sealedClasses") + @ParameterizedTest + @MethodSource("sealedClassesData") public void testSealedClasses(Class cls) { assertTrue(cls.isSealed()); - assertTrue(!Modifier.isFinal(cls.getModifiers())); - assertTrue(cls.getPermittedSubclasses() != null); + assertFalse(Modifier.isFinal(cls.getModifiers())); + assertNotNull(cls.getPermittedSubclasses()); assertTrue(cls.getPermittedSubclasses().length > 0); } - @DataProvider(name = "notSealedClasses") - public Object[][] notSealedClassesData() { + public static List> notSealedClassesData() { return List.of( Object.class, void.class, Void.class, Void[].class, @@ -104,34 +102,34 @@ public class SealedClassesReflectionTest { double.class, double[].class, Double.class, Double[].class, boolean.class, boolean[].class, Boolean.class, Boolean[].class, String.class, String[].class - ).stream().map(c -> new Object[] {c}).toArray(Object[][]::new); + ); } - @Test(dataProvider = "notSealedClasses") + @ParameterizedTest + @MethodSource("notSealedClassesData") public void testNotSealedClasses(Class cls) { - assertTrue(!cls.isSealed()); - assertTrue(cls.getPermittedSubclasses() == null); + assertFalse(cls.isSealed()); + assertNull(cls.getPermittedSubclasses()); } - @DataProvider(name = "non_sealedClasses") - public Object[][] non_sealedClassesData() { + public static List> non_sealedClassesData() { return List.of( NonSealedSubclass1.class, NonSealedSubInt1.class, NonSealedSubclass2.class - ).stream().map(c -> new Object[] {c}).toArray(Object[][]::new); + ); } - @Test(dataProvider = "non_sealedClasses") + @ParameterizedTest + @MethodSource("non_sealedClassesData") public void testnon_sealedClasses(Class cls) { - assertTrue(!cls.isSealed()); - assertTrue(!Modifier.isFinal(cls.getModifiers())); + assertFalse(cls.isSealed()); + assertFalse(Modifier.isFinal(cls.getModifiers())); assertTrue((cls.getSuperclass() != null && cls.getSuperclass().isSealed()) || Arrays.stream(cls.getInterfaces()).anyMatch(Class::isSealed)); - assertTrue(cls.getPermittedSubclasses() == null); + assertNull(cls.getPermittedSubclasses()); } - @DataProvider(name = "reflectionData") - public Object[][] reflectionData() { + public static Object[][] reflectionData() { return new Object[][] { new Object[] { SealedClass1.class, @@ -204,7 +202,8 @@ public class SealedClassesReflectionTest { SEALED, NON_SEALED, FINAL } - @Test(dataProvider = "reflectionData") + @ParameterizedTest + @MethodSource("reflectionData") public void testSealedReflection(Class sealedClass, int numberOfSubclasses, String[] subclassDescriptors, @@ -213,10 +212,10 @@ public class SealedClassesReflectionTest { throws ReflectiveOperationException { assertTrue(sealedClass.isSealed()); - assertTrue(sealedClass.getPermittedSubclasses().length == numberOfSubclasses); + assertEquals(numberOfSubclasses, sealedClass.getPermittedSubclasses().length); int i = 0; for (Class cd : sealedClass.getPermittedSubclasses()) { - assertTrue(cd.getName().equals(subclassDescriptors[i]), "expected: " + subclassDescriptors[i] + " found: " + cd.getName()); + assertEquals(subclassDescriptors[i], cd.getName()); i++; } i = 0; diff --git a/test/jdk/java/lang/runtime/ExactnessConversionsSupportTest.java b/test/jdk/java/lang/runtime/ExactnessConversionsSupportTest.java index 6e1ef8e4c9f..3fbdfc5e9ab 100644 --- a/test/jdk/java/lang/runtime/ExactnessConversionsSupportTest.java +++ b/test/jdk/java/lang/runtime/ExactnessConversionsSupportTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2026, 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 @@ -21,46 +21,20 @@ * questions. */ -import org.testng.annotations.Test; - -import java.io.Serializable; -import java.lang.Enum.EnumDesc; -import java.lang.classfile.ClassFile; -import java.lang.constant.ClassDesc; -import java.lang.constant.ConstantDescs; -import java.lang.constant.MethodTypeDesc; -import java.lang.invoke.CallSite; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.AccessFlag; import java.lang.runtime.ExactConversionsSupport; -import java.lang.runtime.SwitchBootstraps; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.testng.Assert.*; +import org.junit.jupiter.api.Test; /** * @test * @bug 8304487 * @summary Verify boundary and special cases of exact conversion predicates * @compile ExactnessConversionsSupportTest.java - * @run testng/othervm ExactnessConversionsSupportTest + * @run junit/othervm ExactnessConversionsSupportTest */ -@Test public class ExactnessConversionsSupportTest { - public static void main(String[] args) { - testByte(); - testShort(); - testChar(); - testInt(); - testLong(); - testFloat(); - testDouble(); - } - - public static void testByte() { + @Test + public void testByte() { assertEquals(true, ExactConversionsSupport.isIntToByteExact((byte) (Byte.MAX_VALUE))); assertEquals(true, ExactConversionsSupport.isIntToByteExact((byte) (0))); assertEquals(true, ExactConversionsSupport.isIntToByteExact((byte) (Byte.MIN_VALUE))); @@ -92,7 +66,8 @@ public class ExactnessConversionsSupportTest { assertEquals(false, ExactConversionsSupport.isDoubleToByteExact(-0.0d)); assertEquals(true, ExactConversionsSupport.isDoubleToByteExact(+0.0d)); } - public static void testShort() { + @Test + public void testShort() { assertEquals(true, ExactConversionsSupport.isIntToShortExact((byte) (Byte.MAX_VALUE))); assertEquals(true, ExactConversionsSupport.isIntToShortExact((byte) (0))); assertEquals(true, ExactConversionsSupport.isIntToShortExact((byte) (Byte.MIN_VALUE))); @@ -125,7 +100,8 @@ public class ExactnessConversionsSupportTest { assertEquals(false, ExactConversionsSupport.isDoubleToShortExact(-0.0d)); assertEquals(true, ExactConversionsSupport.isDoubleToShortExact(+0.0d)); } - public static void testChar() { + @Test + public void testChar() { assertEquals(true, ExactConversionsSupport.isIntToCharExact((byte) (Byte.MAX_VALUE))); assertEquals(true, ExactConversionsSupport.isIntToCharExact((byte) (0))); assertEquals(false, ExactConversionsSupport.isIntToCharExact((byte) (Byte.MIN_VALUE))); @@ -157,7 +133,8 @@ public class ExactnessConversionsSupportTest { assertEquals(false, ExactConversionsSupport.isDoubleToCharExact(-0.0d)); assertEquals(true, ExactConversionsSupport.isDoubleToCharExact(+0.0d)); } - public static void testInt() { + @Test + public void testInt() { assertEquals(false, ExactConversionsSupport.isLongToIntExact((Long.MAX_VALUE))); assertEquals(true, ExactConversionsSupport.isLongToIntExact((0L))); assertEquals(false, ExactConversionsSupport.isLongToIntExact((Long.MIN_VALUE))); @@ -178,7 +155,8 @@ public class ExactnessConversionsSupportTest { assertEquals(false, ExactConversionsSupport.isDoubleToIntExact((-0.0d))); assertEquals(true, ExactConversionsSupport.isDoubleToIntExact((+0.0d))); } - public static void testLong() { + @Test + public void testLong() { assertEquals(false, ExactConversionsSupport.isFloatToLongExact((Float.MAX_VALUE))); assertEquals(true, ExactConversionsSupport.isFloatToLongExact(((float) 0))); assertEquals(false, ExactConversionsSupport.isFloatToLongExact((Float.MIN_VALUE))); @@ -196,7 +174,8 @@ public class ExactnessConversionsSupportTest { assertEquals(false, ExactConversionsSupport.isDoubleToLongExact((-0.0d))); assertEquals(true, ExactConversionsSupport.isDoubleToLongExact((+0.0d))); } - public static void testFloat() { + @Test + public void testFloat() { assertEquals(true, ExactConversionsSupport.isIntToFloatExact(((byte) (Byte.MAX_VALUE)))); assertEquals(true, ExactConversionsSupport.isIntToFloatExact(((byte) (0)))); assertEquals(true, ExactConversionsSupport.isIntToFloatExact(((byte) (Byte.MIN_VALUE)))); @@ -220,7 +199,8 @@ public class ExactnessConversionsSupportTest { assertEquals(true, ExactConversionsSupport.isDoubleToFloatExact((-0.0d))); assertEquals(true, ExactConversionsSupport.isDoubleToFloatExact((+0.0d))); } - public static void testDouble() { + @Test + public void testDouble() { assertEquals(false, ExactConversionsSupport.isLongToDoubleExact((Long.MAX_VALUE))); assertEquals(true, ExactConversionsSupport.isLongToDoubleExact((0L))); assertEquals(true, ExactConversionsSupport.isLongToDoubleExact((Long.MIN_VALUE))); diff --git a/test/jdk/java/lang/runtime/ObjectMethodsTest.java b/test/jdk/java/lang/runtime/ObjectMethodsTest.java index 62c8b034ed1..951d3b68383 100644 --- a/test/jdk/java/lang/runtime/ObjectMethodsTest.java +++ b/test/jdk/java/lang/runtime/ObjectMethodsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, 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 @@ -25,7 +25,7 @@ * @test * @bug 8246774 * @summary Basic tests for ObjectMethods - * @run testng ObjectMethodsTest + * @run junit ObjectMethodsTest */ import java.util.List; @@ -34,14 +34,14 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.runtime.ObjectMethods; -import org.testng.annotations.Test; import static java.lang.invoke.MethodType.methodType; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertThrows; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -@Test +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + public class ObjectMethodsTest { public static class C { @@ -80,6 +80,7 @@ public class ObjectMethodsTest { static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + @Test public void testEqualsC() throws Throwable { CallSite cs = (CallSite)ObjectMethods.bootstrap(LOOKUP, "equals", C.EQUALS_DESC, C.class, C.NAME_LIST, C.ACCESSORS); MethodHandle handle = cs.dynamicInvoker(); @@ -92,6 +93,7 @@ public class ObjectMethodsTest { assertFalse((boolean)handle.invokeExact(c, new Object())); } + @Test public void testEqualsEmpty() throws Throwable { CallSite cs = (CallSite)ObjectMethods.bootstrap(LOOKUP, "equals", Empty.EQUALS_DESC, Empty.class, Empty.NAME_LIST, Empty.ACCESSORS); MethodHandle handle = cs.dynamicInvoker(); @@ -102,45 +104,50 @@ public class ObjectMethodsTest { assertFalse((boolean)handle.invokeExact(e, new Object())); } + @Test public void testHashCodeC() throws Throwable { CallSite cs = (CallSite)ObjectMethods.bootstrap(LOOKUP, "hashCode", C.HASHCODE_DESC, C.class, "x;y", C.ACCESSORS); MethodHandle handle = cs.dynamicInvoker(); C c = new C(6, 7); int hc = (int)handle.invokeExact(c); - assertEquals(hc, hashCombiner(c.x(), c.y())); + assertEquals(hashCombiner(c.x(), c.y()), hc); - assertEquals((int)handle.invokeExact(new C(100, 1)), hashCombiner(100, 1)); - assertEquals((int)handle.invokeExact(new C(0, 0)), hashCombiner(0, 0)); - assertEquals((int)handle.invokeExact(new C(-1, 100)), hashCombiner(-1, 100)); - assertEquals((int)handle.invokeExact(new C(100, 1)), hashCombiner(100, 1)); - assertEquals((int)handle.invokeExact(new C(100, -1)), hashCombiner(100, -1)); + assertEquals(hashCombiner(100, 1), (int)handle.invokeExact(new C(100, 1))); + assertEquals(hashCombiner(0, 0), (int)handle.invokeExact(new C(0, 0))); + assertEquals(hashCombiner(-1, 100), (int)handle.invokeExact(new C(-1, 100))); + assertEquals(hashCombiner(100, 1), (int)handle.invokeExact(new C(100, 1))); + assertEquals(hashCombiner(100, -1), (int)handle.invokeExact(new C(100, -1))); } + @Test public void testHashCodeEmpty() throws Throwable { CallSite cs = (CallSite)ObjectMethods.bootstrap(LOOKUP, "hashCode", Empty.HASHCODE_DESC, Empty.class, "", Empty.ACCESSORS); MethodHandle handle = cs.dynamicInvoker(); Empty e = new Empty(); - assertEquals((int)handle.invokeExact(e), 0); + assertEquals(0, (int)handle.invokeExact(e)); } + @Test public void testToStringC() throws Throwable { CallSite cs = (CallSite)ObjectMethods.bootstrap(LOOKUP, "toString", C.TO_STRING_DESC, C.class, C.NAME_LIST, C.ACCESSORS); MethodHandle handle = cs.dynamicInvoker(); - assertEquals((String)handle.invokeExact(new C(8, 9)), "C[x=8, y=9]" ); - assertEquals((String)handle.invokeExact(new C(10, 11)), "C[x=10, y=11]" ); - assertEquals((String)handle.invokeExact(new C(100, -9)), "C[x=100, y=-9]"); - assertEquals((String)handle.invokeExact(new C(0, 0)), "C[x=0, y=0]" ); + assertEquals("C[x=8, y=9]", (String)handle.invokeExact(new C(8, 9)) ); + assertEquals("C[x=10, y=11]", (String)handle.invokeExact(new C(10, 11)) ); + assertEquals("C[x=100, y=-9]", (String)handle.invokeExact(new C(100, -9))); + assertEquals("C[x=0, y=0]", (String)handle.invokeExact(new C(0, 0)) ); } + @Test public void testToStringEmpty() throws Throwable { CallSite cs = (CallSite)ObjectMethods.bootstrap(LOOKUP, "toString", Empty.TO_STRING_DESC, Empty.class, Empty.NAME_LIST, Empty.ACCESSORS); MethodHandle handle = cs.dynamicInvoker(); - assertEquals((String)handle.invokeExact(new Empty()), "Empty[]"); + assertEquals("Empty[]", (String)handle.invokeExact(new Empty())); } Class NPE = NullPointerException.class; Class IAE = IllegalArgumentException.class; + @Test public void exceptions() { assertThrows(IAE, () -> ObjectMethods.bootstrap(LOOKUP, "badName", C.EQUALS_DESC, C.class, C.NAME_LIST, C.ACCESSORS)); assertThrows(IAE, () -> ObjectMethods.bootstrap(LOOKUP, "toString", C.TO_STRING_DESC, C.class, "x;y;z", C.ACCESSORS)); diff --git a/test/jdk/java/lang/runtime/SwitchBootstrapsTest.java b/test/jdk/java/lang/runtime/SwitchBootstrapsTest.java index 8c6132b2815..061ce2ae241 100644 --- a/test/jdk/java/lang/runtime/SwitchBootstrapsTest.java +++ b/test/jdk/java/lang/runtime/SwitchBootstrapsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -35,21 +35,20 @@ import java.lang.runtime.SwitchBootstraps; import java.util.concurrent.atomic.AtomicBoolean; import java.lang.classfile.ClassFile; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @test * @bug 8318144 * @enablePreview * @compile SwitchBootstrapsTest.java - * @run testng/othervm SwitchBootstrapsTest + * @run junit/othervm SwitchBootstrapsTest */ -@Test public class SwitchBootstrapsTest { public static final MethodHandle BSM_TYPE_SWITCH; @@ -70,14 +69,14 @@ public class SwitchBootstrapsTest { private void testType(Object target, int start, int result, Object... labels) throws Throwable { MethodType switchType = MethodType.methodType(int.class, Object.class, int.class); MethodHandle indy = ((CallSite) BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType, labels)).dynamicInvoker(); - assertEquals((int) indy.invoke(target, start), result); + assertEquals(result, (int) indy.invoke(target, start)); assertEquals(-1, (int) indy.invoke(null, start)); } private void testPrimitiveType(Object target, Class targetType, int start, int result, Object... labels) throws Throwable { MethodType switchType = MethodType.methodType(int.class, targetType, int.class); MethodHandle indy = ((CallSite) BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType, labels)).dynamicInvoker(); - assertEquals((int) indy.invoke(target, start), result); + assertEquals(result, (int) indy.invoke(target, start)); } private void testEnum(Enum target, int start, int result, Object... labels) throws Throwable { @@ -87,7 +86,7 @@ public class SwitchBootstrapsTest { private void testEnum(Class targetClass, Enum target, int start, int result, Object... labels) throws Throwable { MethodType switchType = MethodType.methodType(int.class, targetClass, int.class); MethodHandle indy = ((CallSite) BSM_ENUM_SWITCH.invoke(MethodHandles.lookup(), "", switchType, labels)).dynamicInvoker(); - assertEquals((int) indy.invoke(target, start), result); + assertEquals(result, (int) indy.invoke(target, start)); assertEquals(-1, (int) indy.invoke(null, start)); } @@ -100,6 +99,7 @@ public class SwitchBootstrapsTest { C; } + @Test public void testTypes() throws Throwable { testType("", 0, 0, String.class, Object.class); testType("", 0, 0, Object.class); @@ -138,6 +138,7 @@ public class SwitchBootstrapsTest { }, 0, 1, 1L); } + @Test public void testPrimitiveTypes() throws Throwable { testPrimitiveType((short) 1, short.class, 0, 1, String.class); testPrimitiveType((byte) 1, byte.class,0, 1, String.class, byte.class); @@ -150,52 +151,32 @@ public class SwitchBootstrapsTest { testPrimitiveType(true, boolean.class,0, 1, String.class, boolean.class); } + @Test public void testEnums() throws Throwable { testEnum(E1.A, 0, 2, "B", "C", "A", E1.class); testEnum(E1.B, 0, 0, "B", "C", "A", E1.class); testEnum(E1.B, 1, 3, "B", "C", "A", E1.class); - try { - testEnum(E1.B, 0, -1, E2.class); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, String.class); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, 10); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, new Object()); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, new Object[] { null }); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, ""); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, (Object[]) null); - fail("Didn't get the expected exception."); - } catch (NullPointerException ex) { - //OK - } + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, E2.class) + ); + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, String.class) + ); + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, 10) + ); + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, new Object()) + ); + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, new Object[] { null }) + ); + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, "") + ); + assertThrows(NullPointerException.class, () -> + testEnum(E1.B, 0, -1, (Object[]) null) + ); testEnum(E1.B, 0, 0, "B", "A"); testEnum(E1.A, 0, 1, "B", "A"); testEnum(E1.A, 0, 0, "A", "A", "B"); @@ -208,9 +189,10 @@ public class SwitchBootstrapsTest { //null invocation name: MethodType switchType = MethodType.methodType(int.class, E1.class, int.class); MethodHandle indy = ((CallSite) BSM_ENUM_SWITCH.invoke(MethodHandles.lookup(), null, switchType)).dynamicInvoker(); - assertEquals((int) indy.invoke(E1.A, 0), 0); + assertEquals(0, (int) indy.invoke(E1.A, 0)); } + @Test public void testEnumsWithConstants() throws Throwable { enum E { A {}, @@ -239,18 +221,16 @@ public class SwitchBootstrapsTest { testEnum(E.class, E.C, 2, 2, "A", "B"); } + @Test public void testWrongSwitchTypes() throws Throwable { MethodType[] switchTypes = new MethodType[] { MethodType.methodType(int.class, Object.class), MethodType.methodType(int.class, Object.class, Integer.class) }; for (MethodType switchType : switchTypes) { - try { - BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK, expected - } + assertThrows(IllegalArgumentException.class, () -> + BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType) + ); } MethodType[] enumSwitchTypes = new MethodType[] { MethodType.methodType(int.class, Enum.class), @@ -259,25 +239,21 @@ public class SwitchBootstrapsTest { MethodType.methodType(int.class, Enum.class, Integer.class) }; for (MethodType enumSwitchType : enumSwitchTypes) { - try { - BSM_ENUM_SWITCH.invoke(MethodHandles.lookup(), "", enumSwitchType); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK, expected - } + assertThrows(IllegalArgumentException.class, () -> + BSM_ENUM_SWITCH.invoke(MethodHandles.lookup(), "", enumSwitchType) + ); } } + @Test public void testSwitchLabelTypes() throws Throwable { enum E {A} - try { - testType(E.A, 0, -1, E.A); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK, expected - } + assertThrows(IllegalArgumentException.class, () -> + testType(E.A, 0, -1, E.A) + ); } + @Test public void testSwitchQualifiedEnum() throws Throwable { enum E {A, B, C} Object[] labels = new Object[] { @@ -290,41 +266,31 @@ public class SwitchBootstrapsTest { testType(E.C, 0, 2, labels); } + @Test public void testNullLabels() throws Throwable { MethodType switchType = MethodType.methodType(int.class, Object.class, int.class); - try { - BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType, (Object[]) null); - fail("Didn't get the expected exception."); - } catch (NullPointerException ex) { - //OK - } - try { + assertThrows(NullPointerException.class, () -> + BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType, (Object[]) null) + ); + assertThrows(IllegalArgumentException.class, () -> BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType, - new Object[] {1, null, String.class}); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } + new Object[] {1, null, String.class}) + ); MethodType enumSwitchType = MethodType.methodType(int.class, E1.class, int.class); - try { - BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", enumSwitchType, (Object[]) null); - fail("Didn't get the expected exception."); - } catch (NullPointerException ex) { - //OK - } - try { + assertThrows(NullPointerException.class, () -> + BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", enumSwitchType, (Object[]) null) + ); + assertThrows(IllegalArgumentException.class, () -> BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", enumSwitchType, - new Object[] {1, null, String.class}); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } + new Object[] {1, null, String.class}) + ); //null invocationName is OK: BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), null, switchType, new Object[] {Object.class}); } private static AtomicBoolean enumInitialized = new AtomicBoolean(); + @Test public void testEnumInitialization1() throws Throwable { enumInitialized.set(false); @@ -340,13 +306,14 @@ public class SwitchBootstrapsTest { CallSite invocation = (CallSite) BSM_ENUM_SWITCH.invoke(MethodHandles.lookup(), "", enumSwitchType, new Object[] {"A"}); assertFalse(enumInitialized.get()); - assertEquals(invocation.dynamicInvoker().invoke(null, 0), -1); + assertEquals(-1, invocation.dynamicInvoker().invoke(null, 0)); assertFalse(enumInitialized.get()); E e = E.A; assertTrue(enumInitialized.get()); - assertEquals(invocation.dynamicInvoker().invoke(e, 0), 0); + assertEquals(0, invocation.dynamicInvoker().invoke(e, 0)); } + @Test public void testEnumInitialization2() throws Throwable { enumInitialized.set(false); @@ -365,60 +332,46 @@ public class SwitchBootstrapsTest { }; CallSite invocation = (CallSite) BSM_TYPE_SWITCH.invoke(MethodHandles.lookup(), "", switchType, labels); assertFalse(enumInitialized.get()); - assertEquals(invocation.dynamicInvoker().invoke(null, 0), -1); + assertEquals(-1, invocation.dynamicInvoker().invoke(null, 0)); assertFalse(enumInitialized.get()); - assertEquals(invocation.dynamicInvoker().invoke("test", 0), 1); + assertEquals(1, invocation.dynamicInvoker().invoke("test", 0)); assertFalse(enumInitialized.get()); E e = E.A; assertTrue(enumInitialized.get()); - assertEquals(invocation.dynamicInvoker().invoke(e, 0), 0); + assertEquals(0, invocation.dynamicInvoker().invoke(e, 0)); } + @Test public void testIncorrectEnumLabels() throws Throwable { - try { - testEnum(E1.B, 0, -1, "B", 1); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } - try { - testEnum(E1.B, 0, -1, "B", null); - fail("Didn't get the expected exception."); - } catch (IllegalArgumentException ex) { - //OK - } + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, "B", 1) + ); + assertThrows(IllegalArgumentException.class, () -> + testEnum(E1.B, 0, -1, "B", null) + ); } + @Test public void testIncorrectEnumStartIndex() throws Throwable { - try { - testEnum(E1.B, -1, -1, "B"); - fail("Didn't get the expected exception."); - } catch (IndexOutOfBoundsException ex) { - //OK - } - try { - testEnum(E1.B, 2, -1, "B"); - fail("Didn't get the expected exception."); - } catch (IndexOutOfBoundsException ex) { - //OK - } + assertThrows(IndexOutOfBoundsException.class, () -> + testEnum(E1.B, -1, -1, "B") + ); //OK + assertThrows(IndexOutOfBoundsException.class, () -> + testEnum(E1.B, 2, -1, "B") + ); } + @Test public void testIncorrectTypeStartIndex() throws Throwable { - try { - testType("", -1, -1, ""); - fail("Didn't get the expected exception."); - } catch (IndexOutOfBoundsException ex) { - //OK - } - try { - testType("", 2, -1, ""); - fail("Didn't get the expected exception."); - } catch (IndexOutOfBoundsException ex) { - //OK - } + assertThrows(IndexOutOfBoundsException.class, () -> + testType("", -1, -1, "") + ); + assertThrows(IndexOutOfBoundsException.class, () -> + testType("", 2, -1, "") + ); } + @Test public void testHiddenClassAsCaseLabel() throws Throwable { MethodHandles.Lookup lookup = MethodHandles.lookup(); byte[] classBytes = createClass(); @@ -447,4 +400,23 @@ public class SwitchBootstrapsTest { }); }); } + + @Test + public void testNullLookup() throws Throwable { + assertThrows(NullPointerException.class, () -> { + MethodType switchType = MethodType.methodType(int.class, Object.class, int.class); + BSM_TYPE_SWITCH.invoke(null, "", switchType, Object.class); + }); + enum E {} + assertThrows(NullPointerException.class, () -> { + MethodType switchType = MethodType.methodType(int.class, E.class, int.class); + BSM_ENUM_SWITCH.invoke(null, "", switchType, + new Object[] {}); + }); + assertThrows(NullPointerException.class, () -> { + MethodType switchType = MethodType.methodType(int.class, E.class, int.class); + BSM_ENUM_SWITCH.invoke(null, "", switchType, + new Object[] {"A"}); + }); + } } diff --git a/test/jdk/java/net/httpclient/StreamingBody.java b/test/jdk/java/net/httpclient/StreamingBody.java index c2ad19cf7b7..3fb4f29208e 100644 --- a/test/jdk/java/net/httpclient/StreamingBody.java +++ b/test/jdk/java/net/httpclient/StreamingBody.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -25,11 +25,12 @@ * @test * @summary Exercise a streaming subscriber ( InputStream ) without holding a * strong (or any ) reference to the client. + * @key randomness * @library /test/lib /test/jdk/java/net/httpclient/lib * @build jdk.httpclient.test.lib.common.HttpServerAdapters jdk.test.lib.net.SimpleSSLContext - * @run testng/othervm + * @run junit/othervm * -Djdk.httpclient.HttpClient.log=trace,headers,requests - * StreamingBody + * ${test.main.class} */ import java.io.IOException; @@ -40,13 +41,15 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; import javax.net.ssl.SSLContext; import jdk.httpclient.test.lib.common.HttpServerAdapters; +import jdk.test.lib.RandomFactory; import jdk.test.lib.net.SimpleSSLContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; import static java.lang.System.out; import static java.net.http.HttpClient.Version.HTTP_1_1; import static java.net.http.HttpClient.Version.HTTP_2; @@ -55,8 +58,21 @@ import static java.net.http.HttpOption.Http3DiscoveryMode.HTTP_3_URI_ONLY; import static java.net.http.HttpOption.H3_DISCOVERY; import static java.nio.charset.StandardCharsets.UTF_8; import static java.net.http.HttpClient.Builder.NO_PROXY; -import static org.testng.Assert.assertEquals; +import org.junit.jupiter.api.AfterAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.extension.TestWatcher; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class StreamingBody implements HttpServerAdapters { private static final SSLContext sslContext = SimpleSSLContext.findSSLContext(); @@ -71,10 +87,105 @@ public class StreamingBody implements HttpServerAdapters { String https2URI; String http3URI; + static final AtomicLong clientCount = new AtomicLong(); + static final AtomicLong serverCount = new AtomicLong(); + static final ConcurrentMap FAILURES = new ConcurrentHashMap<>(); + private static boolean stopAfterFirstFailure() { + return true; + } + + static final long start = System.nanoTime(); + public static String now() { + long now = System.nanoTime() - start; + long secs = now / 1000_000_000; + long mill = (now % 1000_000_000) / 1000_000; + long nan = now % 1000_000; + return String.format("[%d s, %d ms, %d ns] ", secs, mill, nan); + } + + final static class TestStopper implements TestWatcher, BeforeEachCallback { + final AtomicReference failed = new AtomicReference<>(); + TestStopper() { } + @Override + public void testFailed(ExtensionContext context, Throwable cause) { + if (stopAfterFirstFailure()) { + String msg = "Aborting due to: " + cause; + failed.compareAndSet(null, msg); + FAILURES.putIfAbsent(context.getDisplayName(), cause); + System.out.printf("%nTEST FAILED: %s%s%n\tAborting due to %s%n%n", + now(), context.getDisplayName(), cause); + System.err.printf("%nTEST FAILED: %s%s%n\tAborting due to %s%n%n", + now(), context.getDisplayName(), cause); + } + } + + @Override + public void beforeEach(ExtensionContext context) { + String msg = failed.get(); + Assumptions.assumeTrue(msg == null, msg); + } + } + + @RegisterExtension + static final TestStopper stopper = new TestStopper(); + + /// The GCTrigger triggers GC at random intervals to + /// help garbage collecting HttpClient intances. This test + /// wants to verify that HttpClient instances which are no + /// longer strongly referenced are not garbage collected + /// before pending HTTP requests are finished. The test + /// creates many client instances (up to 500) and relies + /// on the GC to collect them, since it does not want to + /// keep a strong reference, and therefore cannot not call + /// close(). This can put extra load on the machine since + /// we can't (and don't want to) control when the GC will + /// intervene. The purpose of this class is to trigger the + /// GC at random intervals to 1. help garbage collect client + /// instances earlier, thus reducing the load on the machine, + /// and 2. potentially trigger bugs if the client gets + /// inadvertently GC'ed before the request is finished + /// (which is the bug we're testing for here). + static class GCTrigger { + private final long gcinterval; + private final Thread runner; + private volatile boolean stop; + private final static Random RANDOM = RandomFactory.getRandom(); + + GCTrigger(long gcinterval) { + this.gcinterval = Math.clamp(gcinterval, 100, Long.MAX_VALUE/2); + runner = Thread.ofPlatform().daemon().unstarted(this::loop); + } + + private void loop() { + long min = gcinterval / 2; + long max = gcinterval + min; + while (!stop) { + try { + Thread.sleep(RANDOM.nextLong(min, max)); + } catch (InterruptedException x) { + stop = true; + break; + } + out.println(now() + "triggering gc"); + System.gc(); + } + } + + public void start() { + runner.start(); + } + + public void stop() throws InterruptedException { + stop = true; + runner.interrupt(); + runner.join(); + } + } + + static GCTrigger gcTrigger; static final String MESSAGE = "StreamingBody message body"; static final int ITERATIONS = 100; - @DataProvider(name = "positive") public Object[][] positive() { return new Object[][] { { http3URI, }, @@ -94,72 +205,118 @@ public class StreamingBody implements HttpServerAdapters { return builder; } - @Test(dataProvider = "positive") + @ParameterizedTest + @MethodSource("positive") void test(String uriString) throws Exception { - out.printf("%n---- starting (%s) ----%n", uriString); + out.printf("%n%s---- starting (%s) ----%n", now(), uriString); URI uri = URI.create(uriString); HttpRequest request = newRequestBuilder(uri).build(); for (int i=0; i< ITERATIONS; i++) { - out.println("iteration: " + i); - var builder = uriString.contains("/http3/") - ? newClientBuilderForH3() - : HttpClient.newBuilder(); - HttpResponse response = builder - .sslContext(sslContext) - .proxy(NO_PROXY) - .build() - .sendAsync(request, BodyHandlers.ofInputStream()) - .join(); + try { + out.println(now() + "iteration: " + i); + var builder = uriString.contains("/http3/") + ? newClientBuilderForH3() + : HttpClient.newBuilder(); + clientCount.incrementAndGet(); - String body = new String(response.body().readAllBytes(), UTF_8); - out.println("Got response: " + response); - out.println("Got body Path: " + body); + // we want to relinquish the reference to the HttpClient facade + // as soon as possible. We're using `ofInputStream()` because + // the HttpResponse will be returned almost immediately, before + // the response is read. Similarly we use sendAsync() because + // this will return a CompletableFuture and not wait for the + // request to complete within a method called on the client + // facade. + HttpResponse response = builder + .sslContext(sslContext) + .proxy(NO_PROXY) + .build() + .sendAsync(request, BodyHandlers.ofInputStream()) + .join(); - assertEquals(response.statusCode(), 200); - assertEquals(body, MESSAGE); + String body = new String(response.body().readAllBytes(), UTF_8); + out.println("Got response: " + response); + out.println("Got body Path: " + body); + + assertEquals(200, response.statusCode()); + assertEquals(MESSAGE, body); + } catch (Throwable t) { + String msg = "%stest(%s)[%s] failed: %s" + .formatted(now(), uriString, i, t); + out.println(msg); + throw new AssertionError(msg, t); + } } } // -- Infrastructure - @BeforeTest + @BeforeAll public void setup() throws Exception { httpTestServer = HttpTestServer.create(HTTP_1_1); httpTestServer.addHandler(new MessageHandler(), "/http1/streamingbody/"); httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/streamingbody/w"; + serverCount.incrementAndGet(); httpsTestServer = HttpTestServer.create(HTTP_1_1, sslContext); httpsTestServer.addHandler(new MessageHandler(),"/https1/streamingbody/"); httpsURI = "https://" + httpsTestServer.serverAuthority() + "/https1/streamingbody/x"; + serverCount.incrementAndGet(); http2TestServer = HttpTestServer.create(HTTP_2); http2TestServer.addHandler(new MessageHandler(), "/http2/streamingbody/"); http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/streamingbody/y"; + serverCount.incrementAndGet(); https2TestServer = HttpTestServer.create(HTTP_2, sslContext); https2TestServer.addHandler(new MessageHandler(), "/https2/streamingbody/"); https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/streamingbody/z"; + serverCount.incrementAndGet(); http3TestServer = HttpTestServer.create(HTTP_3_URI_ONLY, sslContext); http3TestServer.addHandler(new MessageHandler(), "/http3/streamingbody/"); http3URI = "https://" + http3TestServer.serverAuthority() + "/http3/streamingbody/z"; + serverCount.incrementAndGet(); + + gcTrigger = new GCTrigger(500); httpTestServer.start(); httpsTestServer.start(); http2TestServer.start(); https2TestServer.start(); http3TestServer.start(); + gcTrigger.start(); } - @AfterTest + @AfterAll public void teardown() throws Exception { - httpTestServer.stop(); - httpsTestServer.stop(); - http2TestServer.stop(); - https2TestServer.stop(); - http3TestServer.stop(); + try { + httpTestServer.stop(); + httpsTestServer.stop(); + http2TestServer.stop(); + https2TestServer.stop(); + http3TestServer.stop(); + gcTrigger.stop(); + } finally { + printFailedTests(); + } + } + + static final void printFailedTests() { + out.println("\n========================="); + try { + out.printf("%n%sCreated %s servers and %s clients%n", + now(), serverCount.get(), clientCount.get()); + if (FAILURES.isEmpty()) return; + out.println("Failed tests: "); + FAILURES.entrySet().forEach((e) -> { + out.printf("\t%s: %s%n", e.getKey(), e.getValue()); + e.getValue().printStackTrace(out); + }); + } finally { + out.println("\n=========================\n"); + } } static class MessageHandler implements HttpTestHandler { diff --git a/test/jdk/java/net/httpclient/http3/H3FixedThreadPoolTest.java b/test/jdk/java/net/httpclient/http3/H3FixedThreadPoolTest.java index c513cd092c7..6c181186fda 100644 --- a/test/jdk/java/net/httpclient/http3/H3FixedThreadPoolTest.java +++ b/test/jdk/java/net/httpclient/http3/H3FixedThreadPoolTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, 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 @@ -30,9 +30,17 @@ * jdk.test.lib.Utils * jdk.test.lib.net.SimpleSSLContext * @compile ../ReferenceTracker.java + * + * @comment This test failed on Tier 7, but the failure could not be reproduced. + * The QUIC idle timeout has been increased to a value higher than the + * JTreg on Tier 7 so that, if the client becomes wedged again, the + * JTreg timeout handlers can collect more diagnostic information. + * * @run testng/othervm -Djdk.internal.httpclient.debug=err * -Djdk.httpclient.HttpClient.log=ssl,headers,requests,responses,errors - * H3FixedThreadPoolTest + * -Djdk.httpclient.quic.idleTimeout=666666 + * -Djdk.test.server.quic.idleTimeout=666666 + * ${test.main.class} */ import java.net.URI; diff --git a/test/jdk/javax/crypto/Cipher/TestDisabledWithOids.java b/test/jdk/javax/crypto/Cipher/TestDisabledWithOids.java new file mode 100644 index 00000000000..d1d9fa7a5bb --- /dev/null +++ b/test/jdk/javax/crypto/Cipher/TestDisabledWithOids.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2026, 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. + */ + +/** + * @test + * @bug 8375549 + * @summary Test JCE layer algorithm restriction using algorithms w/ oids + * @library /test/lib + * @run main/othervm -Djdk.crypto.disabledAlgorithms=Cipher.DES,Cipher.RSA/ECB/PKCS1Padding TestDisabledWithOids + * @run main/othervm -Djdk.crypto.disabledAlgorithms=Cipher.RSA/ECB/PKCS1Padding,Cipher.DES TestDisabledWithOids + */ +import java.security.NoSuchAlgorithmException; +import javax.crypto.Cipher; +import jdk.test.lib.Utils; + +public class TestDisabledWithOids { + public static void main(String[] args) throws Exception { + String algo1 = "RSA/ECB/PKCS1Padding"; + String algo2 = "DES"; + + Utils.runAndCheckException(() -> Cipher.getInstance(algo1), + NoSuchAlgorithmException.class); + Utils.runAndCheckException(() -> Cipher.getInstance(algo2), + NoSuchAlgorithmException.class); + System.out.println("Done"); + } +} diff --git a/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java index c16fe0e5a82..8125b656de4 100644 --- a/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java +++ b/test/jdk/javax/print/PrintServiceLookup/FlushCustomClassLoader.java @@ -56,17 +56,6 @@ public final class FlushCustomClassLoader { } private static Reference getLoader(String m) throws Exception { - /* - * The print services are stored per the AppContext, and each AppContext - * caches the "current" class loader during creation. - * see javax.print.PrintServiceLookup. - * - * To prevent AppContext from cache our test loader we force AppContext - * creation early by the invokeAndWait. - * The "EventQueue.invokeAndWait(() -> {});" can be removed when the - * AppContext usage will be deleted in the PrintServiceLookup - */ - EventQueue.invokeAndWait(() -> {}); URL url = FlushCustomClassLoader.class.getProtectionDomain() .getCodeSource().getLocation(); diff --git a/test/jdk/javax/print/PrintablePrintDPI.java b/test/jdk/javax/print/PrintablePrintDPI.java index 6cae2be532c..6b5e83df233 100644 --- a/test/jdk/javax/print/PrintablePrintDPI.java +++ b/test/jdk/javax/print/PrintablePrintDPI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2025, BELLSOFT. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -54,7 +54,7 @@ import java.awt.print.PrinterJob; /* * @test - * @bug 8251928 + * @bug 8251928 8375221 * @key printer * @summary Printable.print method should reflect printer's DPI * @library /java/awt/regtesthelpers @@ -201,7 +201,9 @@ public class PrintablePrintDPI implements Printable { attributeSet.add(OrientationRequested.PORTRAIT); job.setPrintService(printService); job.setPrintable(this); - job.print(attributeSet); + if (job.printDialog(attributeSet)) { + job.print(attributeSet); + } } catch (PrinterException ex) { throw new RuntimeException(ex); } diff --git a/test/jdk/javax/swing/JFileChooser/4966171/bug4966171.java b/test/jdk/javax/swing/JFileChooser/4966171/bug4966171.java index f3b3ba684e6..27f26d570be 100644 --- a/test/jdk/javax/swing/JFileChooser/4966171/bug4966171.java +++ b/test/jdk/javax/swing/JFileChooser/4966171/bug4966171.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, 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 @@ -50,8 +50,8 @@ public final class bug4966171 { } private static void test() { - // Will run the test no more than 10 seconds per L&F - long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(10); + // Will run the test no more than 5 seconds per L&F + long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(5); while (System.nanoTime() < endtime) { try { var byteOut = new ByteArrayOutputStream(); diff --git a/test/jdk/javax/swing/Security/6938813/bug6938813.java b/test/jdk/javax/swing/Security/6938813/bug6938813.java deleted file mode 100644 index 8f5e3fc3505..00000000000 --- a/test/jdk/javax/swing/Security/6938813/bug6938813.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2010, 2017, 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. - */ - -/* - * @test - * @key headful - * @bug 6938813 - * @summary Swing mutable statics - * @author Pavel Porvatov - * @modules java.desktop/javax.swing.text.html.parser:open - * @modules java.desktop/sun.awt - */ - -import sun.awt.AppContext; -import sun.awt.SunToolkit; - -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.StyleSheet; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.ParserDelegator; -import java.lang.reflect.Field; - -public class bug6938813 { - public static final String DTD_KEY = "dtd_key"; - - private static volatile StyleSheet styleSheet; - - public static void main(String[] args) throws Exception { - // Run validation and init values for this AppContext - validate(); - - Thread thread = new ThreadInAnotherAppContext(); - - thread.start(); - thread.join(); - } - - private static void validate() throws Exception { - AppContext appContext = AppContext.getAppContext(); - - assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts"); - - // Spoil hash value - DTD invalidDtd = DTD.getDTD("invalid DTD"); - - DTD.putDTDHash(DTD_KEY, invalidDtd); - - assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()"); - - Object dtdKey = getParserDelegator_DTD_KEY(); - - assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts"); - - // Init default DTD - new ParserDelegator(); - - Object dtdValue = appContext.get(dtdKey); - - assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized"); - - // Try reinit default DTD - new ParserDelegator(); - - assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate"); - - HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); - - if (styleSheet == null) { - // First AppContext - styleSheet = htmlEditorKit.getStyleSheet(); - - assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null"); - assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()"); - } else { - assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts"); - } - } - - private static void assertTrue(boolean b, String msg) { - if (!b) { - throw new RuntimeException("Test failed: " + msg); - } - } - - private static Object getParserDelegator_DTD_KEY() throws Exception { - Field field = ParserDelegator.class.getDeclaredField("DTD_KEY"); - - field.setAccessible(true); - - return field.get(null); - } - - private static class ThreadInAnotherAppContext extends Thread { - public ThreadInAnotherAppContext() { - super(new ThreadGroup("6938813"), "ThreadInAnotherAppContext"); - } - - public void run() { - SunToolkit.createNewAppContext(); - - try { - validate(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/test/jdk/javax/swing/plaf/synth/7143614/bug7143614.java b/test/jdk/javax/swing/plaf/synth/7143614/bug7143614.java deleted file mode 100644 index f1e1cbb94aa..00000000000 --- a/test/jdk/javax/swing/plaf/synth/7143614/bug7143614.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2012, 2015, 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. - */ - -/* - * @test - * @bug 7143614 - * @summary Issues with Synth Look&Feel - * @author Pavel Porvatov - * @modules java.desktop/javax.swing.plaf.synth:open - * @modules java.desktop/sun.awt - */ - -import sun.awt.SunToolkit; - -import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicButtonUI; -import javax.swing.plaf.synth.SynthConstants; -import javax.swing.plaf.synth.SynthLookAndFeel; -import java.lang.reflect.Method; - -public class bug7143614 { - private static Method setSelectedUIMethod; - - private static ComponentUI componentUI = new BasicButtonUI(); - - public static void main(String[] args) throws Exception { - setSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("setSelectedUI", ComponentUI.class, - boolean.class, boolean.class, boolean.class, boolean.class); - setSelectedUIMethod.setAccessible(true); - - setSelectedUIMethod.invoke(null, componentUI, true, true, true, true); - - validate(); - - Thread thread = new ThreadInAnotherAppContext(); - - thread.start(); - thread.join(); - - validate(); - - System.out.println("Test bug7143614 passed."); - } - - private static void validate() throws Exception { - Method getSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUI"); - - getSelectedUIMethod.setAccessible(true); - - Method getSelectedUIStateMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUIState"); - - getSelectedUIStateMethod.setAccessible(true); - - if (getSelectedUIMethod.invoke(null) != componentUI) { - throw new RuntimeException("getSelectedUI returns invalid value"); - } - if (((Integer) getSelectedUIStateMethod.invoke(null)).intValue() != - (SynthConstants.SELECTED | SynthConstants.FOCUSED)) { - throw new RuntimeException("getSelectedUIState returns invalid value"); - } - - } - - private static class ThreadInAnotherAppContext extends Thread { - public ThreadInAnotherAppContext() { - super(new ThreadGroup("7143614"), "ThreadInAnotherAppContext"); - } - - public void run() { - SunToolkit.createNewAppContext(); - - try { - setSelectedUIMethod.invoke(null, null, false, false, false, false); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } -} diff --git a/test/jdk/javax/swing/plaf/synth/Test6660049.java b/test/jdk/javax/swing/plaf/synth/Test6660049.java deleted file mode 100644 index a7486eb86c8..00000000000 --- a/test/jdk/javax/swing/plaf/synth/Test6660049.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2009, 2016, 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. - */ - -/* - * @test - * @key headful - * @bug 6660049 6849518 - * @summary Tests the Region initialization - * @author Sergey Malenkov - * @modules java.desktop/sun.awt - */ - -import sun.awt.SunToolkit; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.SwingUtilities; -import javax.swing.plaf.synth.Region; -import javax.swing.plaf.synth.SynthLookAndFeel; - -public class Test6660049 implements Runnable { - public static void main(String[] args) { - SwingUtilities.invokeLater(new Test6660049( - javax.swing.JButton.class, - javax.swing.JCheckBox.class, - javax.swing.JCheckBoxMenuItem.class, - javax.swing.JColorChooser.class, - javax.swing.JComboBox.class, - javax.swing.JDesktopPane.class, - javax.swing.JEditorPane.class, - javax.swing.JFileChooser.class, - javax.swing.JFormattedTextField.class, - javax.swing.JInternalFrame.class, - javax.swing.JLabel.class, - javax.swing.JList.class, - javax.swing.JMenu.class, - javax.swing.JMenuBar.class, - javax.swing.JMenuItem.class, - javax.swing.JOptionPane.class, - javax.swing.JPanel.class, - javax.swing.JPasswordField.class, - javax.swing.JPopupMenu.class, - javax.swing.JProgressBar.class, - javax.swing.JRadioButton.class, - javax.swing.JRadioButtonMenuItem.class, - javax.swing.JRootPane.class, - javax.swing.JScrollBar.class, - javax.swing.JScrollPane.class, - javax.swing.JSeparator.class, - javax.swing.JSlider.class, - javax.swing.JSpinner.class, - javax.swing.JSplitPane.class, - javax.swing.JTabbedPane.class, - javax.swing.JTable.class, - javax.swing.JTextArea.class, - javax.swing.JTextField.class, - javax.swing.JTextPane.class, - javax.swing.JToggleButton.class, - javax.swing.JToolBar.class, - javax.swing.JToolTip.class, - javax.swing.JTree.class, - javax.swing.JViewport.class, - javax.swing.table.JTableHeader.class)); - } - - private final Class[] types; - private final Region region; - - private Test6660049(Class... types) { - this.types = types; - run(); - - this.region = new Region("Button", "ButtonUI", true) { - @Override - public String getName() { - throw new Error("6660049: exploit is available"); - } - }; - } - - public void run() { - if (this.region != null) { - SunToolkit.createNewAppContext(); - } - for (Class type : this.types) { - Region region = getRegion(type); - if (region == null) { - throw new Error("6849518: region is not initialized"); - } - } - getRegion(JButton.class).getName(); - } - - private static Region getRegion(Class type) { - try { - return SynthLookAndFeel.getRegion(type.newInstance()); - } - catch (IllegalAccessException exception) { - throw new Error("unexpected exception", exception); - } - catch (InstantiationException exception) { - throw new Error("unexpected exception", exception); - } - } -} diff --git a/test/jdk/javax/swing/text/LayoutQueue/Test6588003.java b/test/jdk/javax/swing/text/LayoutQueue/Test6588003.java deleted file mode 100644 index 561ac594a47..00000000000 --- a/test/jdk/javax/swing/text/LayoutQueue/Test6588003.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2007, 2015, 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. - */ - -/* @test - @bug 6588003 - @summary LayoutQueue should not share its DefaultQueue across AppContexts - @author Peter Zhelezniakov - @modules java.desktop/sun.awt - @run main Test6588003 -*/ - -import javax.swing.text.LayoutQueue; -import sun.awt.SunToolkit; - -public class Test6588003 implements Runnable { - private static final LayoutQueue DEFAULT = new LayoutQueue(); - - public static void main(String[] args) throws InterruptedException { - LayoutQueue.setDefaultQueue(DEFAULT); - - ThreadGroup group = new ThreadGroup("Test6588003"); - Thread thread = new Thread(group, new Test6588003()); - thread.start(); - thread.join(); - - if (LayoutQueue.getDefaultQueue() != DEFAULT) { - throw new RuntimeException("Sharing detected"); - } - } - - public void run() { - SunToolkit.createNewAppContext(); - - if (LayoutQueue.getDefaultQueue() == DEFAULT) { - throw new RuntimeException("Sharing detected"); - } - - LayoutQueue.setDefaultQueue(new LayoutQueue()); - } -} diff --git a/test/jdk/javax/swing/text/html/parser/Test8017492.java b/test/jdk/javax/swing/text/html/parser/Test8017492.java deleted file mode 100644 index dbc1e125cf7..00000000000 --- a/test/jdk/javax/swing/text/html/parser/Test8017492.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2013, 2020, 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. - */ - -import java.util.Vector; -import javax.swing.text.html.HTML; -import javax.swing.text.html.HTMLDocument; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.parser.DTD; -import javax.swing.text.html.parser.Element; -import sun.awt.SunToolkit; - -/* - * @test - * @bug 8017492 - * @modules java.desktop/sun.awt - * @run main/othervm Test8017492 - * @summary Tests for OutOfMemoryError/NegativeArraySizeException - * @author Sergey Malenkov - */ - -public class Test8017492 { - public static void main(String[] args) throws Exception { - Runnable task = new Runnable() { - @Override - public void run() { - try { - SunToolkit.createNewAppContext(); - DTD dtd = DTD.getDTD("dtd"); - dtd.elements = new Vector() { - @Override - public synchronized int size() { - return Integer.MAX_VALUE; - } - }; - dtd.getElement("element"); - } - catch (Exception exception) { - throw new Error("unexpected", exception); - } - } - }; - // run task with different AppContext - Thread thread = new Thread(new ThreadGroup("$$$"), task); - thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread thread, Throwable throwable) { - throwable.printStackTrace(); - throw new RuntimeException(throwable); - } - }); - thread.start(); - thread.join(); - // add error handling - SunToolkit.createNewAppContext(); - HTMLDocument document = new HTMLDocument() { - @Override - public HTMLEditorKit.ParserCallback getReader(int pos) { - return getReader(pos, 0, 0, null); - } - - @Override - public HTMLEditorKit.ParserCallback getReader(int pos, int popDepth, int pushDepth, HTML.Tag insertTag) { - return new HTMLDocument.HTMLReader(pos, popDepth, pushDepth, insertTag) { - @Override - public void handleError(String error, int pos) { - throw new Error(error); - } - }; - } - }; - // run parser - new HTMLEditorKit().insertHTML(document, 0, "text", 0, 0, null); - } -} diff --git a/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java b/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java index 7d5dbca6f7c..4b487934169 100644 --- a/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java +++ b/test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java @@ -91,7 +91,8 @@ public class TestDockerMemoryMetricsSubgroup { .addDockerOpts("--volume", Utils.TEST_JDK + ":/jdk") .addDockerOpts("--privileged") .addDockerOpts("--cgroupns=" + (privateNamespace ? "private" : "host")) - .addDockerOpts("--memory", outerGroupMemorySize); + .addDockerOpts("--memory", outerGroupMemorySize) + .addDockerOpts("-e", "LANG=C.UTF-8"); opts.addClassOptions("mkdir -p /sys/fs/cgroup/memory/test ; " + "echo " + innerSize + " > /sys/fs/cgroup/memory/test/memory.limit_in_bytes ; " + "echo $$ > /sys/fs/cgroup/memory/test/cgroup.procs ; " + @@ -112,6 +113,7 @@ public class TestDockerMemoryMetricsSubgroup { .addDockerOpts("--volume", Utils.TEST_JDK + ":/jdk") .addDockerOpts("--privileged") .addDockerOpts("--cgroupns=" + (privateNamespace ? "private" : "host")) + .addDockerOpts("-e", "LANG=C.UTF-8") .addDockerOpts("--memory", outerGroupMemorySize); opts.addClassOptions("mkdir -p /sys/fs/cgroup/memory/test ; " + "echo $$ > /sys/fs/cgroup/memory/test/cgroup.procs ; " + diff --git a/test/jdk/sun/awt/image/ImageRepresentation/LUTCompareTest.java b/test/jdk/sun/awt/image/ImageRepresentation/LUTCompareTest.java index aca2ff1071c..498fe227651 100644 --- a/test/jdk/sun/awt/image/ImageRepresentation/LUTCompareTest.java +++ b/test/jdk/sun/awt/image/ImageRepresentation/LUTCompareTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2026, 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 @@ -23,12 +23,13 @@ /* * @test - * @bug 6570475 + * @bug 6570475 8375338 * @summary Test verifies that palette comparison procedure of * ImageRepresentation class does not produce extra transparent * pixels. * - * @run main LUTCompareTest + * @run main/othervm LUTCompareTest + * @run main/othervm -Xcheck:jni LUTCompareTest */ diff --git a/test/langtools/jdk/javadoc/doclet/checkStylesheetClasses/CheckStylesheetClasses.java b/test/langtools/jdk/javadoc/doclet/checkStylesheetClasses/CheckStylesheetClasses.java index ee1fa538a57..6740bace528 100644 --- a/test/langtools/jdk/javadoc/doclet/checkStylesheetClasses/CheckStylesheetClasses.java +++ b/test/langtools/jdk/javadoc/doclet/checkStylesheetClasses/CheckStylesheetClasses.java @@ -122,7 +122,7 @@ public class CheckStylesheetClasses { "modifiers", "permits", "return-type"); // misc: these are defined in HtmlStyle, and used by the doclet - removeAll(htmlStyleNames, "col-plain", "external-link", "header", "index", + removeAll(htmlStyleNames, "col-plain", "external-link", "header", "package-uses", "packages", "permits-note", "serialized-package-container", "source-container"); diff --git a/test/langtools/jdk/jshell/SnippetHighlightTest.java b/test/langtools/jdk/jshell/SnippetHighlightTest.java index dbf3418af83..33f7f263617 100644 --- a/test/langtools/jdk/jshell/SnippetHighlightTest.java +++ b/test/langtools/jdk/jshell/SnippetHighlightTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8274148 8301580 8359497 + * @bug 8274148 8301580 8359497 8374293 * @summary Check snippet highlighting * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api @@ -122,6 +122,13 @@ public class SnippetHighlightTest extends KullaTesting { """); } + @Test // 8374293: The returned Highlights should not overlap + public void testHighlightsOverlap() { + assertHighlights("public void E test()", "Highlight[start=0, end=6, attributes=[KEYWORD]]", + "Highlight[start=7, end=11, attributes=[KEYWORD]]", + "Highlight[start=14, end=18, attributes=[DECLARATION]]"); + } + private void assertHighlights(String code, String... expected) { List completions = computeHighlights(code); assertEquals(Arrays.asList(expected), completions, "Input: " + code + ", " + completions.toString()); @@ -134,7 +141,6 @@ public class SnippetHighlightTest extends KullaTesting { getAnalysis().highlights(code); return highlights.stream() .map(h -> h.toString()) - .distinct() .collect(Collectors.toList()); } } diff --git a/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java b/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java index b013561be0b..bd9a706e3a4 100644 --- a/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java +++ b/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, 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 @@ -380,6 +380,7 @@ public class DockerTestUtils { } template = template + "COPY /jdk /jdk\n" + "ENV JAVA_HOME=/jdk\n" + + "ENV LANG=C.UTF-8\n" + "CMD [\"/bin/bash\"]\n"; String dockerFileStr = String.format(template, baseImage, baseImageVersion); Files.writeString(dockerfile, dockerFileStr); diff --git a/test/lib/jdk/test/lib/util/CoreUtils.java b/test/lib/jdk/test/lib/util/CoreUtils.java index f7a486def2b..72c1d89af44 100644 --- a/test/lib/jdk/test/lib/util/CoreUtils.java +++ b/test/lib/jdk/test/lib/util/CoreUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2025, 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 @@ -203,6 +203,7 @@ public class CoreUtils { private static final String CORE_PATTERN_FILE_NAME = "/proc/sys/kernel/core_pattern"; private static final String LOCATION_STRING = "location: "; + private static final String ALT_LOCATION_STRING = "alternatively, falling back to"; private static String parseCoreFileLocationFromOutput(String crashOutputString) { System.out.println("crashOutputString = [" + crashOutputString + "]"); @@ -220,12 +221,25 @@ public class CoreUtils { // Find the core file name in the output. String coreWithPid; - if (stringWithLocation.contains("or ") && !Platform.isWindows()) { - Matcher m = Pattern.compile("or.* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation); + if (Platform.isLinux() && stringWithLocation.contains(ALT_LOCATION_STRING)) { + /* + * If hotspot detects that /proc/sys/kernel/core_pattern starts with a "|", + * it generates a messages something like the following: + * # Core dump will be written. Default location: Determined by the following: + * "/var/bin/core.sh %p" (alternatively, falling back to + * /ws/jdk/build/linux-x64/test-support/jtreg_open_test_hotspot_jtreg_serviceability_sa_ClhsdbFindPC_java/scratch/2/core.10353) + * We try to detect this and glean this alternative path from the message. The + * hope here is that either this is where the core file actually ends up, or that + * the script referenced by the core_pattern is just zipping the core file, in + * which case a call to unzipCores() will have already unzipped the core file + * into this path. + */ + Matcher m = Pattern.compile(ALT_LOCATION_STRING + ".* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation); if (!m.find()) { throw new RuntimeException("Couldn't find path to core inside location string"); } coreWithPid = m.group(1); + System.out.println("getCoreFileLocation found alt coreWithPid = " + coreWithPid); } else { coreWithPid = stringWithLocation.trim(); } diff --git a/test/micro/org/openjdk/bench/java/nio/CharsetCanEncode.java b/test/micro/org/openjdk/bench/java/nio/CharsetCanEncode.java new file mode 100644 index 00000000000..ebfbc217a95 --- /dev/null +++ b/test/micro/org/openjdk/bench/java/nio/CharsetCanEncode.java @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2026, 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. + */ +package org.openjdk.bench.java.nio; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Thread) +@Fork(3) +public class CharsetCanEncode { + + private static final char ALEF_CHAR = '\u05d0'; + private static final String ALEF_STRING = "\u05d0"; + + // sun.nio.cs.US_ASCII + private CharsetEncoder ascii = Charset.forName("US-ASCII").newEncoder(); + + // sun.nio.cs.ISO_8859_1 + private CharsetEncoder iso88591 = Charset.forName("ISO-8859-1").newEncoder(); + + // sun.nio.cs.SingleByte + private CharsetEncoder iso88592 = Charset.forName("ISO-8859-2").newEncoder(); + + // sun.nio.cs.DoubleByte + private CharsetEncoder shiftjis = Charset.forName("Shift_JIS").newEncoder(); + + // sun.nio.cs.UTF_8 + private CharsetEncoder utf8 = Charset.forName("UTF-8").newEncoder(); + + // sun.nio.cs.UTF_16LE + private CharsetEncoder utf16le = Charset.forName("UTF-16LE").newEncoder(); + + @Benchmark + public boolean asciiCanEncodeCharYes() { + return ascii.canEncode('D'); + } + + @Benchmark + public boolean asciiCanEncodeStringYes() { + return ascii.canEncode("D"); + } + + @Benchmark + public boolean asciiCanEncodeCharNo() { + return ascii.canEncode(ALEF_CHAR); + } + + @Benchmark + public boolean asciiCanEncodeStringNo() { + return ascii.canEncode(ALEF_STRING); + } + + @Benchmark + public boolean iso88591CanEncodeCharYes() { + return iso88591.canEncode('D'); + } + + @Benchmark + public boolean iso88591CanEncodeStringYes() { + return iso88591.canEncode("D"); + } + + @Benchmark + public boolean iso88591CanEncodeCharNo() { + return iso88591.canEncode(ALEF_CHAR); + } + + @Benchmark + public boolean iso88591CanEncodeStringNo() { + return iso88591.canEncode(ALEF_STRING); + } + + @Benchmark + public boolean iso88592CanEncodeCharYes() { + return iso88592.canEncode('D'); + } + + @Benchmark + public boolean iso88592CanEncodeStringYes() { + return iso88592.canEncode("D"); + } + + @Benchmark + public boolean iso88592CanEncodeCharNo() { + return iso88592.canEncode(ALEF_CHAR); + } + + @Benchmark + public boolean iso88592CanEncodeStringNo() { + return iso88592.canEncode(ALEF_STRING); + } + + @Benchmark + public boolean shiftjisCanEncodeCharYes() { + return shiftjis.canEncode('D'); + } + + @Benchmark + public boolean shiftjisCanEncodeStringYes() { + return shiftjis.canEncode("D"); + } + + @Benchmark + public boolean shiftjisCanEncodeCharNo() { + return shiftjis.canEncode(ALEF_CHAR); + } + + @Benchmark + public boolean shiftjisCanEncodeStringNo() { + return shiftjis.canEncode(ALEF_STRING); + } + + @Benchmark + public boolean utf8CanEncodeCharYes() { + return utf8.canEncode('D'); + } + + @Benchmark + public boolean utf8CanEncodeStringYes() { + return utf8.canEncode("D"); + } + + @Benchmark + public boolean utf8CanEncodeCharNo() { + return utf8.canEncode(Character.MIN_SURROGATE); + } + + @Benchmark + public boolean utf8CanEncodeStringNo() { + return utf8.canEncode(String.valueOf(Character.MIN_SURROGATE)); + } + + @Benchmark + public boolean utf16leCanEncodeCharYes() { + return utf16le.canEncode('D'); + } + + @Benchmark + public boolean utf16leCanEncodeStringYes() { + return utf16le.canEncode("D"); + } + + @Benchmark + public boolean utf16leCanEncodeCharNo() { + return utf16le.canEncode(Character.MIN_SURROGATE); + } + + @Benchmark + public boolean utf16leCanEncodeStringNo() { + return utf16le.canEncode(String.valueOf(Character.MIN_SURROGATE)); + } +}