--- old/src/hotspot/share/classfile/javaClasses.cpp 2018-08-09 13:13:43.400787665 +0200 +++ new/src/hotspot/share/classfile/javaClasses.cpp 2018-08-09 13:13:42.708784234 +0200 @@ -4251,6 +4251,7 @@ int jdk_internal_module_ArchivedModuleGraph::_archivedModuleFinder_offset; int jdk_internal_module_ArchivedModuleGraph::_archivedMainModule_offset; int jdk_internal_module_ArchivedModuleGraph::_archivedConfiguration_offset; +int java_lang_Integer_IntegerCache::_cache_offset; int java_lang_module_Configuration::_EMPTY_CONFIGURATION_offset; int java_util_ImmutableCollections_ListN::_EMPTY_LIST_offset; int java_util_ImmutableCollections_SetN::_EMPTY_SET_offset; @@ -4417,6 +4418,21 @@ return (hardcoded_offset * heapOopSize) + instanceOopDesc::base_offset_in_bytes(); } +#define INTEGERCACHE_FIELDS_DO(macro) \ + macro(_cache_offset, k, "cache", java_lang_Integer_array_signature, true) + +void java_lang_Integer_IntegerCache::compute_offsets() { + InstanceKlass* k = SystemDictionary::Integer_IntegerCache_klass(); + assert(k != NULL, "must be loaded"); + INTEGERCACHE_FIELDS_DO(FIELD_COMPUTE_OFFSET); +} + +#if INCLUDE_CDS +void java_lang_Integer_IntegerCache::serialize(SerializeClosure* f) { + INTEGERCACHE_FIELDS_DO(FIELD_SERIALIZE_OFFSET); +} +#endif + #define ARCHIVEDMODULEGRAPH_FIELDS_DO(macro) \ macro(_archivedSystemModules_offset, k, "archivedSystemModules", systemModules_signature, true); \ macro(_archivedModuleFinder_offset, k, "archivedModuleFinder", moduleFinder_signature, true); \ @@ -4553,6 +4569,7 @@ java_lang_LiveStackFrameInfo::compute_offsets(); java_util_concurrent_locks_AbstractOwnableSynchronizer::compute_offsets(); + java_lang_Integer_IntegerCache::compute_offsets(); java_lang_module_Configuration::compute_offsets(); java_util_ImmutableCollections_ListN::compute_offsets(); java_util_ImmutableCollections_MapN::compute_offsets(); --- old/src/hotspot/share/classfile/javaClasses.hpp 2018-08-09 13:13:45.240796790 +0200 +++ new/src/hotspot/share/classfile/javaClasses.hpp 2018-08-09 13:13:44.552793378 +0200 @@ -1485,6 +1485,15 @@ static void serialize(SerializeClosure* f) NOT_CDS_RETURN; }; +class java_lang_Integer_IntegerCache: AllStatic { + private: + static int _cache_offset; + public: + static int cache_offset() { return _cache_offset; } + static void compute_offsets(); + static void serialize(SerializeClosure* f) NOT_CDS_RETURN; +}; + class jdk_internal_module_ArchivedModuleGraph: AllStatic { private: static int _archivedSystemModules_offset; --- old/src/hotspot/share/classfile/systemDictionary.hpp 2018-08-09 13:13:46.776804406 +0200 +++ new/src/hotspot/share/classfile/systemDictionary.hpp 2018-08-09 13:13:46.088800995 +0200 @@ -215,6 +215,7 @@ do_klass(Byte_klass, java_lang_Byte, Pre ) \ do_klass(Short_klass, java_lang_Short, Pre ) \ do_klass(Integer_klass, java_lang_Integer, Pre ) \ + do_klass(Integer_IntegerCache_klass, java_lang_Integer_IntegerCache, Pre ) \ do_klass(Long_klass, java_lang_Long, Pre ) \ \ /* JVMCI classes. These are loaded on-demand. */ \ --- old/src/hotspot/share/classfile/vmSymbols.hpp 2018-08-09 13:13:48.412812519 +0200 +++ new/src/hotspot/share/classfile/vmSymbols.hpp 2018-08-09 13:13:47.720809087 +0200 @@ -438,6 +438,7 @@ template(fileToEncodedURL_signature, "(Ljava/io/File;)Ljava/net/URL;") \ template(getProtectionDomain_name, "getProtectionDomain") \ template(getProtectionDomain_signature, "(Ljava/security/CodeSource;)Ljava/security/ProtectionDomain;") \ + template(java_lang_Integer_array_signature, "[Ljava/lang/Integer;") \ template(url_code_signer_array_void_signature, "(Ljava/net/URL;[Ljava/security/CodeSigner;)V") \ template(module_entry_name, "module_entry") \ template(resolved_references_name, "") \ --- old/src/hotspot/share/memory/heapShared.cpp 2018-08-09 13:13:50.248821623 +0200 +++ new/src/hotspot/share/memory/heapShared.cpp 2018-08-09 13:13:49.524818033 +0200 @@ -510,6 +510,7 @@ archive_object_graph_do(SystemDictionary::ImmutableCollections_ListN_klass(), java_util_ImmutableCollections_ListN::EMPTY_LIST_offset(), T_OBJECT, CHECK); \ archive_object_graph_do(SystemDictionary::ImmutableCollections_MapN_klass(), java_util_ImmutableCollections_MapN::EMPTY_MAP_offset(), T_OBJECT, CHECK); \ archive_object_graph_do(SystemDictionary::ImmutableCollections_SetN_klass(), java_util_ImmutableCollections_SetN::EMPTY_SET_offset(), T_OBJECT, CHECK); \ + archive_object_graph_do(SystemDictionary::Integer_IntegerCache_klass(), java_lang_Integer_IntegerCache::cache_offset(), T_OBJECT, CHECK); \ archive_object_graph_do(SystemDictionary::Configuration_klass(), java_lang_module_Configuration::EMPTY_CONFIGURATION_offset(), T_OBJECT, CHECK) void HeapShared::archive_module_graph_objects(Thread* THREAD) { --- old/src/java.base/share/classes/java/lang/Integer.java 2018-08-09 13:13:51.820829418 +0200 +++ new/src/java.base/share/classes/java/lang/Integer.java 2018-08-09 13:13:51.132826007 +0200 @@ -997,7 +997,7 @@ private static class IntegerCache { static final int low = -128; static final int high; - static final Integer cache[]; + static @jdk.internal.vm.annotation.Stable Integer cache[]; static { // high value may be configured by property @@ -1016,11 +1016,18 @@ } high = h; - cache = new Integer[(high - low) + 1]; - int j = low; - for(int k = 0; k < cache.length; k++) - cache[k] = new Integer(j++); + // Load IntegerCache.cache from archive, if possible + VM.initializeFromArchive(IntegerCache.class); + int size = (high - low) + 1; + // Use the archived cache if it exists and is large enough + if (cache == null || size > cache.length) { + Integer[] c = new Integer[size]; + int j = low; + for(int k = 0; k < c.length; k++) + c[k] = new Integer(j++); + cache = c; + } // range [-128, 127] must be interned (JLS7 5.1.7) assert IntegerCache.high >= 127; }