提交 32f125eb 编写于 作者: H hseigel

8011773: Some tests on Interned String crashed JVM with OOM

Summary: Instead of terminating the VM, throw OutOfMemoryError exceptions.
Reviewed-by: coleenp, dholmes
上级 ce070a6e
...@@ -315,15 +315,19 @@ Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jch ...@@ -315,15 +315,19 @@ Handle java_lang_String::char_converter(Handle java_string, jchar from_char, jch
return string; return string;
} }
jchar* java_lang_String::as_unicode_string(oop java_string, int& length) { jchar* java_lang_String::as_unicode_string(oop java_string, int& length, TRAPS) {
typeArrayOop value = java_lang_String::value(java_string); typeArrayOop value = java_lang_String::value(java_string);
int offset = java_lang_String::offset(java_string); int offset = java_lang_String::offset(java_string);
length = java_lang_String::length(java_string); length = java_lang_String::length(java_string);
jchar* result = NEW_RESOURCE_ARRAY(jchar, length); jchar* result = NEW_RESOURCE_ARRAY_RETURN_NULL(jchar, length);
if (result != NULL) {
for (int index = 0; index < length; index++) { for (int index = 0; index < length; index++) {
result[index] = value->char_at(index + offset); result[index] = value->char_at(index + offset);
} }
} else {
THROW_MSG_0(vmSymbols::java_lang_OutOfMemoryError(), "could not allocate Unicode string");
}
return result; return result;
} }
......
...@@ -153,7 +153,7 @@ class java_lang_String : AllStatic { ...@@ -153,7 +153,7 @@ class java_lang_String : AllStatic {
static char* as_utf8_string(oop java_string, char* buf, int buflen); static char* as_utf8_string(oop java_string, char* buf, int buflen);
static char* as_utf8_string(oop java_string, int start, int len); static char* as_utf8_string(oop java_string, int start, int len);
static char* as_platform_dependent_str(Handle java_string, TRAPS); static char* as_platform_dependent_str(Handle java_string, TRAPS);
static jchar* as_unicode_string(oop java_string, int& length); static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
// produce an ascii string with all other values quoted using \u#### // produce an ascii string with all other values quoted using \u####
static char* as_quoted_ascii(oop java_string); static char* as_quoted_ascii(oop java_string);
......
...@@ -735,7 +735,7 @@ oop StringTable::intern(oop string, TRAPS) ...@@ -735,7 +735,7 @@ oop StringTable::intern(oop string, TRAPS)
ResourceMark rm(THREAD); ResourceMark rm(THREAD);
int length; int length;
Handle h_string (THREAD, string); Handle h_string (THREAD, string);
jchar* chars = java_lang_String::as_unicode_string(string, length); jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL);
oop result = intern(h_string, chars, length, CHECK_NULL); oop result = intern(h_string, chars, length, CHECK_NULL);
return result; return result;
} }
......
...@@ -539,6 +539,9 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC { ...@@ -539,6 +539,9 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
#define NEW_RESOURCE_ARRAY(type, size)\ #define NEW_RESOURCE_ARRAY(type, size)\
(type*) resource_allocate_bytes((size) * sizeof(type)) (type*) resource_allocate_bytes((size) * sizeof(type))
#define NEW_RESOURCE_ARRAY_RETURN_NULL(type, size)\
(type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
#define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\ #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\
(type*) resource_allocate_bytes(thread, (size) * sizeof(type)) (type*) resource_allocate_bytes(thread, (size) * sizeof(type))
......
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -103,11 +103,17 @@ intptr_t oopDesc::slow_identity_hash() { ...@@ -103,11 +103,17 @@ intptr_t oopDesc::slow_identity_hash() {
// When String table needs to rehash // When String table needs to rehash
unsigned int oopDesc::new_hash(jint seed) { unsigned int oopDesc::new_hash(jint seed) {
EXCEPTION_MARK;
ResourceMark rm; ResourceMark rm;
int length; int length;
jchar* chars = java_lang_String::as_unicode_string(this, length); jchar* chars = java_lang_String::as_unicode_string(this, length, THREAD);
if (chars != NULL) {
// Use alternate hashing algorithm on the string // Use alternate hashing algorithm on the string
return AltHashing::murmur3_32(seed, chars, length); return AltHashing::murmur3_32(seed, chars, length);
} else {
vm_exit_out_of_memory(length, "unable to create Unicode strings for String table rehash");
return 0;
}
} }
VerifyOopClosure VerifyOopClosure::verify_oop; VerifyOopClosure VerifyOopClosure::verify_oop;
......
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -310,12 +310,8 @@ WB_END ...@@ -310,12 +310,8 @@ WB_END
WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
ResourceMark rm(THREAD); ResourceMark rm(THREAD);
int len; int len;
jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len); jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
oop found_string = StringTable::the_table()->lookup(name, len); return (StringTable::lookup(name, len) != NULL);
if (found_string == NULL) {
return false;
}
return true;
WB_END WB_END
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册