Skip to content

Commit bbc5748

Browse files
committed
8272096: Exceptions::new_exception can return wrong exception
Reviewed-by: hseigel, dholmes
1 parent a41b12f commit bbc5748

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/hotspot/os/posix/perfMemory_posix.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,13 @@ static char* get_user_name_slow(int vmid, int nspid, TRAPS) {
644644
// return the name of the user that owns the JVM indicated by the given vmid.
645645
//
646646
static char* get_user_name(int vmid, int *nspid, TRAPS) {
647-
char *result = get_user_name_slow(vmid, *nspid, THREAD);
647+
char *result = get_user_name_slow(vmid, *nspid, CHECK_NULL);
648648

649649
#if defined(LINUX)
650650
// If we are examining a container process without PID namespaces enabled
651651
// we need to use /proc/{pid}/root/tmp to find hsperfdata files.
652652
if (result == NULL) {
653-
result = get_user_name_slow(vmid, vmid, THREAD);
653+
result = get_user_name_slow(vmid, vmid, CHECK_NULL);
654654
// Enable nspid logic going forward
655655
if (result != NULL) *nspid = vmid;
656656
}

src/hotspot/share/classfile/stackMapTable.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -173,13 +173,15 @@ int32_t StackMapReader::chop(
173173
return pos+1;
174174
}
175175

176+
#define CHECK_NT CHECK_(VerificationType::bogus_type())
177+
176178
VerificationType StackMapReader::parse_verification_type(u1* flags, TRAPS) {
177-
u1 tag = _stream->get_u1(THREAD);
179+
u1 tag = _stream->get_u1(CHECK_NT);
178180
if (tag < (u1)ITEM_UninitializedThis) {
179181
return VerificationType::from_tag(tag);
180182
}
181183
if (tag == ITEM_Object) {
182-
u2 class_index = _stream->get_u2(THREAD);
184+
u2 class_index = _stream->get_u2(CHECK_NT);
183185
int nconstants = _cp->length();
184186
if ((class_index <= 0 || class_index >= nconstants) ||
185187
(!_cp->tag_at(class_index).is_klass() &&
@@ -196,7 +198,7 @@ VerificationType StackMapReader::parse_verification_type(u1* flags, TRAPS) {
196198
return VerificationType::uninitialized_this_type();
197199
}
198200
if (tag == ITEM_Uninitialized) {
199-
u2 offset = _stream->get_u2(THREAD);
201+
u2 offset = _stream->get_u2(CHECK_NT);
200202
if (offset >= _code_length ||
201203
_code_data[offset] != ClassVerifier::NEW_OFFSET) {
202204
_verifier->class_format_error(
@@ -214,7 +216,7 @@ StackMapFrame* StackMapReader::next(
214216
StackMapFrame* frame;
215217
int offset;
216218
VerificationType* locals = NULL;
217-
u1 frame_type = _stream->get_u1(THREAD);
219+
u1 frame_type = _stream->get_u1(CHECK_NULL);
218220
if (frame_type < 64) {
219221
// same_frame
220222
if (first) {
@@ -268,7 +270,7 @@ StackMapFrame* StackMapReader::next(
268270
return frame;
269271
}
270272

271-
u2 offset_delta = _stream->get_u2(THREAD);
273+
u2 offset_delta = _stream->get_u2(CHECK_NULL);
272274

273275
if (frame_type < SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
274276
// reserved frame types
@@ -360,7 +362,7 @@ StackMapFrame* StackMapReader::next(
360362
}
361363
u1 flags = pre_frame->flags();
362364
for (i=0; i<appends; i++) {
363-
locals[real_length] = parse_verification_type(&flags, THREAD);
365+
locals[real_length] = parse_verification_type(&flags, CHECK_NULL);
364366
if (locals[real_length].is_category2()) {
365367
locals[real_length + 1] = locals[real_length].to_category2_2nd();
366368
++real_length;
@@ -382,15 +384,15 @@ StackMapFrame* StackMapReader::next(
382384
if (frame_type == FULL) {
383385
// full_frame
384386
u1 flags = 0;
385-
u2 locals_size = _stream->get_u2(THREAD);
387+
u2 locals_size = _stream->get_u2(CHECK_NULL);
386388
int real_locals_size = 0;
387389
if (locals_size > 0) {
388390
locals = NEW_RESOURCE_ARRAY_IN_THREAD(
389391
THREAD, VerificationType, locals_size*2);
390392
}
391393
int i;
392394
for (i=0; i<locals_size; i++) {
393-
locals[real_locals_size] = parse_verification_type(&flags, THREAD);
395+
locals[real_locals_size] = parse_verification_type(&flags, CHECK_NULL);
394396
if (locals[real_locals_size].is_category2()) {
395397
locals[real_locals_size + 1] =
396398
locals[real_locals_size].to_category2_2nd();
@@ -400,15 +402,15 @@ StackMapFrame* StackMapReader::next(
400402
}
401403
check_verification_type_array_size(
402404
real_locals_size, max_locals, CHECK_VERIFY_(_verifier, NULL));
403-
u2 stack_size = _stream->get_u2(THREAD);
405+
u2 stack_size = _stream->get_u2(CHECK_NULL);
404406
int real_stack_size = 0;
405407
VerificationType* stack = NULL;
406408
if (stack_size > 0) {
407409
stack = NEW_RESOURCE_ARRAY_IN_THREAD(
408410
THREAD, VerificationType, stack_size*2);
409411
}
410412
for (i=0; i<stack_size; i++) {
411-
stack[real_stack_size] = parse_verification_type(NULL, THREAD);
413+
stack[real_stack_size] = parse_verification_type(NULL, CHECK_NULL);
412414
if (stack[real_stack_size].is_category2()) {
413415
stack[real_stack_size + 1] = stack[real_stack_size].to_category2_2nd();
414416
++real_stack_size;

src/hotspot/share/prims/nativeLookup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ address NativeLookup::lookup_base(const methodHandle& method, TRAPS) {
416416
address entry = NULL;
417417
ResourceMark rm(THREAD);
418418

419-
entry = lookup_entry(method, THREAD);
419+
entry = lookup_entry(method, CHECK_NULL);
420420
if (entry != NULL) return entry;
421421

422422
// standard native method resolution has failed. Check if there are any
423423
// JVM TI prefixes which have been applied to the native method name.
424-
entry = lookup_entry_prefixed(method, THREAD);
424+
entry = lookup_entry_prefixed(method, CHECK_NULL);
425425
if (entry != NULL) return entry;
426426

427427
// Native function not found, throw UnsatisfiedLinkError

src/hotspot/share/utilities/exceptions.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,14 @@ Handle Exceptions::new_exception(JavaThread* thread, Symbol* name,
351351
if (message == NULL) {
352352
signature = vmSymbols::void_method_signature();
353353
} else {
354-
// We want to allocate storage, but we can't do that if there's
355-
// a pending exception, so we preserve any pending exception
356-
// around the allocation.
357-
// If we get an exception from the allocation, prefer that to
358-
// the exception we are trying to build, or the pending exception.
359-
// This is sort of like what PreserveExceptionMark does, except
360-
// for the preferencing and the early returns.
361-
Handle incoming_exception(thread, NULL);
354+
// There should be no pending exception. The caller is responsible for not calling
355+
// this with a pending exception.
356+
Handle incoming_exception;
362357
if (thread->has_pending_exception()) {
363358
incoming_exception = Handle(thread, thread->pending_exception());
364359
thread->clear_pending_exception();
360+
ResourceMark rm(thread);
361+
assert(incoming_exception.is_null(), "Pending exception while throwing %s %s", name->as_C_string(), message);
365362
}
366363
Handle msg;
367364
if (to_utf8_safe == safe_to_utf8) {
@@ -371,6 +368,8 @@ Handle Exceptions::new_exception(JavaThread* thread, Symbol* name,
371368
// Make a java string keeping the encoding scheme of the original string.
372369
msg = java_lang_String::create_from_platform_dependent_str(message, thread);
373370
}
371+
// If we get an exception from the allocation, prefer that to
372+
// the exception we are trying to build, or the pending exception (in product mode)
374373
if (thread->has_pending_exception()) {
375374
Handle exception(thread, thread->pending_exception());
376375
thread->clear_pending_exception();

0 commit comments

Comments
 (0)