diff --git a/make/test/BuildMicrobenchmark.gmk b/make/test/BuildMicrobenchmark.gmk index 1052e422f7b..272cb1af0a6 100644 --- a/make/test/BuildMicrobenchmark.gmk +++ b/make/test/BuildMicrobenchmark.gmk @@ -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 @@ -96,8 +96,6 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \ --add-exports java.base/jdk.internal.foreign=ALL-UNNAMED \ --add-exports java.base/jdk.internal.misc=ALL-UNNAMED \ --add-exports java.base/jdk.internal.util=ALL-UNNAMED \ - --add-exports java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED \ - --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED \ --add-exports java.base/jdk.internal.vm=ALL-UNNAMED \ --add-exports java.base/sun.invoke.util=ALL-UNNAMED \ --add-exports java.base/sun.security.util=ALL-UNNAMED \ diff --git a/src/hotspot/cpu/riscv/compressedKlass_riscv.cpp b/src/hotspot/cpu/riscv/compressedKlass_riscv.cpp index 7e596e0a7e9..7d5f630d0aa 100644 --- a/src/hotspot/cpu/riscv/compressedKlass_riscv.cpp +++ b/src/hotspot/cpu/riscv/compressedKlass_riscv.cpp @@ -31,7 +31,7 @@ char* CompressedKlassPointers::reserve_address_space_for_compressed_classes(size char* result = nullptr; - // RiscV loads a 64-bit immediate in up to four separate steps, splitting it into four different sections + // RISC-V loads a 64-bit immediate in up to four separate steps, splitting it into four different sections // (two 32-bit sections, each split into two subsections of 20/12 bits). // // 63 ....... 44 43 ... 32 31 ....... 12 11 ... 0 @@ -51,11 +51,6 @@ char* CompressedKlassPointers::reserve_address_space_for_compressed_classes(size // with one instruction (2) result = reserve_address_space_for_unscaled_encoding(size, aslr); - // Failing that, attempt to reserve for base=zero shift>0 - if (result == nullptr && optimize_for_zero_base) { - result = reserve_address_space_for_zerobased_encoding(size, aslr); - } - // Failing that, optimize for case (3) - a base with only bits set between [32-44) if (result == nullptr) { const uintptr_t from = nth_bit(32); diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index 753160e7ec1..bd2f0508022 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -987,8 +987,10 @@ bool MetaspaceShared::try_link_class(JavaThread* current, InstanceKlass* ik) { ik->external_name()); CLEAR_PENDING_EXCEPTION; SystemDictionaryShared::set_class_has_failed_verification(ik); + } else { + assert(!SystemDictionaryShared::has_class_failed_verification(ik), "sanity"); + ik->compute_has_loops_flag_for_methods(); } - ik->compute_has_loops_flag_for_methods(); BytecodeVerificationLocal = saved; return true; } else { diff --git a/src/hotspot/share/compiler/compileBroker.cpp b/src/hotspot/share/compiler/compileBroker.cpp index 30956b6c793..67a48cfdd15 100644 --- a/src/hotspot/share/compiler/compileBroker.cpp +++ b/src/hotspot/share/compiler/compileBroker.cpp @@ -2532,6 +2532,11 @@ void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time // C1 and C2 counters are counting both successful and unsuccessful compiles _t_total_compilation.add(time); + // Update compilation times. Used by the implementation of JFR CompilerStatistics + // and java.lang.management.CompilationMXBean. + _perf_total_compilation->inc(time.ticks()); + _peak_compilation_time = MAX2(time.milliseconds(), _peak_compilation_time); + if (!success) { _total_bailout_count++; if (UsePerfData) { @@ -2550,12 +2555,6 @@ void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time _t_invalidated_compilation.add(time); } else { // Compilation succeeded - - // update compilation ticks - used by the implementation of - // java.lang.management.CompilationMXBean - _perf_total_compilation->inc(time.ticks()); - _peak_compilation_time = time.milliseconds() > _peak_compilation_time ? time.milliseconds() : _peak_compilation_time; - if (CITime) { int bytes_compiled = method->code_size() + task->num_inlined_bytecodes(); if (is_osr) { diff --git a/src/hotspot/share/gc/shenandoah/shenandoahWorkGroup.cpp b/src/hotspot/share/gc/shenandoah/shenandoahWorkGroup.cpp index 4a49d28ea86..c9dbe5f4024 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahWorkGroup.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahWorkGroup.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2017, 2021, Red Hat, Inc. All rights reserved. + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,7 +74,6 @@ ShenandoahPushWorkerScope::~ShenandoahPushWorkerScope() { } void ShenandoahWorkerThreads::on_create_worker(WorkerThread* worker) { - ShenandoahThreadLocalData::create(worker); if (_initialize_gclab) { ShenandoahThreadLocalData::initialize_gclab(worker); } diff --git a/src/hotspot/share/opto/vectornode.cpp b/src/hotspot/share/opto/vectornode.cpp index 33429dfacad..e62524b37cd 100644 --- a/src/hotspot/share/opto/vectornode.cpp +++ b/src/hotspot/share/opto/vectornode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -666,7 +666,7 @@ VectorNode* VectorNode::make_mask_node(int vopc, Node* n1, Node* n2, uint vlen, } } -// Make a vector node for binary operation +// Make a vector node for unary or binary operation VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, const TypeVect* vt, bool is_mask, bool is_var_shift, bool is_unsigned) { // This method should not be called for unimplemented vectors. guarantee(vopc > 0, "vopc must be > 0"); @@ -747,6 +747,9 @@ VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, const TypeVect* vt, b case Op_URShiftVI: return new URShiftVINode(n1, n2, vt, is_var_shift); case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt, is_var_shift); + case Op_LShiftCntV: return new LShiftCntVNode(n1, vt); + case Op_RShiftCntV: return new RShiftCntVNode(n1, vt); + case Op_AndV: return new AndVNode(n1, n2, vt); case Op_OrV: return new OrVNode (n1, n2, vt); case Op_XorV: return new XorVNode(n1, n2, vt); @@ -766,6 +769,18 @@ VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, const TypeVect* vt, b case Op_SaturatingAddV: return new SaturatingAddVNode(n1, n2, vt, is_unsigned); case Op_SaturatingSubV: return new SaturatingSubVNode(n1, n2, vt, is_unsigned); + case Op_VectorCastB2X: return new VectorCastB2XNode(n1, vt); + case Op_VectorCastS2X: return new VectorCastS2XNode(n1, vt); + case Op_VectorCastI2X: return new VectorCastI2XNode(n1, vt); + case Op_VectorCastL2X: return new VectorCastL2XNode(n1, vt); + case Op_VectorCastF2X: return new VectorCastF2XNode(n1, vt); + case Op_VectorCastD2X: return new VectorCastD2XNode(n1, vt); + case Op_VectorUCastB2X: return new VectorUCastB2XNode(n1, vt); + case Op_VectorUCastS2X: return new VectorUCastS2XNode(n1, vt); + case Op_VectorUCastI2X: return new VectorUCastI2XNode(n1, vt); + case Op_VectorCastHF2F: return new VectorCastHF2FNode(n1, vt); + case Op_VectorCastF2HF: return new VectorCastF2HFNode(n1, vt); + default: fatal("Missed vector creation for '%s'", NodeClassNames[vopc]); return nullptr; @@ -791,6 +806,7 @@ VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, Node* n3, const TypeV case Op_SelectFromTwoVector: return new SelectFromTwoVectorNode(n1, n2, n3, vt); case Op_SignumVD: return new SignumVDNode(n1, n2, n3, vt); case Op_SignumVF: return new SignumVFNode(n1, n2, n3, vt); + case Op_VectorBlend: return new VectorBlendNode(n1, n2, n3); default: fatal("Missed vector creation for '%s'", NodeClassNames[vopc]); return nullptr; @@ -818,22 +834,26 @@ VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, BasicType bt, bool is_ } VectorNode* VectorNode::shift_count(int opc, Node* cnt, uint vlen, BasicType bt) { - // Match shift count type with shift vector type. + int vopc = VectorNode::shift_count_opcode(opc); const TypeVect* vt = TypeVect::make(bt, vlen); + return VectorNode::make(vopc, cnt, nullptr, vt); +} + +int VectorNode::shift_count_opcode(int opc) { switch (opc) { case Op_LShiftI: case Op_LShiftL: - return new LShiftCntVNode(cnt, vt); + return Op_LShiftCntV; case Op_RShiftI: case Op_RShiftL: case Op_URShiftB: case Op_URShiftS: case Op_URShiftI: case Op_URShiftL: - return new RShiftCntVNode(cnt, vt); + return Op_RShiftCntV; default: - fatal("Missed vector creation for '%s'", NodeClassNames[opc]); - return nullptr; + fatal("Node class '%s' is not supported for shift count", NodeClassNames[opc]); + return -1; } } @@ -1412,24 +1432,9 @@ VectorStoreMaskNode* VectorStoreMaskNode::make(PhaseGVN& gvn, Node* in, BasicTyp return new VectorStoreMaskNode(in, gvn.intcon(elem_size), vt); } -VectorCastNode* VectorCastNode::make(int vopc, Node* n1, BasicType bt, uint vlen) { +VectorNode* VectorCastNode::make(int vopc, Node* n1, BasicType bt, uint vlen) { const TypeVect* vt = TypeVect::make(bt, vlen); - switch (vopc) { - case Op_VectorCastB2X: return new VectorCastB2XNode(n1, vt); - case Op_VectorCastS2X: return new VectorCastS2XNode(n1, vt); - case Op_VectorCastI2X: return new VectorCastI2XNode(n1, vt); - case Op_VectorCastL2X: return new VectorCastL2XNode(n1, vt); - case Op_VectorCastF2X: return new VectorCastF2XNode(n1, vt); - case Op_VectorCastD2X: return new VectorCastD2XNode(n1, vt); - case Op_VectorUCastB2X: return new VectorUCastB2XNode(n1, vt); - case Op_VectorUCastS2X: return new VectorUCastS2XNode(n1, vt); - case Op_VectorUCastI2X: return new VectorUCastI2XNode(n1, vt); - case Op_VectorCastHF2F: return new VectorCastHF2FNode(n1, vt); - case Op_VectorCastF2HF: return new VectorCastF2HFNode(n1, vt); - default: - assert(false, "unknown node: %s", NodeClassNames[vopc]); - return nullptr; - } + return VectorNode::make(vopc, n1, nullptr, vt); } int VectorCastNode::opcode(int sopc, BasicType bt, bool is_signed) { diff --git a/src/hotspot/share/opto/vectornode.hpp b/src/hotspot/share/opto/vectornode.hpp index f5574ba79e3..0bd1c71d7e6 100644 --- a/src/hotspot/share/opto/vectornode.hpp +++ b/src/hotspot/share/opto/vectornode.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -95,6 +95,8 @@ class VectorNode : public TypeNode { static int opcode(int sopc, BasicType bt); // scalar_opc -> vector_opc static int scalar_opcode(int vopc, BasicType bt); // vector_opc -> scalar_opc + static int shift_count_opcode(int opc); + // Limits on vector size (number of elements) for auto-vectorization. static bool vector_size_supported_auto_vectorization(const BasicType bt, int size); static bool implemented(int opc, uint vlen, BasicType bt); @@ -1764,7 +1766,7 @@ class VectorCastNode : public VectorNode { VectorCastNode(Node* in, const TypeVect* vt) : VectorNode(in, vt) {} virtual int Opcode() const; - static VectorCastNode* make(int vopc, Node* n1, BasicType bt, uint vlen); + static VectorNode* make(int vopc, Node* n1, BasicType bt, uint vlen); static int opcode(int opc, BasicType bt, bool is_signed = true); static bool implemented(int opc, uint vlen, BasicType src_type, BasicType dst_type); diff --git a/src/java.base/share/classes/java/time/ZoneOffset.java b/src/java.base/share/classes/java/time/ZoneOffset.java index 14ac5fcfb6b..520a0e0b9a1 100644 --- a/src/java.base/share/classes/java/time/ZoneOffset.java +++ b/src/java.base/share/classes/java/time/ZoneOffset.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -424,11 +424,17 @@ public static ZoneOffset ofTotalSeconds(int totalSeconds) { throw new DateTimeException("Zone offset not in valid range: -18:00 to +18:00"); } if (totalSeconds % (15 * SECONDS_PER_MINUTE) == 0) { - return SECONDS_CACHE.computeIfAbsent(totalSeconds, totalSecs -> { - ZoneOffset result = new ZoneOffset(totalSecs); + Integer totalSecs = totalSeconds; + ZoneOffset result = SECONDS_CACHE.get(totalSecs); + if (result == null) { + result = new ZoneOffset(totalSeconds); + var existing = SECONDS_CACHE.putIfAbsent(totalSecs, result); + if (existing != null) { + result = existing; + } ID_CACHE.putIfAbsent(result.getId(), result); - return result; - }); + } + return result; } else { return new ZoneOffset(totalSeconds); } diff --git a/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java b/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java index 5ee4c5c23c8..5be33551c70 100644 --- a/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java +++ b/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 @@ -309,7 +309,15 @@ public Iterator> getTextIterator(Chronology chrono, Temporal private Object findStore(TemporalField field, Locale locale) { Entry key = createEntry(field, locale); - return CACHE.computeIfAbsent(key, e -> createStore(e.getKey(), e.getValue())); + Object store = CACHE.get(key); + if (store == null) { + store = createStore(field, locale); + var existing = CACHE.putIfAbsent(key, store); + if (existing != null) { + store = existing; + } + } + return store; } private static int toWeekDay(int calWeekDay) { diff --git a/src/java.base/share/classes/java/time/format/DecimalStyle.java b/src/java.base/share/classes/java/time/format/DecimalStyle.java index b2513888790..a9ad8a4e273 100644 --- a/src/java.base/share/classes/java/time/format/DecimalStyle.java +++ b/src/java.base/share/classes/java/time/format/DecimalStyle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 @@ -160,7 +160,15 @@ public static DecimalStyle ofDefaultLocale() { */ public static DecimalStyle of(Locale locale) { Objects.requireNonNull(locale, "locale"); - return CACHE.computeIfAbsent(locale, DecimalStyle::create); + DecimalStyle info = CACHE.get(locale); + if (info == null) { + info = create(locale); + var existing = CACHE.putIfAbsent(locale, info); + if (existing != null) { + info = existing; + } + } + return info; } private static DecimalStyle create(Locale locale) { diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index 2904f665732..66e6267367c 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.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 @@ -197,14 +197,6 @@ jdk.jlink; exports jdk.internal.logger to java.logging; - exports jdk.internal.org.objectweb.asm to - jdk.jfr; - exports jdk.internal.org.objectweb.asm.tree to - jdk.jfr; - exports jdk.internal.org.objectweb.asm.util to - jdk.jfr; - exports jdk.internal.org.objectweb.asm.commons to - jdk.jfr; exports jdk.internal.org.xml.sax to jdk.jfr; exports jdk.internal.org.xml.sax.helpers to diff --git a/src/java.base/share/classes/sun/nio/ch/ThreadPool.java b/src/java.base/share/classes/sun/nio/ch/ThreadPool.java index 92aee323823..38a49567c15 100644 --- a/src/java.base/share/classes/sun/nio/ch/ThreadPool.java +++ b/src/java.base/share/classes/sun/nio/ch/ThreadPool.java @@ -70,7 +70,7 @@ int poolSize() { static ThreadFactory defaultThreadFactory() { return (Runnable r) -> { - Thread t = new Thread(r); + Thread t = InnocuousThread.newThread(r); t.setDaemon(true); return t; }; diff --git a/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java b/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java index e2ac950f01d..29c07223988 100644 --- a/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java +++ b/src/java.base/share/classes/sun/nio/fs/AbstractPoller.java @@ -25,9 +25,10 @@ package sun.nio.fs; -import java.nio.file.*; import java.io.IOException; +import java.nio.file.*; import java.util.*; +import jdk.internal.misc.InnocuousThread; /** * Base implementation of background poller thread used in watch service @@ -53,11 +54,7 @@ protected AbstractPoller() { * Starts the poller thread */ public void start() { - Thread thr = new Thread(null, - this, - "FileSystemWatchService", - 0, - false); + Thread thr = InnocuousThread.newThread("FileSystemWatchService", this); thr.setDaemon(true); thr.start(); } diff --git a/src/java.base/share/classes/sun/nio/fs/Cancellable.java b/src/java.base/share/classes/sun/nio/fs/Cancellable.java index 5e3ff43a7b0..df3c95abcc9 100644 --- a/src/java.base/share/classes/sun/nio/fs/Cancellable.java +++ b/src/java.base/share/classes/sun/nio/fs/Cancellable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved. * 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 @@ package sun.nio.fs; -import jdk.internal.misc.Unsafe; import java.util.concurrent.ExecutionException; +import jdk.internal.misc.InnocuousThread; +import jdk.internal.misc.Unsafe; /** * Base implementation of a task (typically native) that polls a memory location * during execution so that it may be aborted/cancelled before completion. The - * task is executed by invoking the {@link runInterruptibly} method defined - * here and cancelled by invoking Thread.interrupt. + * task is executed by invoking the {@linkplain #runInterruptibly} method + * defined here and cancelled by invoking Thread.interrupt. */ abstract class Cancellable implements Runnable { @@ -117,7 +118,7 @@ public final void run() { * thread by writing into the memory location that it polls cooperatively. */ static void runInterruptibly(Cancellable task) throws ExecutionException { - Thread t = new Thread(null, task, "NIO-Task", 0, false); + Thread t = InnocuousThread.newThread("CancellableOp", task); t.start(); boolean cancelledByInterrupt = false; while (t.isAlive()) { diff --git a/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java b/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java index 0284156ca3b..da486231a1d 100644 --- a/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java +++ b/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java @@ -47,6 +47,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; +import jdk.internal.misc.InnocuousThread; import static java.nio.file.LinkOption.NOFOLLOW_LINKS; /** @@ -73,7 +74,7 @@ class PollingWatchService .newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { - Thread t = new Thread(null, r, "FileSystemWatcher", 0, false); + Thread t = InnocuousThread.newThread("FileSystemWatcher", r); t.setDaemon(true); return t; }}); diff --git a/src/java.base/windows/classes/sun/nio/ch/PipeImpl.java b/src/java.base/windows/classes/sun/nio/ch/PipeImpl.java index 7e138a5cc11..1e4b6a05ce1 100644 --- a/src/java.base/windows/classes/sun/nio/ch/PipeImpl.java +++ b/src/java.base/windows/classes/sun/nio/ch/PipeImpl.java @@ -78,7 +78,7 @@ public void init() throws IOException { connector.run(); if (ioe instanceof ClosedByInterruptException) { ioe = null; - Thread connThread = new Thread(connector) { + Thread connThread = new Thread(connector, "LoopbackConnector") { @Override public void interrupt() {} }; diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java index 79c86de16c6..19d77115025 100644 --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -621,7 +621,6 @@ public void installComponents(JFileChooser fc) { fc.add(interior, BorderLayout.CENTER); - @SuppressWarnings("serial") // anonymous class JPanel comboBoxPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0) { public void layoutContainer(Container target) { @@ -733,7 +732,6 @@ public void layoutContainer(Container target) { if (currentDirectory != null) { curDirName = currentDirectory.getPath(); } - @SuppressWarnings("serial") // anonymous class JLabel tmp = new JLabel(curDirName) { public Dimension getMaximumSize() { Dimension d = super.getMaximumSize(); @@ -748,7 +746,6 @@ public Dimension getMaximumSize() { interior.add(pathFieldPanel); // add the fileName field - @SuppressWarnings("serial") // anonymous class JTextField tmp2 = new JTextField() { public Dimension getMaximumSize() { Dimension d = super.getMaximumSize(); diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java index 79d6965e05f..42e684bfac7 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -168,7 +168,6 @@ public boolean isReparentSupported() { return System.getProperty("sun.awt.X11.XComponentPeer.reparentNotSupported", "false").equals("false"); } - @SuppressWarnings("deprecation") public boolean isObscured() { Container container = (target instanceof Container) ? (Container)target : target.getParent(); @@ -244,7 +243,6 @@ static final AWTEvent wrapInSequenced(AWTEvent event) { } // TODO: consider moving it to KeyboardFocusManagerPeerImpl - @SuppressWarnings("deprecation") public final boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time, FocusEvent.Cause cause) diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XFileDialogPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XFileDialogPeer.java index 98caf9f43cf..5c6fde2251c 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XFileDialogPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XFileDialogPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -197,7 +197,6 @@ private void init(FileDialog target) { // After showing we should display 'user.dir' as current directory // if user didn't set directory programmatically pathField = new TextField(savedDir != null ? savedDir : userDir); - @SuppressWarnings("serial") // Anonymous class Choice tmp = new Choice() { public Dimension getPreferredSize() { return new Dimension(PATH_CHOICE_WIDTH, pathField.getPreferredSize().height); @@ -778,7 +777,6 @@ public void dispose() { } // 03/02/2005 b5097243 Pressing 'ESC' on a file dlg does not dispose the dlg on Xtoolkit - @SuppressWarnings("deprecation") public void setVisible(boolean b){ if (fileDialog == null) { init(target); diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XFramePeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XFramePeer.java index c7f3ba95bc1..acbe8639702 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XFramePeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XFramePeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -137,7 +137,6 @@ void setupState(boolean onInit) { setExtendedState(state); } - @SuppressWarnings("deprecation") public void setMenuBar(MenuBar mb) { // state_lock should always be the second after awt_lock XToolkit.awtLock(); diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java index f4c46c2766d..321cb4fbf1e 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XMouseInfoPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -83,7 +83,6 @@ public int fillPointWithCoords(Point point) { return 0; } - @SuppressWarnings("deprecation") public boolean isWindowUnderMouse(Window w) { if (w == null) { return false; diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java index a37e82d2273..cda05e0a6c7 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -214,7 +214,6 @@ protected String getWMName() { private static native String getLocalHostname(); private static native int getJvmPID(); - @SuppressWarnings("deprecation") void postInit(XCreateWindowParams params) { super.postInit(params); diff --git a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java index 41fa0c3f048..7065e3db19b 100644 --- a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java +++ b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -273,7 +273,6 @@ public void installComponents(JFileChooser fc) { fc.add(topPanel, BorderLayout.NORTH); // ComboBox Label - @SuppressWarnings("serial") // anonymous class JLabel tmp1 = new JLabel(lookInLabelText, JLabel.TRAILING) { public Dimension getPreferredSize() { return getMinimumSize(); @@ -295,7 +294,6 @@ public Dimension getMinimumSize() { topPanel.add(Box.createRigidArea(new Dimension(8,0))); // CurrentDir ComboBox - @SuppressWarnings("serial") // anonymous class JComboBox tmp2 = new JComboBox() { public Dimension getMinimumSize() { Dimension d = super.getMinimumSize(); @@ -477,7 +475,6 @@ public void propertyChange(PropertyChangeEvent e) { fileAndFilterPanel.add(Box.createRigidArea(vstrut8)); fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS)); - @SuppressWarnings("serial") // anonymous class JTextField tmp3 = new JTextField(35) { public Dimension getMaximumSize() { return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height); @@ -518,7 +515,6 @@ public void focusGained(FocusEvent e) { // buttons getButtonPanel().setLayout(new BoxLayout(getButtonPanel(), BoxLayout.Y_AXIS)); - @SuppressWarnings("serial") // anonymous class JButton tmp4 = new JButton(getApproveButtonText(fc)) { public Dimension getMaximumSize() { return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ? @@ -537,7 +533,6 @@ public Dimension getMaximumSize() { getButtonPanel().add(approveButton); getButtonPanel().add(Box.createRigidArea(vstrut4)); - @SuppressWarnings("serial") // anonymous class JButton tmp5 = new JButton(cancelButtonText) { public Dimension getMaximumSize() { return approveButton.getPreferredSize().width > cancelButton.getPreferredSize().width ? @@ -974,7 +969,6 @@ protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser return new DirectoryComboBoxRenderer(); } - @SuppressWarnings("serial") // anonymous class private static JButton createToolButton(Action a, Icon defaultIcon, String toolTipText, String accessibleName) { final JButton result = new JButton(a); diff --git a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java index cd0987a9079..083563b4464 100644 --- a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java +++ b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -289,7 +289,6 @@ protected void assembleSystemMenu() { systemPopupMenu = new JPopupMenu(); addSystemMenuItems(systemPopupMenu); enableActions(); - @SuppressWarnings("serial") // anonymous class JLabel tmp = new JLabel(frame.getFrameIcon()) { protected void paintComponent(Graphics g) { int x = 0; diff --git a/src/java.desktop/windows/classes/sun/awt/windows/WDialogPeer.java b/src/java.desktop/windows/classes/sun/awt/windows/WDialogPeer.java index 930064d5981..a02bceae7fb 100644 --- a/src/java.desktop/windows/classes/sun/awt/windows/WDialogPeer.java +++ b/src/java.desktop/windows/classes/sun/awt/windows/WDialogPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -94,7 +94,6 @@ protected void realShow() { } @Override - @SuppressWarnings("deprecation") void hide() { Dialog dlg = (Dialog)target; if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java index e28c0fe60f8..1131800f8ed 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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,16 +30,17 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Stream; -import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.main.Option; +import com.sun.tools.javac.tree.JCTree.*; +import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.LintWarning; -import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Log; +import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Options; -import com.sun.tools.javac.util.Pair; /** * A class for handling -Xlint suboptions and @SuppressWarnings. @@ -49,8 +50,8 @@ * This code and its internal interfaces are subject to change or * deletion without notice. */ -public class Lint -{ +public class Lint { + /** The context key for the root Lint object. */ protected static final Context.Key lintKey = new Context.Key<>(); @@ -63,26 +64,35 @@ public static Lint instance(Context context) { } /** - * Returns the result of combining the values in this object with - * the given annotation. + * Obtain an instance with additional warning supression applied from any + * @SuppressWarnings and/or @Deprecated annotations on the given symbol. + * + *

+ * The returned instance will be different from this instance if and only if + * {@link #suppressionsFrom} returns a non-empty set. + * + * @param sym symbol + * @return lint instance with new warning suppressions applied, or this instance if none */ - public Lint augment(Attribute.Compound attr) { - return augmentor.augment(this, attr); + public Lint augment(Symbol sym) { + EnumSet suppressions = suppressionsFrom(sym); + if (!suppressions.isEmpty()) { + Lint lint = new Lint(this); + lint.values.removeAll(suppressions); + lint.suppressedValues.addAll(suppressions); + return lint; + } + return this; } - /** - * Returns the result of combining the values in this object with - * the metadata on the given symbol. + * Returns a new Lint that has the given LintCategorys enabled. + * @param lc one or more categories to be enabled */ - public Lint augment(Symbol sym) { - Lint l = augmentor.augment(this, sym.getDeclarationAttributes()); - if (sym.isDeprecated() && sym.isDeprecatableViaAnnotation()) { - if (l == this) - l = new Lint(this); - l.values.remove(LintCategory.DEPRECATION); - l.suppressedValues.add(LintCategory.DEPRECATION); - } + public Lint enable(LintCategory... lc) { + Lint l = new Lint(this); + l.values.addAll(Arrays.asList(lc)); + l.suppressedValues.removeAll(Arrays.asList(lc)); return l; } @@ -97,8 +107,13 @@ public Lint suppress(LintCategory... lc) { return l; } - private final AugmentVisitor augmentor; + private final Context context; + + // These are initialized lazily to avoid dependency loops + private Symtab syms; + private Names names; + // Invariant: it's never the case that a category is in both "values" and "suppressedValues" private final EnumSet values; private final EnumSet suppressedValues; @@ -114,10 +129,10 @@ protected Lint(Context context) { values = EnumSet.allOf(LintCategory.class); } else if (options.isSet(Option.XLINT_CUSTOM, "none")) { // if -Xlint:none is given, disable all categories by default - values = EnumSet.noneOf(LintCategory.class); + values = LintCategory.newEmptySet(); } else { // otherwise, enable on-by-default categories - values = EnumSet.noneOf(LintCategory.class); + values = LintCategory.newEmptySet(); Source source = Source.instance(context); if (source.compareTo(Source.JDK9) >= 0) { @@ -146,21 +161,23 @@ protected Lint(Context context) { } } - suppressedValues = EnumSet.noneOf(LintCategory.class); + suppressedValues = LintCategory.newEmptySet(); + this.context = context; context.put(lintKey, this); - augmentor = new AugmentVisitor(context); } protected Lint(Lint other) { - this.augmentor = other.augmentor; + this.context = other.context; + this.syms = other.syms; + this.names = other.names; this.values = other.values.clone(); this.suppressedValues = other.suppressedValues.clone(); } @Override public String toString() { - return "Lint:[values" + values + " suppressedValues" + suppressedValues + "]"; + return "Lint:[enable" + values + ",suppress" + suppressedValues + "]"; } /** @@ -373,6 +390,11 @@ public static Optional get(String option) { return Optional.ofNullable(map.get(option)); } + public static EnumSet newEmptySet() { + return EnumSet.noneOf(LintCategory.class); + } + + /** Get the string representing this category in @SuppressAnnotations and -Xlint options. */ public final String option; } @@ -404,82 +426,64 @@ public void logIfEnabled(Log log, DiagnosticPosition pos, LintWarning warning) { } } - protected static class AugmentVisitor implements Attribute.Visitor { - private final Context context; - private Symtab syms; - private Lint parent; - private Lint lint; - - AugmentVisitor(Context context) { - // to break an ugly sequence of initialization dependencies, - // we defer the initialization of syms until it is needed - this.context = context; - } - - Lint augment(Lint parent, Attribute.Compound attr) { - initSyms(); - this.parent = parent; - lint = null; - attr.accept(this); - return (lint == null ? parent : lint); - } - - Lint augment(Lint parent, List attrs) { - initSyms(); - this.parent = parent; - lint = null; - for (Attribute.Compound a: attrs) { - a.accept(this); - } - return (lint == null ? parent : lint); - } - - private void initSyms() { - if (syms == null) - syms = Symtab.instance(context); - } - - private void suppress(LintCategory lc) { - if (lint == null) - lint = new Lint(parent); - lint.suppressedValues.add(lc); - lint.values.remove(lc); - } - - public void visitConstant(Attribute.Constant value) { - if (value.type.tsym == syms.stringType.tsym) { - LintCategory.get((String)value.value) - .ifPresent(this::suppress); - } - } - - public void visitClass(Attribute.Class clazz) { - } - - // If we find a @SuppressWarnings annotation, then we continue - // walking the tree, in order to suppress the individual warnings - // specified in the @SuppressWarnings annotation. - public void visitCompound(Attribute.Compound compound) { - if (compound.type.tsym == syms.suppressWarningsType.tsym) { - for (List> v = compound.values; - v.nonEmpty(); v = v.tail) { - Pair value = v.head; - if (value.fst.name.toString().equals("value")) - value.snd.accept(this); - } + /** + * Obtain the set of recognized lint warning categories suppressed at the given symbol's declaration. + * + *

+ * This set can be non-empty only if the symbol is annotated with either + * @SuppressWarnings or @Deprecated. + * + * @param symbol symbol corresponding to a possibly-annotated declaration + * @return new warning suppressions applied to sym + */ + public EnumSet suppressionsFrom(Symbol symbol) { + EnumSet suppressions = suppressionsFrom(symbol.getDeclarationAttributes().stream()); + if (symbol.isDeprecated() && symbol.isDeprecatableViaAnnotation()) + suppressions.add(LintCategory.DEPRECATION); + return suppressions; + } - } - } + /** + * Retrieve the recognized lint categories suppressed by the given @SuppressWarnings annotation. + * + * @param annotation @SuppressWarnings annotation, or null + * @return set of lint categories, possibly empty but never null + */ + private EnumSet suppressionsFrom(JCAnnotation annotation) { + initializeIfNeeded(); + if (annotation == null) + return LintCategory.newEmptySet(); + Assert.check(annotation.attribute.type.tsym == syms.suppressWarningsType.tsym); + return suppressionsFrom(Stream.of(annotation).map(anno -> anno.attribute)); + } - public void visitArray(Attribute.Array array) { - for (Attribute value : array.values) - value.accept(this); - } + // Find the @SuppressWarnings annotation in the given stream and extract the recognized suppressions + private EnumSet suppressionsFrom(Stream attributes) { + initializeIfNeeded(); + EnumSet result = LintCategory.newEmptySet(); + attributes + .filter(attribute -> attribute.type.tsym == syms.suppressWarningsType.tsym) + .map(this::suppressionsFrom) + .forEach(result::addAll); + return result; + } - public void visitEnum(Attribute.Enum e) { + // Given a @SuppressWarnings annotation, extract the recognized suppressions + private EnumSet suppressionsFrom(Attribute.Compound suppressWarnings) { + EnumSet result = LintCategory.newEmptySet(); + Attribute.Array values = (Attribute.Array)suppressWarnings.member(names.value); + for (Attribute value : values.values) { + Optional.of((String)((Attribute.Constant)value).value) + .flatMap(LintCategory::get) + .ifPresent(result::add); } + return result; + } - public void visitError(Attribute.Error e) { + private void initializeIfNeeded() { + if (syms == null) { + syms = Symtab.instance(context); + names = Names.instance(context); } } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index a5b4186659b..a76dab2bb31 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -2945,11 +2945,19 @@ boolean potentiallyAmbiguousOverload(Type site, MethodSymbol msym1, MethodSymbol return potentiallyAmbiguous; } + // Apply special flag "-XDwarnOnAccessToMembers" which turns on just this particular warning for all types of access void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) { - if (warnOnAnyAccessToMembers || - (lint.isEnabled(LintCategory.SERIAL) && - !lint.isSuppressed(LintCategory.SERIAL) && - isLambda)) { + final Lint prevLint = setLint(warnOnAnyAccessToMembers ? lint.enable(LintCategory.SERIAL) : lint); + try { + if (warnOnAnyAccessToMembers || isLambda) + checkAccessFromSerializableElementInner(tree, isLambda); + } finally { + setLint(prevLint); + } + } + + private void checkAccessFromSerializableElementInner(final JCTree tree, boolean isLambda) { + if (lint.isEnabled(LintCategory.SERIAL)) { Symbol sym = TreeInfo.symbol(tree); if (!sym.kind.matches(KindSelector.VAL_MTH)) { return; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/CompileStates.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/CompileStates.java index b9cab47d8ab..4896ecbe728 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/CompileStates.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/CompileStates.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 @@ -58,11 +58,12 @@ public enum CompileState { PROCESS(3), ATTR(4), FLOW(5), - TRANSTYPES(6), - TRANSPATTERNS(7), - LOWER(8), - UNLAMBDA(9), - GENERATE(10); + WARN(6), + TRANSTYPES(7), + TRANSPATTERNS(8), + LOWER(9), + UNLAMBDA(10), + GENERATE(11); CompileState(int value) { this.value = value; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java index 175cceeeb7f..b0b79104def 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -229,7 +229,6 @@ public void analyzeTree(Env env, TreeMaker make) { new AssignAnalyzer().analyzeTree(env, make); new FlowAnalyzer().analyzeTree(env, make); new CaptureAnalyzer().analyzeTree(env, make); - new ThisEscapeAnalyzer(names, syms, types, rs, log, lint).analyzeTree(env); } public void analyzeLambda(Env env, JCLambda that, TreeMaker make, boolean speculative) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index e1bf92a7f7b..77ddd5c6583 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -58,6 +58,7 @@ import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.Assert; +import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; @@ -140,8 +141,17 @@ *

  • We assume that native methods do not leak. *
  • We don't try to follow {@code super()} invocations; that's for the superclass analysis to handle. * + * + *

    This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. */ -class ThisEscapeAnalyzer extends TreeScanner { +public class ThisEscapeAnalyzer extends TreeScanner { + + protected static final Context.Key contextKey = new Context.Key<>(); + +// Other singletons we utilize private final Names names; private final Symtab syms; @@ -211,15 +221,24 @@ class ThisEscapeAnalyzer extends TreeScanner { */ private RefSet refs; -// Constructor +// Access - ThisEscapeAnalyzer(Names names, Symtab syms, Types types, Resolve rs, Log log, Lint lint) { - this.names = names; - this.syms = syms; - this.types = types; - this.rs = rs; - this.log = log; - this.lint = lint; + public static ThisEscapeAnalyzer instance(Context context) { + ThisEscapeAnalyzer instance = context.get(contextKey); + if (instance == null) + instance = new ThisEscapeAnalyzer(context); + return instance; + } + + @SuppressWarnings("this-escape") + protected ThisEscapeAnalyzer(Context context) { + context.put(contextKey, this); + names = Names.instance(context); + log = Log.instance(context); + syms = Symtab.instance(context); + types = Types.instance(context); + rs = Resolve.instance(context); + lint = Lint.instance(context); } // @@ -227,6 +246,24 @@ class ThisEscapeAnalyzer extends TreeScanner { // public void analyzeTree(Env env) { + try { + doAnalyzeTree(env); + } finally { + attrEnv = null; + methodMap.clear(); + nonPublicOuters.clear(); + targetClass = null; + warningList.clear(); + methodClass = null; + callStack.clear(); + invocations.clear(); + pendingWarning = null; + depth = -1; + refs = null; + } + } + + private void doAnalyzeTree(Env env) { // Sanity check Assert.check(checkInvariants(false, false)); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java index a0b1ef27255..fe4d3d62f3b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -1168,7 +1168,7 @@ private Type erasure(Type t) { private Env env; private static final String statePreviousToFlowAssertMsg = - "The current compile state [%s] of class %s is previous to FLOW"; + "The current compile state [%s] of class %s is previous to WARN"; void translateClass(ClassSymbol c) { Type st = types.supertype(c.type); @@ -1189,7 +1189,7 @@ void translateClass(ClassSymbol c) { * 1) has no compile state being it the most outer class. * We accept this condition for inner classes. * - * 2) has a compile state which is previous to Flow state. + * 2) has a compile state which is previous to WARN state. */ boolean envHasCompState = compileStates.get(myEnv) != null; if (!envHasCompState && c.outermostClass() == c) { @@ -1197,7 +1197,7 @@ void translateClass(ClassSymbol c) { } if (envHasCompState && - CompileState.FLOW.isAfter(compileStates.get(myEnv))) { + CompileState.WARN.isAfter(compileStates.get(myEnv))) { Assert.error(String.format(statePreviousToFlowAssertMsg, compileStates.get(myEnv), myEnv.enclClass.sym)); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/WarningAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/WarningAnalyzer.java new file mode 100644 index 00000000000..00d1de386db --- /dev/null +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/WarningAnalyzer.java @@ -0,0 +1,63 @@ +/* + * 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 com.sun.tools.javac.comp; + +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Log; + +/** This pass checks for various things to warn about. + * It runs after attribution and flow analysis. + * + *

    This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ +public class WarningAnalyzer { + + protected static final Context.Key contextKey = new Context.Key<>(); + + private final Log log; + private final ThisEscapeAnalyzer thisEscapeAnalyzer; + + public static WarningAnalyzer instance(Context context) { + WarningAnalyzer instance = context.get(contextKey); + if (instance == null) + instance = new WarningAnalyzer(context); + return instance; + } + + @SuppressWarnings("this-escape") + protected WarningAnalyzer(Context context) { + context.put(contextKey, this); + log = Log.instance(context); + thisEscapeAnalyzer = ThisEscapeAnalyzer.instance(context); + } + + public void analyzeTree(Env env) { + thisEscapeAnalyzer.analyzeTree(env); + } +} diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java index 646db6a6bf3..4a5370f7a14 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2019, 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 @@ -53,6 +53,7 @@ import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; +import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.main.OptionHelper; import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; @@ -90,10 +91,13 @@ public void setContext(Context context) { classLoaderClass = options.get("procloader"); // Detect Lint options, but use Options.isLintSet() to avoid initializing the Lint class - boolean warn = options.isLintSet("path"); + boolean warn = options.isLintSet(LintCategory.PATH.option); + boolean fileClashOption = options.isLintSet(LintCategory.OUTPUT_FILE_CLASH.option); locations.update(log, warn, FSInfo.instance(context)); + + // Only track file clashes if enabled synchronized (this) { - outputFilesWritten = options.isLintSet("output-file-clash") ? new HashSet<>() : null; + outputFilesWritten = fileClashOption ? new HashSet<>() : null; } // Setting this option is an indication that close() should defer actually closing diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java index 96cf4049533..05efcf7c041 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -306,6 +306,10 @@ else if (option.equals("class")) */ protected Flow flow; + /** The warning analyzer. + */ + protected WarningAnalyzer warningAnalyzer; + /** The modules visitor */ protected Modules modules; @@ -419,6 +423,7 @@ public JavaCompiler(Context context) { chk = Check.instance(context); gen = Gen.instance(context); flow = Flow.instance(context); + warningAnalyzer = WarningAnalyzer.instance(context); transTypes = TransTypes.instance(context); lower = Lower.instance(context); annotate = Annotate.instance(context); @@ -962,20 +967,20 @@ public void compile(Collection sourceFileObjects, if (!CompileState.ATTR.isAfter(shouldStopPolicyIfNoError)) { switch (compilePolicy) { case SIMPLE: - generate(desugar(flow(attribute(todo)))); + generate(desugar(warn(flow(attribute(todo))))); break; case BY_FILE: { Queue>> q = todo.groupByFile(); while (!q.isEmpty() && !shouldStop(CompileState.ATTR)) { - generate(desugar(flow(attribute(q.remove())))); + generate(desugar(warn(flow(attribute(q.remove()))))); } } break; case BY_TODO: while (!todo.isEmpty()) - generate(desugar(flow(attribute(todo.remove())))); + generate(desugar(warn(flow(attribute(todo.remove()))))); break; default: @@ -1435,6 +1440,56 @@ protected void flow(Env env, Queue> results) { } } + /** + * Check for various things to warn about. + * + * @return the list of attributed parse trees + */ + public Queue> warn(Queue> envs) { + ListBuffer> results = new ListBuffer<>(); + for (Env env: envs) { + warn(env, results); + } + return stopIfError(CompileState.WARN, results); + } + + /** + * Check for various things to warn about in an attributed parse tree. + */ + public Queue> warn(Env env) { + ListBuffer> results = new ListBuffer<>(); + warn(env, results); + return stopIfError(CompileState.WARN, results); + } + + /** + * Check for various things to warn about in an attributed parse tree. + */ + protected void warn(Env env, Queue> results) { + if (compileStates.isDone(env, CompileState.WARN)) { + results.add(env); + return; + } + + if (shouldStop(CompileState.WARN)) + return; + + if (verboseCompilePolicy) + printNote("[warn " + env.enclClass.sym + "]"); + JavaFileObject prev = log.useSource( + env.enclClass.sym.sourcefile != null ? + env.enclClass.sym.sourcefile : + env.toplevel.sourcefile); + try { + warningAnalyzer.analyzeTree(env); + compileStates.put(env, CompileState.WARN); + results.add(env); + } + finally { + log.useSource(prev); + } + } + private TaskEvent newAnalyzeTaskEvent(Env env) { JCCompilationUnit toplevel = env.toplevel; ClassSymbol sym; @@ -1493,6 +1548,10 @@ protected void desugar(final Env env, Queue, return; } + // Ensure the file has reached the WARN state + if (!compileStates.isDone(env, CompileState.WARN)) + warn(env); + /** * Ensure that superclasses of C are desugared before C itself. This is * required for two reasons: (i) as erasure (TransTypes) destroys @@ -1576,8 +1635,8 @@ public void visitSwitchExpression(JCSwitchExpression tree) { ScanNested scanner = new ScanNested(); scanner.scan(env.tree); for (Env dep: scanner.dependencies) { - if (!compileStates.isDone(dep, CompileState.FLOW)) - desugaredEnvs.put(dep, desugar(flow(attribute(dep)))); + if (!compileStates.isDone(dep, CompileState.WARN)) + desugaredEnvs.put(dep, desugar(warn(flow(attribute(dep))))); } //We need to check for error another time as more classes might diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index b25ca99eb88..2cec3549c7a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -219,12 +219,12 @@ protected void lexError(DiagnosticFlag flags, int pos, JCDiagnostic.Error key) { } /** - * Report an error at the given position using the provided arguments. + * Report a warning at the given position using the provided arguments. * * @param pos position in input buffer. * @param key error key to report. */ - protected void lexWarning(int pos, JCDiagnostic.Warning key) { + protected void lexWarning(int pos, JCDiagnostic.LintWarning key) { DiagnosticPosition dp = new SimpleDiagnosticPosition(pos) ; log.warning(dp, key); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Warner.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Warner.java index 7b993c1bf16..3da0be49d33 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Warner.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Warner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -42,8 +42,8 @@ public class Warner { private DiagnosticPosition pos = null; protected boolean warned = false; - private EnumSet nonSilentLintSet = EnumSet.noneOf(LintCategory.class); - private EnumSet silentLintSet = EnumSet.noneOf(LintCategory.class); + private EnumSet nonSilentLintSet = LintCategory.newEmptySet(); + private EnumSet silentLintSet = LintCategory.newEmptySet(); public DiagnosticPosition pos() { return pos; diff --git a/test/hotspot/jtreg/runtime/CompressedOops/CompressedCPUSpecificClassSpaceReservation.java b/test/hotspot/jtreg/runtime/CompressedOops/CompressedCPUSpecificClassSpaceReservation.java index 574a680aceb..48fc6699fa2 100644 --- a/test/hotspot/jtreg/runtime/CompressedOops/CompressedCPUSpecificClassSpaceReservation.java +++ b/test/hotspot/jtreg/runtime/CompressedOops/CompressedCPUSpecificClassSpaceReservation.java @@ -85,15 +85,8 @@ private static void do_test(boolean CDS) throws IOException { output.shouldContain(tryReserveFor16bitMoveIntoQ3); } else if (Platform.isRISCV64()) { output.shouldContain(tryReserveForUnscaled); // unconditionally - if (CDS) { - output.shouldNotContain(tryReserveForZeroBased); - // bits 32..44 - output.shouldContain("reserve_between (range [0x0000000100000000-0x0000100000000000)"); - } else { - output.shouldContain(tryReserveForZeroBased); - // bits 32..44, but not lower than zero-based limit - output.shouldContain("reserve_between (range [0x0000000800000000-0x0000100000000000)"); - } + // bits 32..44 + output.shouldContain("reserve_between (range [0x0000000100000000-0x0000100000000000)"); // bits 44..64 output.shouldContain("reserve_between (range [0x0000100000000000-0xffffffffffffffff)"); } else if (Platform.isS390x()) { diff --git a/test/hotspot/jtreg/runtime/cds/appcds/CreateAOTCacheVerifyError.java b/test/hotspot/jtreg/runtime/cds/appcds/CreateAOTCacheVerifyError.java new file mode 100644 index 00000000000..c478fad7cc2 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/CreateAOTCacheVerifyError.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * 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 8346457 + * @summary VM should not crash during AOT cache creation when encountering a + * class with VerifyError. + * @requires vm.cds + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds/test-classes + * @compile test-classes/BadLookupSwitch.jcod + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar badlookupswitch.jar BadLookupSwitch + * @run driver CreateAOTCacheVerifyError + */ + +import jdk.test.lib.helpers.ClassFileInstaller; +import jdk.test.lib.process.OutputAnalyzer; + +public class CreateAOTCacheVerifyError { + + public static void main(String[] args) throws Exception { + String appJar = ClassFileInstaller.getJarPath("badlookupswitch.jar"); + String classList[] = { BadLookupSwitch.class.getName() }; + OutputAnalyzer out = TestCommon.testDump(appJar, classList); + out.shouldContain("Preload Warning: Verification failed for BadLookupSwitch"); + out.shouldHaveExitValue(0); + } +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/test-classes/BadLookupSwitch.jcod b/test/hotspot/jtreg/runtime/cds/appcds/test-classes/BadLookupSwitch.jcod new file mode 100644 index 00000000000..4912479a8aa --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/test-classes/BadLookupSwitch.jcod @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * 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. + * + */ + +class BadLookupSwitch { + 0xCAFEBABE; + 0; + 50; + [] { // Constant Pool + ; // first element is empty + class #12; // #1 at 0x0A + class #15; // #2 at 0x0D + Method #2 #4; // #3 at 0x10 + NameAndType #6 #5; // #4 at 0x15 + Utf8 "()V"; // #5 at 0x1A + Utf8 ""; // #6 at 0x20 + Utf8 "Code"; // #7 at 0x29 + Utf8 "ConstantValue"; // #8 at 0x30 + Utf8 "Exceptions"; // #9 at 0x40 + Utf8 "LineNumberTable"; // #10 at 0x4D + Utf8 "LocalVariables"; // #11 at 0x5F + Utf8 "BadLookupSwitch"; // #12 at 0x70 + Utf8 "SourceFile"; // #13 at 0x76 + Utf8 "f.java"; // #14 at 0x83 + Utf8 "java/lang/Object"; // #15 at 0x8C + Utf8 "m"; // #16 at 0x9F + Utf8 "StackMapTable"; // #17 + } // Constant Pool + + 0x0020; // access + #1;// this_cpx + #2;// super_cpx + + [0] { // Interfaces + } // Interfaces + + [0] { // fields + } // fields + + [2] { // methods + { // Member at 0xAF + 0x0001; // access + #16; // name_cpx + #5; // sig_cpx + [] { // Attributes + Attr(#7) { // Code at 0xB7 + 1; // max_stack + 1; // max_locals + Bytes[29] { + 0x04AB00000000001B; // iconst_1; +/* right: + 0x0000000200000001; // lookupswitch 27 2 1 27 2 27; + 0x0000001B00000002; + 0x0000001B; +end right */ +// wrong: + 0x0000000200000002; // lookupswitch 27 2 2 27 1 27; + 0x0000001B00000001; + 0x0000001B; +// end wrong + 0xB1; // return + }; + [0] { // Traps + } // end Traps + [] { // Attributes + Attr(#17) { // StackMap + [] { // + 255b, 28, []{O,1}, []{}; + } + } // end StackMap + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member at 0xD6 + 0x0000; // access + #6; // name_cpx + #5; // sig_cpx + [1] { // Attributes + Attr(#7) { // Code at 0xDE + 1; // max_stack + 1; // max_locals + Bytes[5] { + 0x2AB70003B1; + }; + [0] { // Traps + } // end Traps + [] { // Attributes + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [] { // Attributes + } // Attributes +} // end class diff --git a/test/jdk/com/sun/jdi/ClassUnloadEventTest.java b/test/jdk/com/sun/jdi/ClassUnloadEventTest.java index cf77ba846ae..41b1bff5e42 100644 --- a/test/jdk/com/sun/jdi/ClassUnloadEventTest.java +++ b/test/jdk/com/sun/jdi/ClassUnloadEventTest.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 @@ -24,18 +24,13 @@ /* * @test * @bug 8256811 - * @modules java.base/jdk.internal.org.objectweb.asm - * java.base/jdk.internal.misc + * @modules java.base/jdk.internal.misc * @library /test/lib * @build jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * @run main/othervm/native ClassUnloadEventTest run */ -import jdk.internal.org.objectweb.asm.ClassWriter; -import jdk.internal.org.objectweb.asm.Label; -import jdk.internal.org.objectweb.asm.MethodVisitor; -import jdk.internal.org.objectweb.asm.Opcodes; import jdk.test.lib.classloader.ClassUnloadCommon; import com.sun.jdi.*; @@ -45,6 +40,9 @@ import java.util.*; import java.io.*; +import java.lang.classfile.ClassFile; +import java.lang.constant.ClassDesc; +import java.lang.constant.ConstantDescs; public class ClassUnloadEventTest { static final String CLASS_NAME_PREFIX = "SampleClass__"; @@ -65,18 +63,13 @@ public static void main(String[] args) throws Exception { } } - private static class TestClassLoader extends ClassLoader implements Opcodes { + private static class TestClassLoader extends ClassLoader { private static byte[] generateSampleClass(String name) { - ClassWriter cw = new ClassWriter(0); - - cw.visit(52, ACC_SUPER | ACC_PUBLIC, name, null, "java/lang/Object", null); - MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "m", "()V", null, null); - mv.visitCode(); - mv.visitInsn(RETURN); - mv.visitMaxs(0, 0); - mv.visitEnd(); - cw.visitEnd(); - return cw.toByteArray(); + return ClassFile.of().build(ClassDesc.of(name), clb -> + clb.withVersion(52, 0) + .withFlags(ClassFile.ACC_SUPER | ClassFile.ACC_PUBLIC) + .withMethodBody("m", ConstantDescs.MTD_void, ClassFile.ACC_PUBLIC | ClassFile.ACC_STATIC, cob -> + cob.return_())); } @Override diff --git a/test/jdk/jdk/classfile/TEST.properties b/test/jdk/jdk/classfile/TEST.properties index 62414b36eae..2d8d20cf1f4 100644 --- a/test/jdk/jdk/classfile/TEST.properties +++ b/test/jdk/jdk/classfile/TEST.properties @@ -2,6 +2,4 @@ maxOutputSize = 2500000 modules = \ java.base/jdk.internal.classfile.components \ java.base/jdk.internal.classfile.impl \ - java.base/jdk.internal.classfile.impl.verifier \ - java.base/jdk.internal.org.objectweb.asm \ - java.base/jdk.internal.org.objectweb.asm.tree \ No newline at end of file + java.base/jdk.internal.classfile.impl.verifier \ No newline at end of file diff --git a/test/jdk/jdk/classfile/helpers/Transforms.java b/test/jdk/jdk/classfile/helpers/Transforms.java index b0e88bd8212..dba3f21cbd8 100644 --- a/test/jdk/jdk/classfile/helpers/Transforms.java +++ b/test/jdk/jdk/classfile/helpers/Transforms.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, 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 @@ -43,27 +43,12 @@ import java.lang.classfile.MethodModel; import java.lang.classfile.MethodTransform; import jdk.internal.classfile.components.ClassRemapper; -import jdk.internal.org.objectweb.asm.AnnotationVisitor; -import jdk.internal.org.objectweb.asm.Attribute; -import jdk.internal.org.objectweb.asm.ClassReader; -import jdk.internal.org.objectweb.asm.ClassVisitor; -import jdk.internal.org.objectweb.asm.FieldVisitor; -import jdk.internal.org.objectweb.asm.Handle; -import jdk.internal.org.objectweb.asm.Label; -import jdk.internal.org.objectweb.asm.MethodVisitor; -import jdk.internal.org.objectweb.asm.ModuleVisitor; -import jdk.internal.org.objectweb.asm.Opcodes; -import jdk.internal.org.objectweb.asm.RecordComponentVisitor; -import jdk.internal.org.objectweb.asm.TypePath; -import jdk.internal.org.objectweb.asm.tree.ClassNode; /** * Transforms */ public class Transforms { - static int ASM9 = 9 << 16 | 0 << 8; - public static final ClassTransform threeLevelNoop = (cb, ce) -> { if (ce instanceof MethodModel mm) { cb.transformMethod(mm, (mb, me) -> { @@ -128,42 +113,10 @@ public enum NoOpTransform { UNSHARED_3(false, threeLevelNoop), SHARED_3_NO_STACKMAP(true, threeLevelNoop, ClassFile.StackMapsOption.DROP_STACK_MAPS), SHARED_3_NO_DEBUG(true, threeLevelNoop, ClassFile.DebugElementsOption.DROP_DEBUG, ClassFile.LineNumbersOption.DROP_LINE_NUMBERS), - ASM_1(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(cw, 0); - return cw.toByteArray(); - }), - ASM_UNSHARED_1(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(cw, 0); - return cw.toByteArray(); - }), - ASM_3(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(new CustomClassVisitor(cw), 0); - return cw.toByteArray(); - }), - ASM_UNSHARED_3(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(new CustomClassVisitor(cw), 0); - return cw.toByteArray(); - }), - ASM_TREE(bytes -> { - ClassNode node = new ClassNode(); - ClassReader cr = new ClassReader(bytes); - cr.accept(node, 0); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - node.accept(cw); - return cw.toByteArray(); - }), CLASS_REMAPPER(bytes -> ClassRemapper.of(Map.of()).remapClass(ClassFile.of(), ClassFile.of().parse(bytes))); - // Need ASM, LOW_UNSHARED + // Need LOW_UNSHARED public final UnaryOperator transform; public final boolean shared; @@ -202,12 +155,6 @@ public Optional classRecord(byte[] bytes) throws IOException { } public enum InjectNopTransform { - ASM_NOP_SHARED(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(new NopClassVisitor(cw), 0); - return cw.toByteArray(); - }), NOP_SHARED(bytes -> { var cc = ClassFile.of(); ClassModel cm = cc.parse(bytes); @@ -242,13 +189,6 @@ public void accept(CodeElement e) { } public enum SimpleTransform { - ASM_ADD_FIELD(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(cw, 0); - cw.visitField(0, "argleBargleWoogaWooga", "I", null, null); - return cw.toByteArray(); - }), HIGH_SHARED_ADD_FIELD(bytes -> { var cc = ClassFile.of(); ClassModel cm = cc.parse(bytes); @@ -273,20 +213,6 @@ public void atEnd(ClassBuilder builder) { cb.withField("argleBargleWoogaWooga", ConstantDescs.CD_int, b -> { }); }); }), - ASM_DEL_METHOD(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - ClassVisitor v = new ClassVisitor(ASM9, cw) { - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - return (name.equals("hashCode") && descriptor.equals("()Z")) - ? null - : super.visitMethod(access, name, descriptor, signature, exceptions); - } - }; - cr.accept(cw, 0); - return cw.toByteArray(); - }), HIGH_SHARED_DEL_METHOD(bytes -> { var cc = ClassFile.of(); ClassModel cm = cc.parse(bytes); @@ -319,277 +245,4 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str } } - static class CustomClassVisitor extends ClassVisitor { - - public CustomClassVisitor(ClassVisitor writer) { - super(ASM9, writer); - } - - @Override - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - super.visit(version, access, name, signature, superName, interfaces); - } - - @Override - public void visitSource(String source, String debug) { - super.visitSource(source, debug); - } - - @Override - public ModuleVisitor visitModule(String name, int access, String version) { - return super.visitModule(name, access, version); - } - - @Override - public void visitNestHost(String nestHost) { - super.visitNestHost(nestHost); - } - - @Override - public void visitOuterClass(String owner, String name, String descriptor) { - super.visitOuterClass(owner, name, descriptor); - } - - @Override - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { - return super.visitAnnotation(descriptor, visible); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitAttribute(Attribute attribute) { - super.visitAttribute(attribute); - } - - @Override - public void visitNestMember(String nestMember) { - super.visitNestMember(nestMember); - } - - @Override - public void visitInnerClass(String name, String outerName, String innerName, int access) { - super.visitInnerClass(name, outerName, innerName, access); - } - - @Override - public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) { - return super.visitRecordComponent(name, descriptor, signature); - } - - @Override - public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) { - return super.visitField(access, name, descriptor, signature, value); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); - return new CustomMethodVisitor(mv); - } - - @Override - public void visitEnd() { - super.visitEnd(); - } - }; - - - static class CustomMethodVisitor extends MethodVisitor { - - public CustomMethodVisitor(MethodVisitor methodVisitor) { - super(ASM9, methodVisitor); - } - - @Override - public void visitParameter(String name, int access) { - super.visitParameter(name, access); - } - - @Override - public AnnotationVisitor visitAnnotationDefault() { - return super.visitAnnotationDefault(); - } - - @Override - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { - return super.visitAnnotation(descriptor, visible); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitAnnotableParameterCount(int parameterCount, boolean visible) { - super.visitAnnotableParameterCount(parameterCount, visible); - } - - @Override - public AnnotationVisitor visitParameterAnnotation(int parameter, String descriptor, boolean visible) { - return super.visitParameterAnnotation(parameter, descriptor, visible); - } - - @Override - public void visitAttribute(Attribute attribute) { - super.visitAttribute(attribute); - } - - @Override - public void visitCode() { - super.visitCode(); - } - - @Override - public void visitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) { - super.visitFrame(type, numLocal, local, numStack, stack); - } - - @Override - public void visitInsn(int opcode) { - super.visitInsn(opcode); - } - - @Override - public void visitIntInsn(int opcode, int operand) { - super.visitIntInsn(opcode, operand); - } - - @Override - public void visitVarInsn(int opcode, int var) { - super.visitVarInsn(opcode, var); - } - - @Override - public void visitTypeInsn(int opcode, String type) { - super.visitTypeInsn(opcode, type); - } - - @Override - public void visitFieldInsn(int opcode, String owner, String name, String descriptor) { - super.visitFieldInsn(opcode, owner, name, descriptor); - } - - @Override - @SuppressWarnings("deprecation") - public void visitMethodInsn(int opcode, String owner, String name, String descriptor) { - super.visitMethodInsn(opcode, owner, name, descriptor); - } - - @Override - public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { - super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); - } - - @Override - public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) { - super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments); - } - - @Override - public void visitJumpInsn(int opcode, Label label) { - super.visitJumpInsn(opcode, label); - } - - @Override - public void visitLabel(Label label) { - super.visitLabel(label); - } - - @Override - public void visitLdcInsn(Object value) { - super.visitLdcInsn(value); - } - - @Override - public void visitIincInsn(int var, int increment) { - super.visitIincInsn(var, increment); - } - - @Override - public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) { - super.visitTableSwitchInsn(min, max, dflt, labels); - } - - @Override - public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { - super.visitLookupSwitchInsn(dflt, keys, labels); - } - - @Override - public void visitMultiANewArrayInsn(String descriptor, int numDimensions) { - super.visitMultiANewArrayInsn(descriptor, numDimensions); - } - - @Override - public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitInsnAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { - super.visitTryCatchBlock(start, end, handler, type); - } - - @Override - public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) { - super.visitLocalVariable(name, descriptor, signature, start, end, index); - } - - @Override - public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String descriptor, boolean visible) { - return super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, descriptor, visible); - } - - @Override - public void visitLineNumber(int line, Label start) { - super.visitLineNumber(line, start); - } - - @Override - public void visitMaxs(int maxStack, int maxLocals) { - super.visitMaxs(maxStack, maxLocals); - } - - @Override - public void visitEnd() { - super.visitEnd(); - } - }; - - static class NopClassVisitor extends CustomClassVisitor { - - public NopClassVisitor(ClassVisitor writer) { - super(writer); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); - return new NopMethodVisitor(mv); - } - } - - static class NopMethodVisitor extends CustomMethodVisitor { - - public NopMethodVisitor(MethodVisitor methodVisitor) { - super(methodVisitor); - } - - @Override - public void visitCode() { - super.visitCode(); - visitInsn(Opcodes.NOP); - } - } - } diff --git a/test/langtools/tools/javac/6734819/T6734819a.out b/test/langtools/tools/javac/6734819/T6734819a.out index a3ccb07e67e..c29dbde637b 100644 --- a/test/langtools/tools/javac/6734819/T6734819a.out +++ b/test/langtools/tools/javac/6734819/T6734819a.out @@ -1,9 +1,12 @@ [attribute Y] [flow Y] +[warn Y] [attribute W] [flow W] +[warn W] [attribute Z] [flow Z] +[warn Z] [desugar Z] [desugar W] [desugar Y] diff --git a/test/langtools/tools/javac/6734819/T6734819b.out b/test/langtools/tools/javac/6734819/T6734819b.out index 0c9629006df..61c1f31f179 100644 --- a/test/langtools/tools/javac/6734819/T6734819b.out +++ b/test/langtools/tools/javac/6734819/T6734819b.out @@ -1,7 +1,9 @@ [attribute A] [flow A] +[warn A] [attribute B] [flow B] +[warn B] [desugar B] [desugar A] [generate code A] diff --git a/test/langtools/tools/javac/6734819/T6734819c.out b/test/langtools/tools/javac/6734819/T6734819c.out index 1d4cff3212f..6ae56176acb 100644 --- a/test/langtools/tools/javac/6734819/T6734819c.out +++ b/test/langtools/tools/javac/6734819/T6734819c.out @@ -1,7 +1,9 @@ [attribute Y] [flow Y] +[warn Y] [attribute W] [flow W] +[warn W] [attribute Z] [flow Z] T6734819c.java:15:11: compiler.err.unreachable.stmt diff --git a/test/langtools/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.out b/test/langtools/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.out index 11cc81304f0..e240208da72 100644 --- a/test/langtools/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.out +++ b/test/langtools/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.out @@ -1,4 +1,5 @@ [attribute Explicit] [flow Explicit] +[warn Explicit] [desugar Explicit] [generate code Explicit] diff --git a/test/langtools/tools/javac/policy/test1/byfile.ABD.out b/test/langtools/tools/javac/policy/test1/byfile.ABD.out index dfa86a44132..0710de49c86 100644 --- a/test/langtools/tools/javac/policy/test1/byfile.ABD.out +++ b/test/langtools/tools/javac/policy/test1/byfile.ABD.out @@ -4,6 +4,9 @@ [flow A] [flow A1] [flow A2] +[warn A] +[warn A1] +[warn A2] [desugar A] [desugar A1] [desugar A2] diff --git a/test/langtools/tools/javac/policy/test1/byfile.ACD.out b/test/langtools/tools/javac/policy/test1/byfile.ACD.out index 66534ce00c5..70cc4856557 100644 --- a/test/langtools/tools/javac/policy/test1/byfile.ACD.out +++ b/test/langtools/tools/javac/policy/test1/byfile.ACD.out @@ -4,6 +4,9 @@ [flow A] [flow A1] [flow A2] +[warn A] +[warn A1] +[warn A2] [desugar A] [desugar A1] [desugar A2] diff --git a/test/langtools/tools/javac/policy/test1/bytodo.ABD.out b/test/langtools/tools/javac/policy/test1/bytodo.ABD.out index 5b3b8faace7..3296547f0ff 100644 --- a/test/langtools/tools/javac/policy/test1/bytodo.ABD.out +++ b/test/langtools/tools/javac/policy/test1/bytodo.ABD.out @@ -1,17 +1,21 @@ [attribute A] [flow A] +[warn A] [desugar A] [generate code A] [attribute A1] [flow A1] +[warn A1] [desugar A1] [generate code A1] [attribute A2] [flow A2] +[warn A2] [desugar A2] [generate code A2] [attribute B] [flow B] +[warn B] [desugar B] [generate code B] [attribute B1] diff --git a/test/langtools/tools/javac/policy/test1/bytodo.ACD.out b/test/langtools/tools/javac/policy/test1/bytodo.ACD.out index a29c0880de9..767a9912a05 100644 --- a/test/langtools/tools/javac/policy/test1/bytodo.ACD.out +++ b/test/langtools/tools/javac/policy/test1/bytodo.ACD.out @@ -1,17 +1,21 @@ [attribute A] [flow A] +[warn A] [desugar A] [generate code A] [attribute A1] [flow A1] +[warn A1] [desugar A1] [generate code A1] [attribute A2] [flow A2] +[warn A2] [desugar A2] [generate code A2] [attribute C] [flow C] +[warn C] [desugar C] [generate code C] [attribute C1] diff --git a/test/langtools/tools/javac/policy/test2/byfile.AB.out b/test/langtools/tools/javac/policy/test2/byfile.AB.out index 6d152c873aa..63a51108f36 100644 --- a/test/langtools/tools/javac/policy/test2/byfile.AB.out +++ b/test/langtools/tools/javac/policy/test2/byfile.AB.out @@ -1,7 +1,9 @@ [attribute A] [flow A] +[warn A] [attribute B] [flow B] +[warn B] [desugar B] [desugar A] [generate code A.A1] diff --git a/test/langtools/tools/javac/policy/test2/byfile.BA.out b/test/langtools/tools/javac/policy/test2/byfile.BA.out index 565ad138615..3c3567043a0 100644 --- a/test/langtools/tools/javac/policy/test2/byfile.BA.out +++ b/test/langtools/tools/javac/policy/test2/byfile.BA.out @@ -1,10 +1,12 @@ [attribute B] [flow B] +[warn B] [desugar B] [generate code B.Inner] [generate code B] [attribute A] [flow A] +[warn A] [desugar A] [generate code A.A1] [generate code A.A2] diff --git a/test/langtools/tools/javac/policy/test2/bytodo.AB.out b/test/langtools/tools/javac/policy/test2/bytodo.AB.out index 6d152c873aa..63a51108f36 100644 --- a/test/langtools/tools/javac/policy/test2/bytodo.AB.out +++ b/test/langtools/tools/javac/policy/test2/bytodo.AB.out @@ -1,7 +1,9 @@ [attribute A] [flow A] +[warn A] [attribute B] [flow B] +[warn B] [desugar B] [desugar A] [generate code A.A1] diff --git a/test/langtools/tools/javac/policy/test2/bytodo.BA.out b/test/langtools/tools/javac/policy/test2/bytodo.BA.out index 565ad138615..3c3567043a0 100644 --- a/test/langtools/tools/javac/policy/test2/bytodo.BA.out +++ b/test/langtools/tools/javac/policy/test2/bytodo.BA.out @@ -1,10 +1,12 @@ [attribute B] [flow B] +[warn B] [desugar B] [generate code B.Inner] [generate code B] [attribute A] [flow A] +[warn A] [desugar A] [generate code A.A1] [generate code A.A2] diff --git a/test/langtools/tools/javac/recovery/AttrRecovery.java b/test/langtools/tools/javac/recovery/AttrRecovery.java index db679915e08..c5d393a23b3 100644 --- a/test/langtools/tools/javac/recovery/AttrRecovery.java +++ b/test/langtools/tools/javac/recovery/AttrRecovery.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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 @@ -115,7 +115,7 @@ public void overridable(C c) {} Path curPath = Path.of("."); List actual = new JavacTask(tb) .options("-XDrawDiagnostics", "-XDdev", - "-XDshould-stop.at=FLOW", "-Xlint:this-escape") + "-XDshould-stop.at=WARN", "-Xlint:this-escape") .sources(code) .outdir(curPath) .run(Expect.FAIL) diff --git a/test/micro/org/openjdk/bench/jdk/classfile/AbstractCorpusBenchmark.java b/test/micro/org/openjdk/bench/jdk/classfile/AbstractCorpusBenchmark.java index f3c934d9c65..ea361b4975b 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/AbstractCorpusBenchmark.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/AbstractCorpusBenchmark.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, 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 @@ -44,8 +44,6 @@ @Warmup(iterations = 2) @Measurement(iterations = 4) @Fork(value = 1, jvmArgs = { - "--add-exports", "java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED", - "--add-exports", "java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED", "--add-exports", "java.base/jdk.internal.classfile.components=ALL-UNNAMED", "--add-exports", "java.base/jdk.internal.classfile.impl=ALL-UNNAMED"}) @State(Scope.Benchmark) diff --git a/test/micro/org/openjdk/bench/jdk/classfile/AdaptNull.java b/test/micro/org/openjdk/bench/jdk/classfile/AdaptNull.java index 55c33b36805..680d1626b2c 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/AdaptNull.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/AdaptNull.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 @@ -35,10 +35,6 @@ public class AdaptNull extends AbstractCorpusBenchmark { @Param({ // "ARRAYCOPY", - "ASM_1", - "ASM_3", - "ASM_UNSHARED_3", -// "ASM_TREE", "SHARED_1", "SHARED_2", "SHARED_3", diff --git a/test/micro/org/openjdk/bench/jdk/classfile/ReadDeep.java b/test/micro/org/openjdk/bench/jdk/classfile/ReadDeep.java index 4165785135c..a134e04bd5a 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/ReadDeep.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/ReadDeep.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, 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 @@ -29,12 +29,6 @@ import java.lang.classfile.CompoundElement; import java.lang.classfile.MethodModel; import java.lang.classfile.instruction.LoadInstruction; -import jdk.internal.org.objectweb.asm.ClassReader; -import jdk.internal.org.objectweb.asm.ClassVisitor; -import jdk.internal.org.objectweb.asm.MethodVisitor; -import jdk.internal.org.objectweb.asm.Opcodes; -import jdk.internal.org.objectweb.asm.tree.ClassNode; -import jdk.internal.org.objectweb.asm.tree.MethodNode; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Mode; @@ -45,55 +39,6 @@ */ public class ReadDeep extends AbstractCorpusBenchmark { - @Benchmark - @BenchmarkMode(Mode.Throughput) - public void asmStreamCountLoads(Blackhole bh) { - for (byte[] bytes : classes) { - ClassReader cr = new ClassReader(bytes); - - var mv = new MethodVisitor(Opcodes.ASM9) { - int count = 0; - - @Override - public void visitVarInsn(int opcode, int var) { - ++count; - } - }; - - var visitor = new ClassVisitor(Opcodes.ASM9) { - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - return mv; - } - }; - cr.accept(visitor, 0); - bh.consume(mv.count); - } - } - - @Benchmark - @BenchmarkMode(Mode.Throughput) - public void asmTreeCountLoads(Blackhole bh) { - for (byte[] bytes : classes) { - var mv = new MethodVisitor(Opcodes.ASM9) { - int count = 0; - - @Override - public void visitVarInsn(int opcode, int var) { - ++count; - } - }; - - ClassNode node = new ClassNode(); - ClassReader cr = new ClassReader(bytes); - cr.accept(node, 0); - for (MethodNode mn : node.methods) { - mn.accept(mv); - } - bh.consume(mv.count); - } - } - @Benchmark @BenchmarkMode(Mode.Throughput) public void jdkElementsCountLoads(Blackhole bh) { diff --git a/test/micro/org/openjdk/bench/jdk/classfile/ReadMetadata.java b/test/micro/org/openjdk/bench/jdk/classfile/ReadMetadata.java index 08b1b6312b1..0a12c5214e7 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/ReadMetadata.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/ReadMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, 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 @@ -27,42 +27,11 @@ import java.lang.classfile.ClassModel; import java.lang.classfile.ClassFile; import java.lang.classfile.FieldModel; -import jdk.internal.org.objectweb.asm.*; -import jdk.internal.org.objectweb.asm.tree.*; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; public class ReadMetadata extends AbstractCorpusBenchmark { - @Benchmark - @BenchmarkMode(Mode.Throughput) - public void asmStreamReadName(Blackhole bh) { - for (byte[] bytes : classes) { - ClassReader cr = new ClassReader(bytes); - var visitor = new ClassVisitor(Opcodes.ASM9) { - String theName; - - @Override - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - theName = name; - } - }; - cr.accept(visitor, 0); - bh.consume(visitor.theName); - } - } - - @Benchmark - @BenchmarkMode(Mode.Throughput) - public void asmTreeReadName(Blackhole bh) { - for (byte[] bytes : classes) { - ClassNode node = new ClassNode(); - ClassReader cr = new ClassReader(bytes); - cr.accept(node, 0); - bh.consume(node.name); - } - } - @Benchmark @BenchmarkMode(Mode.Throughput) public void jdkReadName(Blackhole bh) { @@ -90,43 +59,6 @@ public void jdkReadMemberNames(Blackhole bh) { } } - @Benchmark - @BenchmarkMode(Mode.Throughput) - public void asmStreamCountFields(Blackhole bh) { - for (byte[] bytes : classes) { - ClassReader cr = new ClassReader(bytes); - var visitor = new ClassVisitor(Opcodes.ASM9) { - int count; - - @Override - public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) { - if ((access & Opcodes.ACC_PUBLIC) != 1) { - ++count; - } - return null; - } - }; - cr.accept(visitor, 0); - bh.consume(visitor.count); - } - } - - @Benchmark - @BenchmarkMode(Mode.Throughput) - public void asmTreeCountFields(Blackhole bh) { - for (byte[] bytes : classes) { - int count = 0; - ClassNode node = new ClassNode(); - ClassReader cr = new ClassReader(bytes); - cr.accept(node, 0); - for (FieldNode fn : node.fields) - if ((fn.access & Opcodes.ACC_PUBLIC) != 1) { - ++count; - } - bh.consume(count); - } - } - @Benchmark @BenchmarkMode(Mode.Throughput) public void jdkTreeCountFields(Blackhole bh) { diff --git a/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java b/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java index 8af03a8b874..19c87442039 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/Transforms.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, 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 @@ -41,27 +41,12 @@ import java.lang.classfile.MethodModel; import java.lang.classfile.MethodTransform; import jdk.internal.classfile.components.ClassRemapper; -import jdk.internal.org.objectweb.asm.AnnotationVisitor; -import jdk.internal.org.objectweb.asm.Attribute; -import jdk.internal.org.objectweb.asm.ClassReader; -import jdk.internal.org.objectweb.asm.ClassVisitor; -import jdk.internal.org.objectweb.asm.FieldVisitor; -import jdk.internal.org.objectweb.asm.Handle; -import jdk.internal.org.objectweb.asm.Label; -import jdk.internal.org.objectweb.asm.MethodVisitor; -import jdk.internal.org.objectweb.asm.ModuleVisitor; -import jdk.internal.org.objectweb.asm.Opcodes; -import jdk.internal.org.objectweb.asm.RecordComponentVisitor; -import jdk.internal.org.objectweb.asm.TypePath; -import jdk.internal.org.objectweb.asm.tree.ClassNode; /** * Transforms */ public class Transforms { - static int ASM9 = 9 << 16 | 0 << 8; - public static final ClassTransform threeLevelNoop = (cb, ce) -> { if (ce instanceof MethodModel mm) { cb.transformMethod(mm, (mb, me) -> { @@ -123,38 +108,6 @@ public enum NoOpTransform { UNSHARED_3(false, threeLevelNoop), SHARED_3_NO_STACKMAP(true, threeLevelNoop, ClassFile.StackMapsOption.DROP_STACK_MAPS), SHARED_3_NO_DEBUG(true, threeLevelNoop, ClassFile.DebugElementsOption.DROP_DEBUG, ClassFile.LineNumbersOption.DROP_LINE_NUMBERS), - ASM_1(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(cw, 0); - return cw.toByteArray(); - }), - ASM_UNSHARED_1(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(cw, 0); - return cw.toByteArray(); - }), - ASM_3(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(new CustomClassVisitor(cw), 0); - return cw.toByteArray(); - }), - ASM_UNSHARED_3(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(new CustomClassVisitor(cw), 0); - return cw.toByteArray(); - }), - ASM_TREE(bytes -> { - ClassNode node = new ClassNode(); - ClassReader cr = new ClassReader(bytes); - cr.accept(node, 0); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - node.accept(cw); - return cw.toByteArray(); - }), CLASS_REMAPPER(bytes -> ClassRemapper.of(Map.of()).remapClass(ClassFile.of(), ClassFile.of().parse(bytes))); @@ -186,12 +139,6 @@ public enum NoOpTransform { } public enum InjectNopTransform { - ASM_NOP_SHARED(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(new NopClassVisitor(cw), 0); - return cw.toByteArray(); - }), NOP_SHARED(bytes -> { var cc = ClassFile.of(); ClassModel cm = cc.parse(bytes); @@ -226,13 +173,6 @@ public void accept(CodeElement e) { } public enum SimpleTransform { - ASM_ADD_FIELD(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - cr.accept(cw, 0); - cw.visitField(0, "argleBargleWoogaWooga", "I", null, null); - return cw.toByteArray(); - }), HIGH_SHARED_ADD_FIELD(bytes -> { var cc = ClassFile.of(); ClassModel cm = cc.parse(bytes); @@ -257,20 +197,6 @@ public void atEnd(ClassBuilder builder) { cb.withField("argleBargleWoogaWooga", ConstantDescs.CD_int, b -> { }); }); }), - ASM_DEL_METHOD(bytes -> { - ClassReader cr = new ClassReader(bytes); - jdk.internal.org.objectweb.asm.ClassWriter cw = new jdk.internal.org.objectweb.asm.ClassWriter(cr, jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES); - ClassVisitor v = new ClassVisitor(ASM9, cw) { - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - return (name.equals("hashCode") && descriptor.equals("()Z")) - ? null - : super.visitMethod(access, name, descriptor, signature, exceptions); - } - }; - cr.accept(cw, 0); - return cw.toByteArray(); - }), HIGH_SHARED_DEL_METHOD(bytes -> { var cc = ClassFile.of(); ClassModel cm = cc.parse(bytes); @@ -303,277 +229,4 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str } } - static class CustomClassVisitor extends ClassVisitor { - - public CustomClassVisitor(ClassVisitor writer) { - super(ASM9, writer); - } - - @Override - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - super.visit(version, access, name, signature, superName, interfaces); - } - - @Override - public void visitSource(String source, String debug) { - super.visitSource(source, debug); - } - - @Override - public ModuleVisitor visitModule(String name, int access, String version) { - return super.visitModule(name, access, version); - } - - @Override - public void visitNestHost(String nestHost) { - super.visitNestHost(nestHost); - } - - @Override - public void visitOuterClass(String owner, String name, String descriptor) { - super.visitOuterClass(owner, name, descriptor); - } - - @Override - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { - return super.visitAnnotation(descriptor, visible); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitAttribute(Attribute attribute) { - super.visitAttribute(attribute); - } - - @Override - public void visitNestMember(String nestMember) { - super.visitNestMember(nestMember); - } - - @Override - public void visitInnerClass(String name, String outerName, String innerName, int access) { - super.visitInnerClass(name, outerName, innerName, access); - } - - @Override - public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) { - return super.visitRecordComponent(name, descriptor, signature); - } - - @Override - public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) { - return super.visitField(access, name, descriptor, signature, value); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); - return new CustomMethodVisitor(mv); - } - - @Override - public void visitEnd() { - super.visitEnd(); - } - }; - - - static class CustomMethodVisitor extends MethodVisitor { - - public CustomMethodVisitor(MethodVisitor methodVisitor) { - super(ASM9, methodVisitor); - } - - @Override - public void visitParameter(String name, int access) { - super.visitParameter(name, access); - } - - @Override - public AnnotationVisitor visitAnnotationDefault() { - return super.visitAnnotationDefault(); - } - - @Override - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { - return super.visitAnnotation(descriptor, visible); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitAnnotableParameterCount(int parameterCount, boolean visible) { - super.visitAnnotableParameterCount(parameterCount, visible); - } - - @Override - public AnnotationVisitor visitParameterAnnotation(int parameter, String descriptor, boolean visible) { - return super.visitParameterAnnotation(parameter, descriptor, visible); - } - - @Override - public void visitAttribute(Attribute attribute) { - super.visitAttribute(attribute); - } - - @Override - public void visitCode() { - super.visitCode(); - } - - @Override - public void visitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) { - super.visitFrame(type, numLocal, local, numStack, stack); - } - - @Override - public void visitInsn(int opcode) { - super.visitInsn(opcode); - } - - @Override - public void visitIntInsn(int opcode, int operand) { - super.visitIntInsn(opcode, operand); - } - - @Override - public void visitVarInsn(int opcode, int var) { - super.visitVarInsn(opcode, var); - } - - @Override - public void visitTypeInsn(int opcode, String type) { - super.visitTypeInsn(opcode, type); - } - - @Override - public void visitFieldInsn(int opcode, String owner, String name, String descriptor) { - super.visitFieldInsn(opcode, owner, name, descriptor); - } - - @Override - @SuppressWarnings("deprecation") - public void visitMethodInsn(int opcode, String owner, String name, String descriptor) { - super.visitMethodInsn(opcode, owner, name, descriptor); - } - - @Override - public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { - super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); - } - - @Override - public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) { - super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments); - } - - @Override - public void visitJumpInsn(int opcode, Label label) { - super.visitJumpInsn(opcode, label); - } - - @Override - public void visitLabel(Label label) { - super.visitLabel(label); - } - - @Override - public void visitLdcInsn(Object value) { - super.visitLdcInsn(value); - } - - @Override - public void visitIincInsn(int var, int increment) { - super.visitIincInsn(var, increment); - } - - @Override - public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) { - super.visitTableSwitchInsn(min, max, dflt, labels); - } - - @Override - public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { - super.visitLookupSwitchInsn(dflt, keys, labels); - } - - @Override - public void visitMultiANewArrayInsn(String descriptor, int numDimensions) { - super.visitMultiANewArrayInsn(descriptor, numDimensions); - } - - @Override - public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitInsnAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { - super.visitTryCatchBlock(start, end, handler, type); - } - - @Override - public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) { - return super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible); - } - - @Override - public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) { - super.visitLocalVariable(name, descriptor, signature, start, end, index); - } - - @Override - public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String descriptor, boolean visible) { - return super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, descriptor, visible); - } - - @Override - public void visitLineNumber(int line, Label start) { - super.visitLineNumber(line, start); - } - - @Override - public void visitMaxs(int maxStack, int maxLocals) { - super.visitMaxs(maxStack, maxLocals); - } - - @Override - public void visitEnd() { - super.visitEnd(); - } - }; - - static class NopClassVisitor extends CustomClassVisitor { - - public NopClassVisitor(ClassVisitor writer) { - super(writer); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); - return new NopMethodVisitor(mv); - } - } - - static class NopMethodVisitor extends CustomMethodVisitor { - - public NopMethodVisitor(MethodVisitor methodVisitor) { - super(methodVisitor); - } - - @Override - public void visitCode() { - super.visitCode(); - visitInsn(Opcodes.NOP); - } - } - } diff --git a/test/micro/org/openjdk/bench/jdk/classfile/Write.java b/test/micro/org/openjdk/bench/jdk/classfile/Write.java index ffd5b8f1c5e..9317ef78806 100644 --- a/test/micro/org/openjdk/bench/jdk/classfile/Write.java +++ b/test/micro/org/openjdk/bench/jdk/classfile/Write.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, 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 @@ -25,7 +25,6 @@ import java.lang.reflect.AccessFlag; import java.lang.classfile.ClassFile; import java.lang.classfile.attribute.SourceFileAttribute; -import jdk.internal.org.objectweb.asm.*; import org.openjdk.jmh.annotations.*; import java.io.FileOutputStream; import static java.lang.classfile.ClassFile.ACC_PUBLIC; @@ -57,8 +56,6 @@ @Warmup(iterations = 3) @Measurement(iterations = 5) @Fork(value = 1, jvmArgs = { - "--add-exports", "java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED", - "--add-exports", "java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED", "--add-exports", "java.base/jdk.internal.classfile.impl=ALL-UNNAMED"}) public class Write { static final int REPEATS = 40; @@ -70,76 +67,9 @@ public class Write { } METHOD_NAMES = names; } - static String checkFileAsm = "/tmp/asw/MyClass.class"; static String checkFileBc = "/tmp/byw/MyClass.class"; - static boolean writeClassAsm = Files.exists(Paths.get(checkFileAsm).getParent()); static boolean writeClassBc = Files.exists(Paths.get(checkFileBc).getParent()); - - @Benchmark - @BenchmarkMode(Mode.Throughput) - public byte[] asmStream() { - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - cw.visit(Opcodes.V12, Opcodes.ACC_PUBLIC, "MyClass", null, "java/lang/Object", null); - cw.visitSource("MyClass.java", null); - - { - MethodVisitor mv = cw.visitMethod(0, INIT_NAME, "()V", null, null); - mv.visitCode(); - Label startLabel = new Label(); - Label endLabel = new Label(); - mv.visitLabel(startLabel); - mv.visitVarInsn(Opcodes.ALOAD, 0); - mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", INIT_NAME, "()V", false); - mv.visitInsn(Opcodes.RETURN); - mv.visitLabel(endLabel); - mv.visitLocalVariable("this", "LMyClass;", null, startLabel, endLabel, 1); - mv.visitMaxs(-1, -1); - mv.visitEnd(); - } - - for (int xi = 0; xi < REPEATS; ++xi) { - MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC+Opcodes.ACC_STATIC, METHOD_NAMES[xi], "([Ljava/lang/String;)V", null, null); - mv.visitCode(); - Label loopTop = new Label(); - Label loopEnd = new Label(); - Label startLabel = new Label(); - Label endLabel = new Label(); - Label iStart = new Label(); - mv.visitLabel(startLabel); - mv.visitInsn(Opcodes.ICONST_1); - mv.visitVarInsn(Opcodes.ISTORE, 1); - mv.visitLabel(iStart); - mv.visitInsn(Opcodes.ICONST_1); - mv.visitVarInsn(Opcodes.ISTORE, 2); - mv.visitLabel(loopTop); - mv.visitVarInsn(Opcodes.ILOAD, 2); - mv.visitIntInsn(Opcodes.BIPUSH, 10); - mv.visitJumpInsn(Opcodes.IF_ICMPGE, loopEnd); - mv.visitVarInsn(Opcodes.ILOAD, 1); - mv.visitVarInsn(Opcodes.ILOAD, 2); - mv.visitInsn(Opcodes.IMUL); - mv.visitVarInsn(Opcodes.ISTORE, 1); - mv.visitIincInsn(2, 1); - mv.visitJumpInsn(Opcodes.GOTO, loopTop); - mv.visitLabel(loopEnd); - mv.visitFieldInsn(Opcodes.GETSTATIC,"java/lang/System", "out", "Ljava/io/PrintStream;"); - mv.visitVarInsn(Opcodes.ILOAD, 1); - mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(I)V", false); - mv.visitLabel(endLabel); - mv.visitInsn(Opcodes.RETURN); - mv.visitLocalVariable("fac", "I", null, startLabel, endLabel, 1); - mv.visitLocalVariable("i", "I", null, iStart, loopEnd, 2); - mv.visitMaxs(-1, -1); - mv.visitEnd(); - } - cw.visitEnd(); - - byte[] bytes = cw.toByteArray(); - if (writeClassAsm) writeClass(bytes, checkFileAsm); - return bytes; - } - @Benchmark @BenchmarkMode(Mode.Throughput) public byte[] jdkTree() {