# HG changeset patch # User amurillo # Date 1342211389 25200 # Node ID a0c2fa4baeb6aad6f33dc87b676b21345794d61e # Parent 0aea8f0afd2788e9c5cb2018110940aa31139a91# Parent a4b60109cffcbbb147ada4ec48e19143cc02bf62 Merge diff -r 0aea8f0afd27 -r a0c2fa4baeb6 agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java --- a/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java Wed Jul 11 11:22:49 2012 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/oops/OopUtilities.java Fri Jul 13 13:29:49 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -141,18 +141,19 @@ public static String stringOopToString(Oop stringOop) { if (offsetField == null) { InstanceKlass k = (InstanceKlass) stringOop.getKlass(); - offsetField = (IntField) k.findField("offset", "I"); - countField = (IntField) k.findField("count", "I"); + offsetField = (IntField) k.findField("offset", "I"); // optional + countField = (IntField) k.findField("count", "I"); // optional valueField = (OopField) k.findField("value", "[C"); if (Assert.ASSERTS_ENABLED) { - Assert.that(offsetField != null && - countField != null && - valueField != null, "must find all java.lang.String fields"); + Assert.that(valueField != null, "Field \'value\' of java.lang.String not found"); } } - return charArrayToString((TypeArray) valueField.getValue(stringOop), - offsetField.getValue(stringOop), - countField.getValue(stringOop)); + if (offsetField != null && countField != null) { + return charArrayToString((TypeArray) valueField.getValue(stringOop), + offsetField.getValue(stringOop), + countField.getValue(stringOop)); + } + return charArrayToString((TypeArray) valueField.getValue(stringOop)); } public static String stringOopToEscapedString(Oop stringOop) { diff -r 0aea8f0afd27 -r a0c2fa4baeb6 agent/src/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java --- a/agent/src/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java Wed Jul 11 11:22:49 2012 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java Fri Jul 13 13:29:49 2012 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2012, 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 @@ -85,6 +85,21 @@ this(new ProcImageClassLoader()); } + static void debugPrintln(String msg) { + if (DEBUG) { + System.err.println("DEBUG>" + msg); + } + } + + static void debugPrintStackTrace(Exception exp) { + if (DEBUG) { + StackTraceElement[] els = exp.getStackTrace(); + for (int i = 0; i < els.length; i++) { + System.err.println("DEBUG>" + els[i].toString()); + } + } + } + public Object readObject(Oop oop) throws ClassNotFoundException { if (oop instanceof Instance) { return readInstance((Instance) oop); @@ -120,13 +135,96 @@ } protected Symbol javaLangString; + protected Symbol javaUtilHashtableEntry; + protected Symbol javaUtilHashtable; + protected Symbol javaUtilProperties; + + protected Symbol getVMSymbol(String name) { + return VM.getVM().getSymbolTable().probe(name); + } + protected Symbol javaLangString() { if (javaLangString == null) { - javaLangString = VM.getVM().getSymbolTable().probe("java/lang/String"); + javaLangString = getVMSymbol("java/lang/String"); } return javaLangString; } + protected Symbol javaUtilHashtableEntry() { + if (javaUtilHashtableEntry == null) { + javaUtilHashtableEntry = getVMSymbol("java/util/Hashtable$Entry"); + } + return javaUtilHashtableEntry; + } + + protected Symbol javaUtilHashtable() { + if (javaUtilHashtable == null) { + javaUtilHashtable = getVMSymbol("java/util/Hashtable"); + } + return javaUtilHashtable; + } + + protected Symbol javaUtilProperties() { + if (javaUtilProperties == null) { + javaUtilProperties = getVMSymbol("java/util/Properties"); + } + return javaUtilProperties; + } + + private void setHashtableEntry(java.util.Hashtable p, Oop oop) { + InstanceKlass ik = (InstanceKlass)oop.getKlass(); + OopField keyField = (OopField)ik.findField("key", "Ljava/lang/Object;"); + OopField valueField = (OopField)ik.findField("value", "Ljava/lang/Object;"); + OopField nextField = (OopField)ik.findField("next", "Ljava/util/Hashtable$Entry;"); + if (DEBUG) { + if (Assert.ASSERTS_ENABLED) { + Assert.that(ik.getName().equals(javaUtilHashtableEntry()), "Not a Hashtable$Entry?"); + Assert.that(keyField != null && valueField != null && nextField != null, "Invalid fields!"); + } + } + + Object key = null; + Object value = null; + Oop next = null; + try { + key = readObject(keyField.getValue(oop)); + value = readObject(valueField.getValue(oop)); + next = (Oop)nextField.getValue(oop); + // For Properties, should use setProperty(k, v). Since it only runs in SA + // using put(k, v) should be OK. + p.put(key, value); + if (next != null) { + setHashtableEntry(p, next); + } + } catch (ClassNotFoundException ce) { + if( DEBUG) { + debugPrintln("Class not found " + ce); + debugPrintStackTrace(ce); + } + } + } + + protected Object getHashtable(Instance oop, boolean isProperties) { + InstanceKlass k = (InstanceKlass)oop.getKlass(); + OopField tableField = (OopField)k.findField("table", "[Ljava/util/Hashtable$Entry;"); + if (tableField == null) { + debugPrintln("Could not find field of [Ljava/util/Hashtable$Entry;"); + return null; + } + java.util.Hashtable table = (isProperties) ? new java.util.Properties() + : new java.util.Hashtable(); + ObjArray kvs = (ObjArray)tableField.getValue(oop); + long size = kvs.getLength(); + debugPrintln("Hashtable$Entry Size = " + size); + for (long i=0; ias_C_string(), sym->utf8_length()); -} - // Create a new table and using alternate hash code, populate the new table // with the existing strings. Set flag to use the alternate hash code afterwards. void SymbolTable::rehash_table() { @@ -127,10 +120,6 @@ // Create a new symbol table SymbolTable* new_table = new SymbolTable(); - // Initialize the global seed for hashing. - _seed = AltHashing::compute_seed(); - assert(seed() != 0, "shouldn't be zero"); - the_table()->move_to(new_table); // Delete the table and buckets (entries are reused in new table). @@ -582,7 +571,6 @@ StringTable* StringTable::_the_table = NULL; bool StringTable::_needs_rehashing = false; -jint StringTable::_seed = 0; // Pick hashing algorithm unsigned int StringTable::hash_string(const jchar* s, int len) { @@ -799,14 +787,6 @@ } -unsigned int StringTable::new_hash(oop string) { - ResourceMark rm; - int length; - jchar* chars = java_lang_String::as_unicode_string(string, length); - // Use alternate hashing algorithm on the string - return AltHashing::murmur3_32(seed(), chars, length); -} - // Create a new table and using alternate hash code, populate the new table // with the existing strings. Set flag to use the alternate hash code afterwards. void StringTable::rehash_table() { @@ -815,10 +795,6 @@ if (DumpSharedSpaces) return; StringTable* new_table = new StringTable(); - // Initialize new global seed for hashing. - _seed = AltHashing::compute_seed(); - assert(seed() != 0, "shouldn't be zero"); - // Rehash the table the_table()->move_to(new_table); diff -r 0aea8f0afd27 -r a0c2fa4baeb6 src/share/vm/classfile/symbolTable.hpp --- a/src/share/vm/classfile/symbolTable.hpp Wed Jul 11 11:22:49 2012 -0700 +++ b/src/share/vm/classfile/symbolTable.hpp Fri Jul 13 13:29:49 2012 -0700 @@ -81,7 +81,6 @@ // Set if one bucket is out of balance due to hash algorithm deficiency static bool _needs_rehashing; - static jint _seed; // For statistics static int symbols_removed; @@ -118,10 +117,6 @@ : Hashtable(symbol_table_size, sizeof (HashtableEntry), t, number_of_entries) {} - static bool use_alternate_hashcode() { return _seed != 0; } - static jint seed() { return _seed; } - - unsigned int new_hash(Symbol* sym); public: enum { symbol_alloc_batch_size = 8 @@ -232,7 +227,6 @@ // Set if one bucket is out of balance due to hash algorithm deficiency static bool _needs_rehashing; - static jint _seed; static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS); oop basic_add(int index, Handle string_or_null, jchar* name, int len, @@ -246,11 +240,6 @@ StringTable(HashtableBucket* t, int number_of_entries) : Hashtable((int)StringTableSize, sizeof (HashtableEntry), t, number_of_entries) {} - - static bool use_alternate_hashcode() { return _seed != 0; } - static jint seed() { return _seed; } - - unsigned int new_hash(oop s); public: // The string table static StringTable* the_table() { return _the_table; } diff -r 0aea8f0afd27 -r a0c2fa4baeb6 src/share/vm/compiler/compilerOracle.cpp --- a/src/share/vm/compiler/compilerOracle.cpp Wed Jul 11 11:22:49 2012 -0700 +++ b/src/share/vm/compiler/compilerOracle.cpp Fri Jul 13 13:29:49 2012 -0700 @@ -550,10 +550,12 @@ } } +static const char* default_cc_file = ".hotspot_compiler"; + static const char* cc_file() { #ifdef ASSERT if (CompileCommandFile == NULL) { - return ".hotspot_compiler"; + return default_cc_file; } #endif return CompileCommandFile; @@ -637,10 +639,17 @@ CompilerOracle::parse_from_string(CompileOnly, CompilerOracle::parse_compile_only); if (CompilerOracle::has_command_file()) { CompilerOracle::parse_from_file(); + } else { + struct stat buf; + if (os::stat(default_cc_file, &buf) == 0) { + warning("%s file is present but has been ignored. " + "Run with -XX:CompileCommandFile=%s to load the file.", + default_cc_file, default_cc_file); + } } if (lists[PrintCommand] != NULL) { if (PrintAssembly) { - warning("CompileCommand and/or .hotspot_compiler file contains 'print' commands, but PrintAssembly is also enabled"); + warning("CompileCommand and/or %s file contains 'print' commands, but PrintAssembly is also enabled", default_cc_file); } else if (FLAG_IS_DEFAULT(DebugNonSafepoints)) { warning("printing of assembly code is enabled; turning on DebugNonSafepoints to gain additional output"); DebugNonSafepoints = true; diff -r 0aea8f0afd27 -r a0c2fa4baeb6 src/share/vm/runtime/arguments.cpp --- a/src/share/vm/runtime/arguments.cpp Wed Jul 11 11:22:49 2012 -0700 +++ b/src/share/vm/runtime/arguments.cpp Fri Jul 13 13:29:49 2012 -0700 @@ -2955,7 +2955,10 @@ const char* tail; // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. + const char* hotspotrc = ".hotspotrc"; bool settings_file_specified = false; + bool needs_hotspotrc_warning = false; + const char* flags_file; int index; for (index = 0; index < args->nOptions; index++) { @@ -2999,16 +3002,19 @@ if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) { return JNI_EINVAL; } - } - + } else { #ifdef ASSERT - // Parse default .hotspotrc settings file - if (!settings_file_specified) { + // Parse default .hotspotrc settings file if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) { return JNI_EINVAL; } +#else + struct stat buf; + if (os::stat(hotspotrc, &buf) == 0) { + needs_hotspotrc_warning = true; + } +#endif } -#endif if (PrintVMOptions) { for (index = 0; index < args->nOptions; index++) { @@ -3025,6 +3031,14 @@ return result; } + // Delay warning until here so that we've had a chance to process + // the -XX:-PrintWarnings flag + if (needs_hotspotrc_warning) { + warning("%s file is present but has been ignored. " + "Run with -XX:Flags=%s to load the file.", + hotspotrc, hotspotrc); + } + #if (defined JAVASE_EMBEDDED || defined ARM) UNSUPPORTED_OPTION(UseG1GC, "G1 GC"); #endif diff -r 0aea8f0afd27 -r a0c2fa4baeb6 src/share/vm/utilities/hashtable.cpp --- a/src/share/vm/utilities/hashtable.cpp Wed Jul 11 11:22:49 2012 -0700 +++ b/src/share/vm/utilities/hashtable.cpp Fri Jul 13 13:29:49 2012 -0700 @@ -23,6 +23,8 @@ */ #include "precompiled.hpp" +#include "classfile/altHashing.hpp" +#include "classfile/javaClasses.hpp" #include "memory/allocation.inline.hpp" #include "memory/filemap.hpp" #include "memory/resourceArea.hpp" @@ -103,12 +105,33 @@ return false; } +template jint Hashtable::_seed = 0; + +template unsigned int Hashtable::new_hash(Symbol* sym) { + ResourceMark rm; + // Use alternate hashing algorithm on this symbol. + return AltHashing::murmur3_32(seed(), (const jbyte*)sym->as_C_string(), sym->utf8_length()); +} + +template unsigned int Hashtable::new_hash(oop string) { + ResourceMark rm; + int length; + jchar* chars = java_lang_String::as_unicode_string(string, length); + // Use alternate hashing algorithm on the string + return AltHashing::murmur3_32(seed(), chars, length); +} + // Create a new table and using alternate hash code, populate the new table // with the existing elements. This can be used to change the hash code // and could in the future change the size of the table. template void Hashtable::move_to(Hashtable* new_table) { - int saved_entry_count = number_of_entries(); + + // Initialize the global seed for hashing. + _seed = AltHashing::compute_seed(); + assert(seed() != 0, "shouldn't be zero"); + + int saved_entry_count = this->number_of_entries(); // Iterate through the table and create a new entry for the new table for (int i = 0; i < new_table->table_size(); ++i) { diff -r 0aea8f0afd27 -r a0c2fa4baeb6 src/share/vm/utilities/hashtable.hpp --- a/src/share/vm/utilities/hashtable.hpp Wed Jul 11 11:22:49 2012 -0700 +++ b/src/share/vm/utilities/hashtable.hpp Fri Jul 13 13:29:49 2012 -0700 @@ -278,7 +278,14 @@ // Function to move these elements into the new table. void move_to(Hashtable* new_table); - virtual unsigned int new_hash(T) { ShouldNotReachHere(); return 0; } // should be overridden + static bool use_alternate_hashcode() { return _seed != 0; } + static jint seed() { return _seed; } + + private: + static jint _seed; + + unsigned int new_hash(Symbol* s); + unsigned int new_hash(oop string); };