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 17, 2024
2 parents a22a806 + b9b0b85 commit 787e9c8
Show file tree
Hide file tree
Showing 31 changed files with 606 additions and 166 deletions.
14 changes: 7 additions & 7 deletions src/hotspot/share/c1/c1_RangeCheckElimination.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -483,14 +483,14 @@ void RangeCheckEliminator::in_block_motion(BlockBegin *block, AccessIndexedList

if (c) {
jint value = c->type()->as_IntConstant()->value();
if (value != min_jint) {
if (ao->op() == Bytecodes::_isub) {
value = -value;
}
if (ao->op() == Bytecodes::_iadd) {
base = java_add(base, value);
last_integer = base;
last_instruction = other;
} else {
assert(ao->op() == Bytecodes::_isub, "unexpected bytecode");
base = java_subtract(base, value);
}
last_integer = base;
last_instruction = other;
index = other;
} else {
break;
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/ci/ciMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
ciEnv *env = CURRENT_ENV;
if (env->jvmti_can_hotswap_or_post_breakpoint()) {
// 6328518 check hotswap conditions under the right lock.
MutexLocker locker(Compile_lock);
bool should_take_Compile_lock = !Compile_lock->owned_by_self();
ConditionalMutexLocker locker(Compile_lock, should_take_Compile_lock, Mutex::_safepoint_check_flag);
if (Dependencies::check_evol_method(h_m()) != nullptr) {
_is_c1_compilable = false;
_is_c2_compilable = false;
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/classfile/classLoaderStats.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 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 @@ -82,9 +82,9 @@ class ClassLoaderStats : public ResourceObj {
uintx _hidden_classes_count;

ClassLoaderStats() :
_cld(0),
_class_loader(0),
_parent(0),
_cld(nullptr),
_class_loader(),
_parent(),
_chunk_sz(0),
_block_sz(0),
_classes_count(0),
Expand Down
21 changes: 19 additions & 2 deletions src/hotspot/share/classfile/symbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,23 @@ Symbol* SymbolTable::lookup_common(const char* name,
return sym;
}

// Symbols should represent entities from the constant pool that are
// limited to <64K in length, but usage errors creep in allowing Symbols
// to be used for arbitrary strings. For debug builds we will assert if
// a string is too long, whereas product builds will truncate it.
static int check_length(const char* name, int len) {
assert(len <= Symbol::max_length(),
"String length %d exceeds the maximum Symbol length of %d", len, Symbol::max_length());
if (len > Symbol::max_length()) {
warning("A string \"%.80s ... %.80s\" exceeds the maximum Symbol "
"length of %d and has been truncated", name, (name + len - 80), Symbol::max_length());
len = Symbol::max_length();
}
return len;
}

Symbol* SymbolTable::new_symbol(const char* name, int len) {
assert(len <= Symbol::max_length(), "sanity");
len = check_length(name, len);
unsigned int hash = hash_symbol(name, len, _alt_hash);
Symbol* sym = lookup_common(name, len, hash);
if (sym == nullptr) {
Expand Down Expand Up @@ -485,6 +500,7 @@ void SymbolTable::new_symbols(ClassLoaderData* loader_data, const constantPoolHa
for (int i = 0; i < names_count; i++) {
const char *name = names[i];
int len = lengths[i];
assert(len <= Symbol::max_length(), "must be - these come from the constant pool");
unsigned int hash = hashValues[i];
assert(lookup_shared(name, len, hash) == nullptr, "must have checked already");
Symbol* sym = do_add_if_needed(name, len, hash, is_permanent);
Expand All @@ -494,6 +510,7 @@ void SymbolTable::new_symbols(ClassLoaderData* loader_data, const constantPoolHa
}

Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, bool is_permanent) {
assert(len <= Symbol::max_length(), "caller should have ensured this");
SymbolTableLookup lookup(name, len, hash);
SymbolTableGet stg;
bool clean_hint = false;
Expand Down Expand Up @@ -542,7 +559,7 @@ Symbol* SymbolTable::do_add_if_needed(const char* name, int len, uintx hash, boo

Symbol* SymbolTable::new_permanent_symbol(const char* name) {
unsigned int hash = 0;
int len = (int)strlen(name);
int len = check_length(name, (int)strlen(name));
Symbol* sym = SymbolTable::lookup_only(name, len, hash);
if (sym == nullptr) {
sym = do_add_if_needed(name, len, hash, /* is_permanent */ true);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/oops/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ uint32_t Symbol::pack_hash_and_refcount(short hash, int refcount) {
}

Symbol::Symbol(const u1* name, int length, int refcount) {
assert(length <= max_length(), "SymbolTable should have caught this!");
_hash_and_refcount = pack_hash_and_refcount((short)os::random(), refcount);
_length = (u2)length;
// _body[0..1] are allocated in the header just by coincidence in the current
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/oops/symbol.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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 @@ -130,6 +130,7 @@ class Symbol : public MetaspaceObj {
return (int)heap_word_size(byte_size(length));
}

// Constructor is private for use only by SymbolTable.
Symbol(const u1* name, int length, int refcount);

static short extract_hash(uint32_t value) { return (short)(value >> 16); }
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/opto/ifnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ bool IfNode::cmpi_folds(PhaseIterGVN* igvn, bool fold_ne) {
bool IfNode::is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn) {
return ctrl != nullptr &&
ctrl->is_Proj() &&
ctrl->outcnt() == 1 && // No side-effects
ctrl->in(0) != nullptr &&
ctrl->in(0)->Opcode() == Op_If &&
ctrl->in(0)->outcnt() == 2 &&
Expand Down Expand Up @@ -1346,7 +1347,7 @@ Node* IfNode::fold_compares(PhaseIterGVN* igvn) {

if (cmpi_folds(igvn)) {
Node* ctrl = in(0);
if (is_ctrl_folds(ctrl, igvn) && ctrl->outcnt() == 1) {
if (is_ctrl_folds(ctrl, igvn)) {
// A integer comparison immediately dominated by another integer
// comparison
ProjNode* success = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/opto/machnode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ class MachSafePointNode : public MachReturnNode {
assert(verify_jvms(jvms), "jvms must match");
return in(_jvmadj + jvms->monitor_box_offset(idx));
}
Node* scalarized_obj(const JVMState* jvms, uint idx) const {
assert(verify_jvms(jvms), "jvms must match");
return in(_jvmadj + jvms->scloff() + idx);
}
void set_local(const JVMState* jvms, uint idx, Node *c) {
assert(verify_jvms(jvms), "jvms must match");
set_req(_jvmadj + jvms->locoff() + idx, c);
Expand Down
26 changes: 25 additions & 1 deletion src/hotspot/share/opto/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,27 @@ bool PhaseOutput::contains_as_owner(GrowableArray<MonitorValue*> *monarray, Obje
return false;
}

// Determine if there is a scalar replaced object description represented by 'ov'.
bool PhaseOutput::contains_as_scalarized_obj(JVMState* jvms, MachSafePointNode* sfn,
GrowableArray<ScopeValue*>* objs,
ObjectValue* ov) const {
for (int i = 0; i < jvms->scl_size(); i++) {
Node* n = sfn->scalarized_obj(jvms, i);
// Other kinds of nodes that we may encounter here, for instance constants
// representing values of fields of objects scalarized, aren't relevant for
// us, since they don't map to ObjectValue.
if (!n->is_SafePointScalarObject()) {
continue;
}

ObjectValue* other = (ObjectValue*) sv_for_node_id(objs, n->_idx);
if (ov == other) {
return true;
}
}
return false;
}

//--------------------------Process_OopMap_Node--------------------------------
void PhaseOutput::Process_OopMap_Node(MachNode *mach, int current_offset) {
// Handle special safepoint nodes for synchronization
Expand Down Expand Up @@ -1137,7 +1158,10 @@ void PhaseOutput::Process_OopMap_Node(MachNode *mach, int current_offset) {

for (int j = 0; j< merge->possible_objects()->length(); j++) {
ObjectValue* ov = merge->possible_objects()->at(j)->as_ObjectValue();
bool is_root = locarray->contains(ov) || exparray->contains(ov) || contains_as_owner(monarray, ov);
bool is_root = locarray->contains(ov) ||
exparray->contains(ov) ||
contains_as_owner(monarray, ov) ||
contains_as_scalarized_obj(jvms, sfn, objs, ov);
ov->set_root(is_root);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/opto/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class PhaseOutput : public Phase {

bool starts_bundle(const Node *n) const;
bool contains_as_owner(GrowableArray<MonitorValue*> *monarray, ObjectValue *ov) const;
bool contains_as_scalarized_obj(JVMState* jvms, MachSafePointNode* sfn,
GrowableArray<ScopeValue*>* objs,
ObjectValue* ov) const;

// Dump formatted assembly
#if defined(SUPPORT_OPTO_ASSEMBLY)
Expand Down
42 changes: 35 additions & 7 deletions src/hotspot/share/opto/superword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2954,27 +2954,55 @@ void VTransform::adjust_pre_loop_limit_to_align_main_loop_vectors() {
TRACE_ALIGN_VECTOR_NODE(mask_AW);
TRACE_ALIGN_VECTOR_NODE(adjust_pre_iter);

// 4: Compute (3a, b):
// 4: The computation of the new pre-loop limit could overflow (for 3a) or
// underflow (for 3b) the int range. This is problematic in combination
// with Range Check Elimination (RCE), which determines a "safe" range
// where a RangeCheck will always succeed. RCE adjusts the pre-loop limit
// such that we only enter the main-loop once we have reached the "safe"
// range, and adjusts the main-loop limit so that we exit the main-loop
// before we leave the "safe" range. After RCE, the range of the main-loop
// can only be safely narrowed, and should never be widened. Hence, the
// pre-loop limit can only be increased (for stride > 0), but an add
// overflow might decrease it, or decreased (for stride < 0), but a sub
// underflow might increase it. To prevent that, we perform the Sub / Add
// and Max / Min with long operations.
old_limit = new ConvI2LNode(old_limit);
orig_limit = new ConvI2LNode(orig_limit);
adjust_pre_iter = new ConvI2LNode(adjust_pre_iter);
phase()->register_new_node(old_limit, pre_ctrl);
phase()->register_new_node(orig_limit, pre_ctrl);
phase()->register_new_node(adjust_pre_iter, pre_ctrl);
TRACE_ALIGN_VECTOR_NODE(old_limit);
TRACE_ALIGN_VECTOR_NODE(orig_limit);
TRACE_ALIGN_VECTOR_NODE(adjust_pre_iter);

// 5: Compute (3a, b):
// new_limit = old_limit + adjust_pre_iter (stride > 0)
// new_limit = old_limit - adjust_pre_iter (stride < 0)
//
Node* new_limit = nullptr;
if (stride < 0) {
new_limit = new SubINode(old_limit, adjust_pre_iter);
new_limit = new SubLNode(old_limit, adjust_pre_iter);
} else {
new_limit = new AddINode(old_limit, adjust_pre_iter);
new_limit = new AddLNode(old_limit, adjust_pre_iter);
}
phase()->register_new_node(new_limit, pre_ctrl);
TRACE_ALIGN_VECTOR_NODE(new_limit);

// 5: Compute (15a, b):
// 6: Compute (15a, b):
// Prevent pre-loop from going past the original limit of the loop.
Node* constrained_limit =
(stride > 0) ? (Node*) new MinINode(new_limit, orig_limit)
: (Node*) new MaxINode(new_limit, orig_limit);
(stride > 0) ? (Node*) new MinLNode(phase()->C, new_limit, orig_limit)
: (Node*) new MaxLNode(phase()->C, new_limit, orig_limit);
phase()->register_new_node(constrained_limit, pre_ctrl);
TRACE_ALIGN_VECTOR_NODE(constrained_limit);

// 7: We know that the result is in the int range, there is never truncation
constrained_limit = new ConvL2INode(constrained_limit);
phase()->register_new_node(constrained_limit, pre_ctrl);
TRACE_ALIGN_VECTOR_NODE(constrained_limit);

// 6: Hack the pre-loop limit
// 8: Hack the pre-loop limit
igvn().replace_input_of(pre_opaq, 1, constrained_limit);
}

Expand Down
29 changes: 17 additions & 12 deletions src/hotspot/share/utilities/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include "utilities/events.hpp"
#include "utilities/exceptions.hpp"

// Limit exception message components to 64K (the same max as Symbols)
#define MAX_LEN 65535

// Implementation of ThreadShadow
void check_ThreadShadow() {
const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception);
Expand Down Expand Up @@ -114,10 +117,11 @@ bool Exceptions::special_exception(JavaThread* thread, const char* file, int lin
if (h_exception.is_null() && !thread->can_call_java()) {
ResourceMark rm(thread);
const char* exc_value = h_name != nullptr ? h_name->as_C_string() : "null";
log_info(exceptions)("Thread cannot call Java so instead of throwing exception <%s%s%s> (" PTR_FORMAT ") \n"
log_info(exceptions)("Thread cannot call Java so instead of throwing exception <%.*s%s%.*s> (" PTR_FORMAT ") \n"
"at [%s, line %d]\nfor thread " PTR_FORMAT ",\n"
"throwing pre-allocated exception: %s",
exc_value, message ? ": " : "", message ? message : "",
MAX_LEN, exc_value, message ? ": " : "",
MAX_LEN, message ? message : "",
p2i(h_exception()), file, line, p2i(thread),
Universe::vm_exception()->print_value_string());
// We do not care what kind of exception we get for a thread which
Expand All @@ -143,10 +147,11 @@ void Exceptions::_throw(JavaThread* thread, const char* file, int line, Handle h

// tracing (do this up front - so it works during boot strapping)
// Note, the print_value_string() argument is not called unless logging is enabled!
log_info(exceptions)("Exception <%s%s%s> (" PTR_FORMAT ") \n"
log_info(exceptions)("Exception <%.*s%s%.*s> (" PTR_FORMAT ") \n"
"thrown [%s, line %d]\nfor thread " PTR_FORMAT,
h_exception->print_value_string(),
message ? ": " : "", message ? message : "",
MAX_LEN, h_exception->print_value_string(),
message ? ": " : "",
MAX_LEN, message ? message : "",
p2i(h_exception()), file, line, p2i(thread));

// for AbortVMOnException flag
Expand Down Expand Up @@ -566,13 +571,13 @@ void Exceptions::log_exception(Handle exception, const char* message) {
ResourceMark rm;
const char* detail_message = java_lang_Throwable::message_as_utf8(exception());
if (detail_message != nullptr) {
log_info(exceptions)("Exception <%s: %s>\n thrown in %s",
exception->print_value_string(),
detail_message,
message);
log_info(exceptions)("Exception <%.*s: %.*s>\n thrown in %.*s",
MAX_LEN, exception->print_value_string(),
MAX_LEN, detail_message,
MAX_LEN, message);
} else {
log_info(exceptions)("Exception <%s>\n thrown in %s",
exception->print_value_string(),
message);
log_info(exceptions)("Exception <%.*s>\n thrown in %.*s",
MAX_LEN, exception->print_value_string(),
MAX_LEN, message);
}
}
11 changes: 8 additions & 3 deletions src/hotspot/share/utilities/utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "precompiled.hpp"
#include "memory/allocation.hpp"
#include "utilities/checkedCast.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/utf8.hpp"
Expand Down Expand Up @@ -431,12 +432,16 @@ int UNICODE::utf8_size(jbyte c) {

template<typename T>
int UNICODE::utf8_length(const T* base, int length) {
int result = 0;
size_t result = 0;
for (int index = 0; index < length; index++) {
T c = base[index];
result += utf8_size(c);
int sz = utf8_size(c);
if (result + sz > INT_MAX-1) {
break;
}
result += sz;
}
return result;
return checked_cast<int>(result);
}

template<typename T>
Expand Down
Loading

0 comments on commit 787e9c8

Please sign in to comment.