8221724: Enable archiving of Strings with hash 0
Reviewed-by: jiangli, iklam
This commit is contained in:
parent
1908897b93
commit
3880f3db74
@ -761,10 +761,6 @@ struct CopyToArchive : StackObj {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
unsigned int hash = java_lang_String::hash_code(s);
|
unsigned int hash = java_lang_String::hash_code(s);
|
||||||
if (hash == 0) {
|
|
||||||
// We do not archive Strings with a 0 hashcode because ......
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
java_lang_String::set_hash(s, hash);
|
java_lang_String::set_hash(s, hash);
|
||||||
oop new_s = StringTable::create_archived_string(s, Thread::current());
|
oop new_s = StringTable::create_archived_string(s, Thread::current());
|
||||||
|
@ -280,9 +280,7 @@ void ConstantPool::archive_resolved_references(Thread* THREAD) {
|
|||||||
rr->obj_at_put(i, NULL);
|
rr->obj_at_put(i, NULL);
|
||||||
if (p != NULL && i < ref_map_len) {
|
if (p != NULL && i < ref_map_len) {
|
||||||
int index = object_to_cp_index(i);
|
int index = object_to_cp_index(i);
|
||||||
// Skip the entry if the string hash code is 0 since the string
|
if (tag_at(index).is_string()) {
|
||||||
// is not included in the shared string_table, see StringTable::copy_shared_string.
|
|
||||||
if (tag_at(index).is_string() && java_lang_String::hash_code(p) != 0) {
|
|
||||||
oop op = StringTable::create_archived_string(p, THREAD);
|
oop op = StringTable::create_archived_string(p, THREAD);
|
||||||
// If the String object is not archived (possibly too large),
|
// If the String object is not archived (possibly too large),
|
||||||
// NULL is returned. Also set it in the array, so we won't
|
// NULL is returned. Also set it in the array, so we won't
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2019, 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
|
||||||
@ -66,8 +66,8 @@ public class HelloStringPlus {
|
|||||||
// Check intern() method for "" string
|
// Check intern() method for "" string
|
||||||
String empty = "";
|
String empty = "";
|
||||||
String empty_interned = empty.intern();
|
String empty_interned = empty.intern();
|
||||||
if (wb.isShared(empty)) {
|
if (!wb.isShared(empty)) {
|
||||||
throw new RuntimeException("Empty string should not be shared");
|
throw new RuntimeException("Empty string should be shared");
|
||||||
}
|
}
|
||||||
if (empty_interned != empty) {
|
if (empty_interned != empty) {
|
||||||
throw new RuntimeException("Different string is returned from intern() for empty string");
|
throw new RuntimeException("Different string is returned from intern() for empty string");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2019, 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
|
||||||
@ -25,19 +25,49 @@
|
|||||||
import sun.hotspot.WhiteBox;
|
import sun.hotspot.WhiteBox;
|
||||||
|
|
||||||
public class LockStringTest extends Thread {
|
public class LockStringTest extends Thread {
|
||||||
static String lock = "StringLock";
|
static String lock;
|
||||||
static boolean done = false;
|
static boolean done;
|
||||||
|
static WhiteBox wb = WhiteBox.getWhiteBox();
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
WhiteBox wb = WhiteBox.getWhiteBox();
|
|
||||||
if (wb.areSharedStringsIgnored()) {
|
if (wb.areSharedStringsIgnored()) {
|
||||||
System.out.println("The shared strings are ignored");
|
System.out.println("The shared strings are ignored");
|
||||||
System.out.println("LockStringTest: PASS");
|
System.out.println("LockStringTest: PASS");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!wb.isShared(LockStringTest.class)) {
|
||||||
|
throw new RuntimeException("Failed: LockStringTest class is not shared.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: This class is archived. All string literals (including the ones used in this class)
|
||||||
|
// in all archived classes are interned into the CDS shared string table.
|
||||||
|
|
||||||
|
doTest("StringLock", false);
|
||||||
|
doTest("", true);
|
||||||
|
|
||||||
|
// The following string has a 0 hashCode. Calling String.hashCode() could cause
|
||||||
|
// the String.hash field to be written into, if so make sure we don't functionally
|
||||||
|
// break.
|
||||||
|
doTest("\u0121\u0151\u00a2\u0001\u0001\udbb2", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doTest(String s, boolean hasZeroHashCode) throws Exception {
|
||||||
|
lock = s;
|
||||||
|
done = false;
|
||||||
|
|
||||||
if (!wb.isShared(lock)) {
|
if (!wb.isShared(lock)) {
|
||||||
throw new RuntimeException("Failed: String is not shared.");
|
throw new RuntimeException("Failed: String \"" + lock + "\" is not shared.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasZeroHashCode && lock.hashCode() != 0) {
|
||||||
|
throw new RuntimeException("Shared string \"" + lock + "\" should have 0 hashCode, but is instead " + lock.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
String copy = new String(lock);
|
||||||
|
if (lock.hashCode() != copy.hashCode()) {
|
||||||
|
throw new RuntimeException("Shared string \"" + lock + "\" does not have the same hashCode as its non-shared copy");
|
||||||
}
|
}
|
||||||
|
|
||||||
new LockStringTest().start();
|
new LockStringTest().start();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user