Skip to content

Commit

Permalink
Merge upstream-jdk
Browse files Browse the repository at this point in the history
  • Loading branch information
corretto-github-robot committed Jul 18, 2024
2 parents 0b1b09e + e83e2b3 commit e757078
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ static void set_serialized(const T* ptr) {
assert(ptr != nullptr, "invariant");
if (current_epoch()) {
CLEAR_THIS_EPOCH_CLEARED_BIT(ptr);
assert(!IS_THIS_EPOCH_CLEARED_BIT_SET(ptr), "invariant");
}
assert(IS_PREVIOUS_EPOCH_CLEARED_BIT_SET(ptr), "invariant");
SET_SERIALIZED(ptr);
assert(IS_SERIALIZED(ptr), "invariant");
}
Expand Down Expand Up @@ -929,9 +931,11 @@ void set_serialized<Method>(MethodPtr method) {
assert(method != nullptr, "invariant");
if (current_epoch()) {
CLEAR_THIS_EPOCH_METHOD_CLEARED_BIT(method);
assert(!IS_THIS_EPOCH_METHOD_CLEARED_BIT_SET(method), "invariant");
}
assert(unloading() ? true : METHOD_IS_NOT_SERIALIZED(method), "invariant");
SET_METHOD_SERIALIZED(method);
assert(IS_PREVIOUS_EPOCH_METHOD_CLEARED_BIT_SET(method), "invariant");
assert(METHOD_IS_SERIALIZED(method), "invariant");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ClearArtifact {
assert(IS_NOT_TRANSIENT(value), "invariant");
SET_PREVIOUS_EPOCH_CLEARED_BIT(value);
CLEAR_PREVIOUS_EPOCH_METHOD_AND_CLASS(value);
assert(IS_THIS_EPOCH_CLEARED_BIT_SET(value), "invariant");
assert(IS_PREVIOUS_EPOCH_CLEARED_BIT_SET(value), "invariant");
return true;
}
};
Expand All @@ -111,6 +113,8 @@ class ClearArtifact<const Method*> {
assert(METHOD_IS_NOT_TRANSIENT(method), "invariant");
SET_PREVIOUS_EPOCH_METHOD_CLEARED_BIT(method);
CLEAR_PREVIOUS_EPOCH_METHOD_FLAG(method);
assert(IS_THIS_EPOCH_METHOD_CLEARED_BIT_SET(method), "invariant");
assert(IS_PREVIOUS_EPOCH_METHOD_CLEARED_BIT_SET(method), "invariant");
return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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
Expand Down Expand Up @@ -50,22 +50,22 @@ static traceid atomic_inc(traceid volatile* const dest, traceid stride = 1) {

static traceid next_class_id() {
static volatile traceid class_id_counter = LAST_TYPE_ID + 1; // + 1 is for the void.class primitive
return atomic_inc(&class_id_counter) << TRACE_ID_SHIFT;
return (atomic_inc(&class_id_counter) << TRACE_ID_SHIFT) | EPOCH_CLEARED_BITS;
}

static traceid next_module_id() {
static volatile traceid module_id_counter = 0;
return atomic_inc(&module_id_counter) << TRACE_ID_SHIFT;
return (atomic_inc(&module_id_counter) << TRACE_ID_SHIFT) | EPOCH_CLEARED_BITS;
}

static traceid next_package_id() {
static volatile traceid package_id_counter = 0;
return atomic_inc(&package_id_counter) << TRACE_ID_SHIFT;
return (atomic_inc(&package_id_counter) << TRACE_ID_SHIFT) | EPOCH_CLEARED_BITS;
}

static traceid next_class_loader_data_id() {
static volatile traceid cld_id_counter = 0;
return atomic_inc(&cld_id_counter) << TRACE_ID_SHIFT;
return (atomic_inc(&cld_id_counter) << TRACE_ID_SHIFT) | EPOCH_CLEARED_BITS;
}

static bool found_jdk_internal_event_klass = false;
Expand Down Expand Up @@ -201,18 +201,18 @@ traceid JfrTraceId::load_raw(jclass jc) {
// used by CDS / APPCDS as part of "remove_unshareable_info"
void JfrTraceId::remove(const Klass* k) {
assert(k != nullptr, "invariant");
// Mask off and store the event flags.
// Mask off and store the event flags and epoch clear bits.
// This mechanism will retain the event specific flags
// in the archive, allowing for event flag restoration
// when renewing the traceid on klass revival.
k->set_trace_id(EVENT_KLASS_MASK(k));
k->set_trace_id(EPOCH_CLEARED_BITS | EVENT_KLASS_MASK(k));
}

// used by CDS / APPCDS as part of "remove_unshareable_info"
void JfrTraceId::remove(const Method* method) {
assert(method != nullptr, "invariant");
// Clear all bits.
method->set_trace_flags(0);
// Clear tag bits and set epoch cleared bits.
method->set_trace_flags(static_cast<uint16_t>(EPOCH_CLEARED_BITS));
}

// used by CDS / APPCDS as part of "restore_unshareable_info"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ inline traceid JfrTraceIdLoadBarrier::load_leakp(const Klass* klass) {

inline traceid JfrTraceIdLoadBarrier::load_leakp(const Klass* klass, const Method* method) {
assert(klass != nullptr, "invariant");
assert(METHOD_AND_CLASS_USED_THIS_EPOCH(klass), "invariant");
assert(method != nullptr, "invariant");
assert(klass == method->method_holder(), "invariant");
assert(METHOD_AND_CLASS_USED_THIS_EPOCH(klass), "invariant");
if (should_tag(method)) {
// the method is already logically tagged, just like the klass,
// but because of redefinition, the latest Method*
Expand All @@ -174,9 +174,9 @@ inline traceid JfrTraceIdLoadBarrier::load_leakp(const Klass* klass, const Metho

inline traceid JfrTraceIdLoadBarrier::load_leakp_previuos_epoch(const Klass* klass, const Method* method) {
assert(klass != nullptr, "invariant");
assert(METHOD_AND_CLASS_USED_PREVIOUS_EPOCH(klass), "invariant");
assert(method != nullptr, "invariant");
assert(klass == method->method_holder(), "invariant");
assert(METHOD_AND_CLASS_USED_PREVIOUS_EPOCH(klass), "invariant");
if (METHOD_FLAG_NOT_USED_PREVIOUS_EPOCH(method)) {
// the method is already logically tagged, just like the klass,
// but because of redefinition, the latest Method*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 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
Expand Down Expand Up @@ -48,6 +48,7 @@
#define EPOCH_0_CLEARED_BIT (EPOCH_0_CLEARED_META_BIT << META_SHIFT)
#define EPOCH_1_CLEARED_META_BIT (BIT << 1)
#define EPOCH_1_CLEARED_BIT (EPOCH_1_CLEARED_META_BIT << META_SHIFT)
#define EPOCH_CLEARED_BITS (EPOCH_1_CLEARED_BIT | EPOCH_0_CLEARED_BIT)
#define LEAKP_META_BIT (BIT << 2)
#define LEAKP_BIT (LEAKP_META_BIT << META_SHIFT)
#define TRANSIENT_META_BIT (BIT << 3)
Expand Down Expand Up @@ -136,6 +137,8 @@
#define IS_TRANSIENT(ptr) (TRACE_ID_PREDICATE(ptr, TRANSIENT_BIT))
#define IS_NOT_TRANSIENT(ptr) (!(IS_TRANSIENT(ptr)))
#define SET_SERIALIZED(ptr) (TRACE_ID_META_TAG(ptr, SERIALIZED_META_BIT))
#define IS_THIS_EPOCH_CLEARED_BIT_SET(ptr) (TRACE_ID_PREDICATE(ptr, (THIS_EPOCH_BIT << META_SHIFT)))
#define IS_PREVIOUS_EPOCH_CLEARED_BIT_SET(ptr) (TRACE_ID_PREDICATE(ptr, (PREVIOUS_EPOCH_BIT << META_SHIFT)))
#define IS_SERIALIZED(ptr) (TRACE_ID_PREDICATE(ptr, SERIALIZED_BIT))
#define IS_NOT_SERIALIZED(ptr) (!(IS_SERIALIZED(ptr)))
#define SHOULD_TAG(ptr) (NOT_USED_THIS_EPOCH(ptr))
Expand All @@ -161,5 +164,7 @@
#define CLEAR_THIS_EPOCH_METHOD_CLEARED_BIT(ptr) (METHOD_META_MASK_CLEAR(ptr,(~(THIS_EPOCH_BIT))))
#define IS_THIS_EPOCH_METHOD_CLEARED(ptr) (METHOD_FLAG_PREDICATE(method, THIS_EPOCH_BIT))
#define IS_PREVIOUS_EPOCH_METHOD_CLEARED(ptr) (METHOD_FLAG_PREDICATE(method, PREVIOUS_EPOCH_BIT))
#define IS_THIS_EPOCH_METHOD_CLEARED_BIT_SET(ptr) (METHOD_FLAG_PREDICATE(ptr, (THIS_EPOCH_BIT << META_SHIFT)))
#define IS_PREVIOUS_EPOCH_METHOD_CLEARED_BIT_SET(ptr) (METHOD_FLAG_PREDICATE(ptr, (PREVIOUS_EPOCH_BIT << META_SHIFT)))

#endif // SHARE_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFRTRACEIDMACROS_HPP
9 changes: 5 additions & 4 deletions src/hotspot/share/jfr/support/jfrTraceIdExtension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@
#define REMOVE_METHOD_ID(method) JfrTraceId::remove(method);
#define RESTORE_ID(k) JfrTraceId::restore(k);

static constexpr const uint16_t cleared_epoch_bits = 512 | 256;

class JfrTraceFlag {
private:
mutable uint16_t _flags;
public:
JfrTraceFlag() : _flags(0) {}
JfrTraceFlag() : _flags(cleared_epoch_bits) {}
bool is_set(uint16_t flag) const {
return (_flags & flag) != 0;
}
Expand Down Expand Up @@ -96,9 +98,8 @@ class JfrTraceFlag {
uint8_t* trace_meta_addr() const { \
return _trace_flags.meta_addr(); \
} \
void copy_trace_flags(uint8_t src_flags) const { \
uint8_t flags = *_trace_flags.flags_addr(); \
_trace_flags.set_flags(flags | src_flags); \
void copy_trace_flags(uint16_t rhs_flags) const { \
_trace_flags.set_flags(_trace_flags.flags() | rhs_flags); \
}

#endif // SHARE_JFR_SUPPORT_JFRTRACEIDEXTENSION_HPP
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/jvmtiRedefineClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
}
}
}
JFR_ONLY(k_new_method->copy_trace_flags(*k_old_method->trace_flags_addr());)
JFR_ONLY(k_new_method->copy_trace_flags(k_old_method->trace_flags());)
log_trace(redefine, class, normalize)
("Method matched: new: %s [%d] == old: %s [%d]",
k_new_method->name_and_sig_as_C_string(), ni, k_old_method->name_and_sig_as_C_string(), oi);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
Expand Down Expand Up @@ -78,6 +78,7 @@
import com.sun.tools.javac.code.Symbol.RecordComponent;
import com.sun.tools.javac.code.Type;
import static com.sun.tools.javac.code.TypeTag.BOT;
import static com.sun.tools.javac.code.TypeTag.VOID;
import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant;
import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.tree.JCTree;
Expand Down Expand Up @@ -1260,7 +1261,11 @@ public void visitLambda(JCLambda tree) {
tree.body = translate(tree.body);
if (deconstructorCalls != null) {
if (tree.body instanceof JCExpression value) {
tree.body = make.Block(0, List.of(make.Return(value)));
if (value.type.hasTag(VOID)) {
tree.body = make.Block(0, List.of(make.Exec(value)));
} else {
tree.body = make.Block(0, List.of(make.Return(value)));
}
}
if (tree.body instanceof JCBlock block) {
preparePatternMatchingCatchIfNeeded(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static int ScrollConsoleScreenBuffer(
MethodHandle mh$ = requireNonNull(ScrollConsoleScreenBufferW$MH, "ScrollConsoleScreenBuffer");
try {
return (int)
mh$.invokeExact(hConsoleOutput, lpScrollRectangle, lpClipRectangle, dwDestinationOrigin, lpFill);
mh$.invokeExact(hConsoleOutput, lpScrollRectangle.seg, lpClipRectangle.seg, dwDestinationOrigin.seg, lpFill.seg);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* 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 8335817
* @summary Verify synthetic catches for deconstruction patterns work properly in expression lambdas
* @compile MatchExceptionLambdaExpression.java
* @run main MatchExceptionLambdaExpression
*/
public class MatchExceptionLambdaExpression {

public static void main(String[] args) {
try {
doRunPrimitiveVoid(new A("", true), o -> checkPrimitiveVoid(o instanceof A(String s, _), true));
throw new AssertionError("Didn't gete the expected exception!");
} catch (MatchException ex) {
if (ex.getCause() instanceof RequestedException) {
//correct
} else {
throw ex;
}
}
try {
doRunPrimitiveVoid(new A("", true), o -> checkVoidBox(o instanceof A(String s, _), true));
throw new AssertionError("Didn't gete the expected exception!");
} catch (MatchException ex) {
if (ex.getCause() instanceof RequestedException) {
//correct
} else {
throw ex;
}
}
try {
doRunPrimitiveVoid(new A("", true), o -> checkNonVoid(o instanceof A(String s, _), true));
throw new AssertionError("Didn't gete the expected exception!");
} catch (MatchException ex) {
if (ex.getCause() instanceof RequestedException) {
//correct
} else {
throw ex;
}
}
try {
doRunVoidBox(new A("", true), o -> checkVoidBox(o instanceof A(String s, _), true));
throw new AssertionError("Didn't gete the expected exception!");
} catch (MatchException ex) {
if (ex.getCause() instanceof RequestedException) {
//correct
} else {
throw ex;
}
}
try {
doRunNonVoid(new A("", true), o -> checkVoidBox(o instanceof A(String s, _), true));
throw new AssertionError("Didn't gete the expected exception!");
} catch (MatchException ex) {
if (ex.getCause() instanceof RequestedException) {
//correct
} else {
throw ex;
}
}
try {
doRunNonVoid(new A("", true), o -> checkNonVoid(o instanceof A(String s, _), true));
throw new AssertionError("Didn't gete the expected exception!");
} catch (MatchException ex) {
if (ex.getCause() instanceof RequestedException) {
//correct
} else {
throw ex;
}
}
}

static void doRunPrimitiveVoid(Object inp, PrimitiveVoidFI toRun) {
toRun.run(inp);
}

static void doRunVoidBox(Object inp, VoidBoxFI toRun) {
toRun.run(inp);
}

static void doRunNonVoid(Object inp, NonVoidFI toRun) {
toRun.run(inp);
}

static void checkPrimitiveVoid(boolean a, boolean shouldNotBeCalled) {
if (shouldNotBeCalled) {
throw new AssertionError("Should not be called.");
}
}

static Void checkVoidBox(boolean a, boolean shouldNotBeCalled) {
if (shouldNotBeCalled) {
throw new AssertionError("Should not be called.");
}
return null;
}

static Object checkNonVoid(boolean a, boolean shouldNotBeCalled) {
if (shouldNotBeCalled) {
throw new AssertionError("Should not be called.");
}
return null;
}

interface PrimitiveVoidFI {
public void run(Object o);
}

interface VoidBoxFI {
public Void run(Object o);
}

interface NonVoidFI {
public Object run(Object o);
}

record A(String s, boolean fail) {
public String s() {
if (fail) {
throw new RequestedException();
}
return s;
}
}

static class RequestedException extends RuntimeException {}
}

0 comments on commit e757078

Please sign in to comment.