changeset 14815:8ca2c23fb8b4

Share the same image with hotspot.
author jlaskey
date Mon, 21 Dec 2015 11:47:11 -0400
parents 28e85e3dd788
children a4d427c2c81b
files make/mapfiles/libjimage/mapfile-vers src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java src/java.base/share/native/libjimage/BasicImageReader.cpp src/java.base/share/native/libjimage/imageFile.cpp src/java.base/share/native/libjimage/imageFile.hpp
diffstat 5 files changed, 102 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/make/mapfiles/libjimage/mapfile-vers	Mon Dec 21 11:47:09 2015 -0400
+++ b/make/mapfiles/libjimage/mapfile-vers	Mon Dec 21 11:47:11 2015 -0400
@@ -27,23 +27,7 @@
 
 SUNWprivate_1.1 {
     global:
-        JNI_OnLoad;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_openImage;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_closeImage;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_getIndexAddress;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_getDataAddress;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_read;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_readCompressed;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_getStringBytes;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_getAttributes;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_findAttributes;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_attributeOffsets;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Open;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Close;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1FindResource;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1GetResource;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1PackageToModule;
-        Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Resources;
+        Java_jdk_internal_jimage_BasicImageReader_getNativeMap;
         JIMAGE_Open;
         JIMAGE_Close;
         JIMAGE_PackageToModule;
--- a/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java	Mon Dec 21 11:47:09 2015 -0400
+++ b/src/java.base/share/classes/jdk/internal/jimage/BasicImageReader.java	Mon Dec 21 11:47:11 2015 -0400
@@ -58,6 +58,8 @@
     private final ImageStringsReader stringsReader;
     private final Decompressor decompressor;
 
+    private native static ByteBuffer getNativeMap(String imagePath);
+
     protected BasicImageReader(String imagePath, ByteOrder byteOrder)
             throws IOException {
         this.byteOrder = byteOrder;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.base/share/native/libjimage/BasicImageReader.cpp	Mon Dec 21 11:47:11 2015 -0400
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <string.h>
+
+#include "jni.h"
+#include "jni_util.h"
+
+#include "endian.hpp"
+#include "imageDecompressor.hpp"
+#include "imageFile.hpp"
+#include "inttypes.hpp"
+#include "jimage.hpp"
+#include "osSupport.hpp"
+
+#include "jdk_internal_jimage_BasicImageReader.h"
+
+
+JNIEXPORT jobject JNICALL
+Java_jdk_internal_jimage_BasicImageReader_getNativeMap(JNIEnv *env,
+        jclass cls, jstring path) {
+    const char *nativePath = env->GetStringUTFChars(path, NULL);
+    ImageFileReader* reader = ImageFileReader::find_image(nativePath);
+    env->ReleaseStringUTFChars(path, nativePath);
+
+    if (reader != NULL) {
+        return env->NewDirectByteBuffer(reader->get_index_address(), (jlong)reader->map_size());
+    }
+
+    return 0;
+}
--- a/src/java.base/share/native/libjimage/imageFile.cpp	Mon Dec 21 11:47:09 2015 -0400
+++ b/src/java.base/share/native/libjimage/imageFile.cpp	Mon Dec 21 11:47:11 2015 -0400
@@ -35,7 +35,7 @@
 #include "osSupport.hpp"
 
 // Map the full jimage, only with 64 bit addressing.
-bool MemoryMapImage = sizeof(void *) == 8;
+bool ImageFileReader::memory_map_image = sizeof(void *) == 8;
 
 #ifdef WIN32
 const char FileSeparator = '\\';
@@ -247,26 +247,34 @@
 
 SimpleCriticalSection _reader_table_lock;
 
+// Locate an image if file already open.
+ImageFileReader* ImageFileReader::find_image(const char* name) {
+    // Lock out _reader_table.
+    SimpleCriticalSectionLock cs(&_reader_table_lock);
+    // Search for an exist image file.
+    for (u4 i = 0; i < _reader_table.count(); i++) {
+        // Retrieve table entry.
+        ImageFileReader* reader = _reader_table.get(i);
+        // If name matches, then reuse (bump up use count.)
+        assert(reader->name() != NULL && "reader->name must not be null");
+        if (strcmp(reader->name(), name) == 0) {
+            reader->inc_use();
+            return reader;
+        }
+    }
+
+    return NULL;
+}
+
 // Open an image file, reuse structure if file already open.
 ImageFileReader* ImageFileReader::open(const char* name, bool big_endian) {
-    {
-        // Lock out _reader_table.
-        SimpleCriticalSectionLock cs(&_reader_table_lock);
-        // Search for an exist image file.
-        for (u4 i = 0; i < _reader_table.count(); i++) {
-            // Retrieve table entry.
-            ImageFileReader* reader = _reader_table.get(i);
-            // If name matches, then reuse (bump up use count.)
-            assert(reader->name() != NULL && "reader->name must not be null");
-            if (strcmp(reader->name(), name) == 0) {
-                reader->inc_use();
-                return reader;
-            }
-        }
-    } // Unlock the mutex
+    ImageFileReader* reader = find_image(name);
+    if (reader != NULL) {
+        return reader;
+    }
 
     // Need a new image reader.
-    ImageFileReader* reader = new ImageFileReader(name, big_endian);
+    reader = new ImageFileReader(name, big_endian);
     if (reader == NULL || !reader->open()) {
         // Failed to open.
         delete reader;
@@ -306,21 +314,21 @@
 }
 
 // Return an id for the specifed ImageFileReader.
-u8 ImageFileReader::readerToID(ImageFileReader *reader) {
+u8 ImageFileReader::reader_to_ID(ImageFileReader *reader) {
     // ID is just the cloaked reader address.
     return (u8)reader;
 }
 
 // Validate the image id.
-bool ImageFileReader::idCheck(u8 id) {
+bool ImageFileReader::id_check(u8 id) {
     // Make sure the ID is a managed (_reader_table) reader.
     SimpleCriticalSectionLock cs(&_reader_table_lock);
     return _reader_table.contains((ImageFileReader*)id);
 }
 
 // Return an id for the specifed ImageFileReader.
-ImageFileReader* ImageFileReader::idToReader(u8 id) {
-    assert(idCheck(id) && "invalid image id");
+ImageFileReader* ImageFileReader::id_to_reader(u8 id) {
+    assert(id_check(id) && "invalid image id");
     return (ImageFileReader*)id;
 }
 
@@ -373,10 +381,8 @@
     if (_file_size < _index_size) {
         return false;
     }
-    // Determine how much of the image is memory mapped.
-    size_t map_size = (size_t)(MemoryMapImage ? _file_size : _index_size);
     // Memory map image (minimally the index.)
-    _index_data = (u1*)osSupport::map_memory(_fd, _name, 0, map_size);
+    _index_data = (u1*)osSupport::map_memory(_fd, _name, 0, (size_t)map_size());
     assert(_index_data && "image file not memory mapped");
     // Retrieve length of index perfect hash table.
     u4 length = table_length();
@@ -578,7 +584,7 @@
     if (compressed_size != 0) {
         u1* compressed_data;
         // If not memory mapped read in bytes.
-        if (!MemoryMapImage) {
+        if (!memory_map_image) {
             // Allocate buffer for compression.
             compressed_data = new u1[(size_t)compressed_size];
             assert(compressed_data != NULL && "allocation failed");
@@ -594,7 +600,7 @@
         ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, uncompressed_size,
                         &strings, _endian);
         // If not memory mapped then release temporary buffer.
-        if (!MemoryMapImage) {
+        if (!memory_map_image) {
                 delete[] compressed_data;
         }
     } else {
--- a/src/java.base/share/native/libjimage/imageFile.hpp	Mon Dec 21 11:47:09 2015 -0400
+++ b/src/java.base/share/native/libjimage/imageFile.hpp	Mon Dec 21 11:47:11 2015 -0400
@@ -401,6 +401,9 @@
     // multiple uses (ex. loader.)
     static ImageFileReaderTable _reader_table;
 
+    // true if image should be fully memory mapped.
+    static bool memory_map_image;
+
     char* _name;         // Name of image
     s4 _use;             // Use count
     int _fd;             // File descriptor
@@ -436,6 +439,9 @@
         MINOR_VERSION = 0
     };
 
+    // Locate an image if file already open.
+    static ImageFileReader* find_image(const char* name);
+
     // Open an image file, reuse structure if file already open.
     static ImageFileReader* open(const char* name, bool big_endian = Endian::is_big_endian());
 
@@ -443,13 +449,13 @@
     static void close(ImageFileReader *reader);
 
     // Return an id for the specifed ImageFileReader.
-    static u8 readerToID(ImageFileReader *reader);
+    static u8 reader_to_ID(ImageFileReader *reader);
 
     // Validate the image id.
-    static bool idCheck(u8 id);
+    static bool id_check(u8 id);
 
     // Return an id for the specifed ImageFileReader.
-    static ImageFileReader* idToReader(u8 id);
+    static ImageFileReader* id_to_reader(u8 id);
 
     // Open image file for read access.
     bool open();
@@ -472,6 +478,11 @@
         return _file_size;
     }
 
+    // Retrieve the size of the mapped image.
+    inline u8 map_size() const {
+        return (u8)(memory_map_image ? _file_size : _index_size);
+    }
+
     // Return first address of index data.
     inline u1* get_index_address() const {
         return _index_data;