jdk/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp
author rriggs
Fri, 30 Oct 2015 11:12:20 -0400
changeset 33492 051df634418c
parent 32757 79d34d4b9627
child 33661 ad7c7378a002
permissions -rw-r--r--
8139390: Very long classname in jimage causes SIGSEGV Summary: Correct issues with ImageNativeSubstrate and JImageReadTest Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     1
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     4
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32757
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    10
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    16
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    20
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    23
 * questions.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    24
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    25
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    26
#include <string.h>
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    27
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    28
#include "jni.h"
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    29
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    30
#include "endian.hpp"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    31
#include "imageDecompressor.hpp"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    32
#include "imageFile.hpp"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    33
#include "inttypes.hpp"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    34
#include "jimage.hpp"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    35
#include "osSupport.hpp"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    36
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    37
#include "jdk_internal_jimage_ImageNativeSubstrate.h"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    38
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    39
extern bool MemoryMapImage;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    40
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    41
/////////////////////////////////////////////////////////////////////////////
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    42
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    43
// Static function for primitive throw since libjimage is not linked with libjava
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    44
static void JNICALL ThrowByName(JNIEnv *env, const char *name, const char *msg)
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    45
{
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    46
    jclass cls = (env)->FindClass(name);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    47
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    48
    if (cls != 0) /* Otherwise an exception has already been thrown */
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    49
        (env)->ThrowNew(cls, msg);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    50
}
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
    51
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    52
// jdk.internal.jimage /////////////////////////////////////////////////////////
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    53
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    54
// Java entry to open an image file for sharing.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    55
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    56
static jlong JIMAGE_Open(JNIEnv *env, const char *nativePath, jboolean big_endian) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    57
    // Open image file for reading.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    58
    ImageFileReader* reader = ImageFileReader::open(nativePath, big_endian != JNI_FALSE);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    59
    // Return image ID as a jlong.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    60
    return ImageFileReader::readerToID(reader);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    61
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    62
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    63
// Java entry for closing a shared image file.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    64
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    65
static void JIMAGE_Close(JNIEnv *env, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    66
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    67
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    68
    // If valid reader the close.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    69
    if (reader != NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    70
        ImageFileReader::close(reader);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    71
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    72
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    73
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    74
// Java entry for accessing the base address of the image index.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    75
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    76
static jlong JIMAGE_GetIndexAddress(JNIEnv *env, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    77
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    78
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    79
    // If valid reader return index base address (as jlong) else zero.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    80
    return reader != NULL ? (jlong) reader->get_index_address() : 0L;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    81
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    82
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    83
// Java entry for accessing the base address of the image data.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    84
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    85
static jlong JIMAGE_GetDataAddress(JNIEnv *env, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    86
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    87
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    88
    // If valid reader return data base address (as jlong) else zero.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    89
    return MemoryMapImage && reader != NULL ? (jlong) reader->get_data_address() : 0L;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    90
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    91
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    92
// Java entry for reading an uncompressed resource from the image.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    93
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    94
static jboolean JIMAGE_Read(JNIEnv *env, jlong id, jlong offset,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    95
        unsigned char* uncompressedAddress, jlong uncompressed_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    96
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    97
    ImageFileReader* reader = ImageFileReader::idToReader(id);\
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    98
  // If not a valid reader the fail the read.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    99
    if (reader == NULL) return false;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   100
    // Get the file offset of resource data.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   101
    u8 file_offset = reader->get_index_size() + offset;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   102
    // Check validity of arguments.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   103
    if (offset < 0 ||
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   104
            uncompressed_size < 0 ||
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   105
            file_offset > reader->file_size() - uncompressed_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   106
        return false;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   107
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   108
    // Read file content into buffer.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   109
    return (jboolean) reader->read_at((u1*) uncompressedAddress, uncompressed_size,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   110
            file_offset);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   111
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   112
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   113
// Java entry for reading a compressed resource from the image.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   114
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   115
static jboolean JIMAGE_ReadCompressed(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   116
        jlong id, jlong offset,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   117
        unsigned char* compressedAddress, jlong compressed_size,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   118
        unsigned char* uncompressedAddress, jlong uncompressed_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   119
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   120
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   121
    // If not a valid reader the fail the read.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   122
    if (reader == NULL) return false;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   123
    // Get the file offset of resource data.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   124
    u8 file_offset = reader->get_index_size() + offset;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   125
    // Check validity of arguments.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   126
    if (offset < 0 ||
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   127
            compressed_size < 0 ||
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   128
            uncompressed_size < 0 ||
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   129
            file_offset > reader->file_size() - compressed_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   130
        return false;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   131
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   132
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   133
    // Read file content into buffer.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   134
    bool is_read = reader->read_at(compressedAddress, compressed_size,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   135
            file_offset);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   136
    // If successfully read then decompress.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   137
    if (is_read) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   138
        const ImageStrings strings = reader->get_strings();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   139
        ImageDecompressor::decompress_resource(compressedAddress, uncompressedAddress,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   140
                (u4) uncompressed_size, &strings);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   141
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   142
    return (jboolean) is_read;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   143
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   144
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   145
// Java entry for retrieving UTF-8 bytes from image string table.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   146
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   147
static const char* JIMAGE_GetStringBytes(JNIEnv *env, jlong id, jint offset) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   148
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   149
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   150
    // Fail if not valid reader.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   151
    if (reader == NULL) return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   152
    // Manage image string table.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   153
    ImageStrings strings = reader->get_strings();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   154
    // Retrieve string adrress from table.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   155
    const char* data = strings.get(offset);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   156
    return data;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   157
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   158
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   159
// Utility function to copy location information into a jlong array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   160
// WARNING: This function is experimental and temporary during JDK 9 development
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   161
// cycle. It will not be supported in the eventual JDK 9 release.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   162
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   163
static void image_expand_location(JNIEnv *env, jlong* rawAttributes, ImageLocation& location) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   164
    // Copy attributes from location.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   165
    for (int kind = ImageLocation::ATTRIBUTE_END + 1;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   166
            kind < ImageLocation::ATTRIBUTE_COUNT;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   167
            kind++) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   168
        rawAttributes[kind] = location.get_attribute(kind);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   169
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   170
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   171
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   172
// Java entry for retrieving location attributes for attribute offset.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   173
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   174
static jlong* JIMAGE_GetAttributes(JNIEnv *env, jlong* rawAttributes, jlong id, jint offset) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   175
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   176
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   177
    // Fail if not valid reader.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   178
    if (reader == NULL) return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   179
    // Retrieve first byte address of resource's location attribute stream.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   180
    u1* data = reader->get_location_offset_data(offset);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   181
    // Fail if not valid offset.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   182
    if (data == NULL) return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   183
    // Expand stream into array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   184
    ImageLocation location(data);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   185
    image_expand_location(env, rawAttributes, location);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   186
    return rawAttributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   187
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   188
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   189
// Java entry for retrieving location attributes count for attribute offset.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   190
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   191
static jsize JIMAGE_GetAttributesCount(JNIEnv *env) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   192
    return ImageLocation::ATTRIBUTE_COUNT;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   193
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   194
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   195
// Java entry for retrieving location attributes for named resource.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   196
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   197
static jlong* JIMAGE_FindAttributes(JNIEnv *env, jlong* rawAttributes, jbyte* rawBytes, jsize size, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   198
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   199
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   200
    // Fail if not valid reader.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   201
    if (reader == NULL) return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   202
    // Convert byte array to a cstring.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   203
    char* path = new char[size + 1];
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   204
    memcpy(path, rawBytes, size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   205
    path[size] = '\0';
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   206
    // Locate resource location data.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   207
    ImageLocation location;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   208
    bool found = reader->find_location(path, location);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   209
    delete path;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   210
    // Resource not found.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   211
    if (!found) return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   212
    // Expand stream into array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   213
    image_expand_location(env, rawAttributes, location);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   214
    return rawAttributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   215
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   216
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   217
// Java entry for retrieving all the attribute stream offsets from an image.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   218
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   219
static jint* JIMAGE_AttributeOffsets(JNIEnv *env, jint* rawOffsets, unsigned int length, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   220
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   221
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   222
    // Fail if not valid reader.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   223
    if (reader == NULL) return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   224
    // Determine endian for reader.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   225
    Endian* endian = reader->endian();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   226
    // Get base address of attribute stream offsets table.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   227
    u4* offsets_table = reader->offsets_table();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   228
    // Allocate int array result.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   229
    // Copy values to result (converting endian.)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   230
    for (u4 i = 0; i < length; i++) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   231
        rawOffsets[i] = endian->get(offsets_table[i]);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   232
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   233
    return rawOffsets;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   234
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   235
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   236
// Java entry for retrieving all the attribute stream offsets length from an image.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   237
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   238
static unsigned int JIMAGE_AttributeOffsetsLength(JNIEnv *env, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   239
    // Convert image ID to image reader structure.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   240
    ImageFileReader* reader = ImageFileReader::idToReader(id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   241
    // Fail if not valid reader.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   242
    if (reader == NULL) return 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   243
    // Get perfect hash table length.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   244
    u4 length = reader->table_length();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   245
    return (jint) length;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   246
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   247
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   248
JNIEXPORT jint JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   249
JNI_OnLoad(JavaVM *vm, void *reserved) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   250
    JNIEnv *env;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   251
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   252
    if (vm->GetEnv((void**) &env, JNI_VERSION_1_2) != JNI_OK) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   253
        return JNI_EVERSION; /* JNI version not supported */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   254
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   255
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   256
    return JNI_VERSION_1_2;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   257
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   258
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   259
JNIEXPORT jlong JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   260
Java_jdk_internal_jimage_ImageNativeSubstrate_openImage(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   261
        jclass cls, jstring path, jboolean big_endian) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   262
    const char *nativePath;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   263
    jlong ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   264
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   265
    nativePath = env->GetStringUTFChars(path, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   266
    ret = JIMAGE_Open(env, nativePath, big_endian);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   267
    env->ReleaseStringUTFChars(path, nativePath);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   268
    return ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   269
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   270
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   271
JNIEXPORT void JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   272
Java_jdk_internal_jimage_ImageNativeSubstrate_closeImage(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   273
        jclass cls, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   274
    JIMAGE_Close(env, id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   275
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   276
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   277
JNIEXPORT jlong JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   278
Java_jdk_internal_jimage_ImageNativeSubstrate_getIndexAddress(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   279
        jclass cls, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   280
    return JIMAGE_GetIndexAddress(env, id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   281
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   282
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   283
JNIEXPORT jlong JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   284
Java_jdk_internal_jimage_ImageNativeSubstrate_getDataAddress(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   285
        jclass cls, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   286
    return JIMAGE_GetDataAddress(env, id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   287
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   288
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   289
JNIEXPORT jboolean JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   290
Java_jdk_internal_jimage_ImageNativeSubstrate_read(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   291
        jclass cls, jlong id, jlong offset,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   292
        jobject uncompressedBuffer, jlong uncompressed_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   293
    unsigned char* uncompressedAddress;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   294
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   295
    uncompressedAddress = (unsigned char*) env->GetDirectBufferAddress(uncompressedBuffer);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   296
    if (uncompressedAddress == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   297
        return JNI_FALSE;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   298
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   299
    return JIMAGE_Read(env, id, offset, uncompressedAddress, uncompressed_size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   300
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   301
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   302
JNIEXPORT jboolean JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   303
Java_jdk_internal_jimage_ImageNativeSubstrate_readCompressed(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   304
        jclass cls, jlong id, jlong offset,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   305
        jobject compressedBuffer, jlong compressed_size,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   306
        jobject uncompressedBuffer, jlong uncompressed_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   307
    // Get address of read direct buffer.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   308
    unsigned char* compressedAddress;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   309
    unsigned char* uncompressedAddress;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   310
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   311
    compressedAddress = (unsigned char*) env->GetDirectBufferAddress(compressedBuffer);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   312
    // Get address of decompression direct buffer.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   313
    uncompressedAddress = (unsigned char*) env->GetDirectBufferAddress(uncompressedBuffer);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   314
    if (compressedAddress == NULL || uncompressedAddress == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   315
        return JNI_FALSE;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   316
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   317
    return JIMAGE_ReadCompressed(env, id, offset, compressedAddress, compressed_size,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   318
            uncompressedAddress, uncompressed_size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   319
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   320
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   321
JNIEXPORT jbyteArray JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   322
Java_jdk_internal_jimage_ImageNativeSubstrate_getStringBytes(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   323
        jclass cls, jlong id, jint offset) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   324
    const char* data;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   325
    size_t size;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   326
    jbyteArray byteArray;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   327
    jbyte* rawBytes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   328
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   329
    data = JIMAGE_GetStringBytes(env, id, offset);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   330
    // Determine String length.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   331
    size = strlen(data);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   332
    // Allocate byte array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   333
    byteArray = env->NewByteArray((jsize) size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   334
    if (byteArray == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   335
        return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   336
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   337
    // Get array base address.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   338
    rawBytes = env->GetByteArrayElements(byteArray, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   339
    // Copy bytes from image string table.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   340
    memcpy(rawBytes, data, size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   341
    // Release byte array base address.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   342
    env->ReleaseByteArrayElements(byteArray, rawBytes, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   343
    return byteArray;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   344
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   345
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   346
JNIEXPORT jlongArray JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   347
Java_jdk_internal_jimage_ImageNativeSubstrate_getAttributes(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   348
        jclass cls, jlong id, jint offset) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   349
    // Allocate a jlong large enough for all location attributes.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   350
    jlongArray attributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   351
    jlong* rawAttributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   352
    jlong* ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   353
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   354
    attributes = env->NewLongArray(JIMAGE_GetAttributesCount(env));
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   355
    if (attributes == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   356
        return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   357
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   358
    // Get base address for jlong array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   359
    rawAttributes = env->GetLongArrayElements(attributes, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   360
    ret = JIMAGE_GetAttributes(env, rawAttributes, id, offset);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   361
    // Release jlong array base address.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   362
    env->ReleaseLongArrayElements(attributes, rawAttributes, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   363
    return ret == NULL ? NULL : attributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   364
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   365
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   366
JNIEXPORT jlongArray JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   367
Java_jdk_internal_jimage_ImageNativeSubstrate_findAttributes(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   368
        jclass cls, jlong id, jbyteArray utf8) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   369
    // Allocate a jlong large enough for all location attributes.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   370
    jsize count;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   371
    jlongArray attributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   372
    jlong* rawAttributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   373
    jsize size;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   374
    jbyte* rawBytes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   375
    jlong* ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   376
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   377
    count = JIMAGE_GetAttributesCount(env);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   378
    attributes = env->NewLongArray(JIMAGE_GetAttributesCount(env));
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   379
    if (attributes == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   380
        return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   381
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   382
    // Get base address for jlong array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   383
    rawAttributes = env->GetLongArrayElements(attributes, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   384
    size = env->GetArrayLength(utf8);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   385
    rawBytes = env->GetByteArrayElements(utf8, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   386
    ret = JIMAGE_FindAttributes(env, rawAttributes, rawBytes, size, id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   387
    env->ReleaseByteArrayElements(utf8, rawBytes, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   388
    // Release jlong array base address.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   389
    env->ReleaseLongArrayElements(attributes, rawAttributes, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   390
    return ret == NULL ? NULL : attributes;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   391
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   392
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   393
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   394
JNIEXPORT jintArray JNICALL
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   395
Java_jdk_internal_jimage_ImageNativeSubstrate_attributeOffsets(JNIEnv *env,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   396
        jclass cls, jlong id) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   397
    unsigned int length;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   398
    jintArray offsets;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   399
    jint* rawOffsets;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   400
    jint* ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   401
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   402
    length = JIMAGE_AttributeOffsetsLength(env, id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   403
    offsets = env->NewIntArray(length);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   404
    if (offsets == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   405
        return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   406
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   407
    // Get base address of result.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   408
    rawOffsets = env->GetIntArrayElements(offsets, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   409
    ret = JIMAGE_AttributeOffsets(env, rawOffsets, length, id);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   410
    if (length == 0) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   411
        return NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   412
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   413
    // Release result base address.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   414
    env->ReleaseIntArrayElements(offsets, rawOffsets, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   415
    return ret == NULL ? NULL : offsets;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   416
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   417
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   418
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   419
 * Class:     jdk_internal_jimage_ImageNativeSubstrate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   420
 * Method:    JIMAGE_open
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   421
 * Signature: (Ljava/lang/String;)J
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   422
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   423
JNIEXPORT jlong JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Open
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   424
(JNIEnv *env, jclass, jstring path) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   425
    const char *nativePath = env->GetStringUTFChars(path, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   426
    if (nativePath == NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   427
        return 0; // Exception already thrown
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   428
    jint error;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   429
    jlong ret = (jlong) JIMAGE_Open(nativePath, &error);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   430
    env->ReleaseStringUTFChars(path, nativePath);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   431
    return ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   432
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   433
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   434
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   435
 * Class:     jdk_internal_jimage_ImageNativeSubstrate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   436
 * Method:    JIMAGE_Close
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   437
 * Signature: (J)J
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   438
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   439
JNIEXPORT void JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Close
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   440
(JNIEnv *env, jclass, jlong jimageHandle) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   441
    JIMAGE_Close((JImageFile*) jimageHandle);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   442
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   443
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   444
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   445
 * Class:     jdk_internal_jimage_ImageNativeSubstrate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   446
 * Method:    JIMAGE_FindResource
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   447
 * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;[J)J
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   448
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   449
JNIEXPORT jlong JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1FindResource
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   450
(JNIEnv *env, jclass, jlong jimageHandle, jstring moduleName,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   451
        jstring version, jstring path, jlongArray output_size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   452
    const char *native_module = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   453
    const char *native_version = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   454
    const char *native_path = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   455
    jlong * native_array = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   456
    jlong size = 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   457
    jlong ret = 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   458
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   459
    if (moduleName == NULL) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   460
        ThrowByName(env, "java/lang/NullPointerException", "moduleName");
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   461
        return 0;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   462
    }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   463
    if (version == NULL) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   464
        ThrowByName(env, "java/lang/NullPointerException", "version");
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   465
        return 0;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   466
    }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   467
    if (path == NULL) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   468
        ThrowByName(env, "java/lang/NullPointerException", "path");
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   469
        return 0;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   470
    }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   471
    if (output_size == NULL) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   472
        ThrowByName(env, "java/lang/NullPointerException", "size");
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   473
        return 0;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   474
    }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   475
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   476
    do {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   477
        native_module = env->GetStringUTFChars(moduleName, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   478
        if (native_module == NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   479
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   480
        native_version = env->GetStringUTFChars(version, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   481
        if (native_version == NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   482
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   483
        native_path = env->GetStringUTFChars(path, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   484
        if (native_path == NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   485
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   486
        if (env->GetArrayLength(output_size) < 1)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   487
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   488
        // Get base address for jlong array.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   489
        native_array = env->GetLongArrayElements(output_size, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   490
        if (native_array == NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   491
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   492
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   493
        ret = (jlong) JIMAGE_FindResource((JImageFile *) jimageHandle,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   494
                native_module, native_version, native_path, &size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   495
        if (ret != 0)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   496
            *native_array = size;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   497
    } while (0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   498
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   499
    if (native_array != NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   500
        env->ReleaseLongArrayElements(output_size, native_array, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   501
    if (native_path != NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   502
        env->ReleaseStringUTFChars(path, native_path);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   503
    if (native_version != NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   504
        env->ReleaseStringUTFChars(path, native_version);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   505
    if (native_module != NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   506
        env->ReleaseStringUTFChars(path, native_module);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   507
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   508
    return ret;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   509
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   510
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   511
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   512
 * Class:     jdk_internal_jimage_ImageNativeSubstrate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   513
 * Method:    JIMAGE_GetResource
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   514
 * Signature: (JJ[BJ)J
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   515
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   516
JNIEXPORT jlong JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1GetResource
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   517
(JNIEnv *env, jclass, jlong jimageHandle, jlong jlocationHandle, jbyteArray buffer, jlong size) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   518
    jbyte * native_buffer = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   519
    jlong actual_size = 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   520
    do {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   521
        if (env->GetArrayLength(buffer) < size)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   522
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   523
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   524
        native_buffer = env->GetByteArrayElements(buffer, NULL);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   525
        if (native_buffer == NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   526
            break;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   527
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   528
        actual_size = JIMAGE_GetResource((JImageFile*) jimageHandle,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   529
                (JImageLocationRef) jlocationHandle,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   530
                (char *) native_buffer, size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   531
    } while (0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   532
    // Release byte array
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   533
    if (native_buffer != NULL)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   534
        env->ReleaseByteArrayElements(buffer, native_buffer, 0);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   535
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   536
    return actual_size;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   537
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   538
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   539
// Structure passed from iterator to a visitor to accumulate the results
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   540
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   541
struct VisitorData {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   542
    JNIEnv *env;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   543
    int size; // current number of strings
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   544
    int max; // Maximum number of strings
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   545
    jobjectArray array; // String array to store the strings
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   546
};
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   547
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   548
// Visitor to accumulate fully qualified resource names
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   549
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   550
static bool resourceVisitor(JImageFile* image,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   551
        const char* module, const char* version, const char* package,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   552
        const char* name, const char* extension, void* arg) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   553
    struct VisitorData *vdata = (struct VisitorData *) arg;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   554
    JNIEnv* env = vdata->env;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   555
    if (vdata->size < vdata->max) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   556
        // Store if there is room in the array
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   557
        // Concatenate to get full path
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   558
        char fullpath[IMAGE_MAX_PATH];
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   559
        size_t moduleLen = strlen(module);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   560
        size_t packageLen = strlen(package);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   561
        size_t nameLen = strlen(name);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   562
        size_t extLen = strlen(extension);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   563
        size_t index;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   564
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   565
        if (1 + moduleLen + 1 + packageLen + 1 + nameLen + 1 + extLen + 1 > IMAGE_MAX_PATH) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   566
            ThrowByName(env, "java/lang/InternalError", "concatenated name too long");
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   567
            return true;
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   568
        }
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   569
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   570
        index = 0;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   571
        if (moduleLen > 0) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   572
            fullpath[index++] = '/';
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   573
            memcpy(&fullpath[index], module, moduleLen);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   574
            index += moduleLen;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   575
            fullpath[index++] = '/';
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   576
        }
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   577
        if (packageLen > 0) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   578
            memcpy(&fullpath[index], package, packageLen);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   579
            index += packageLen;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   580
            fullpath[index++] = '/';
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   581
        }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   582
        memcpy(&fullpath[index], name, nameLen);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   583
        index += nameLen;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   584
        if (extLen > 0) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   585
            fullpath[index++] = '.';
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   586
            memcpy(&fullpath[index], extension, extLen);
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   587
            index += extLen;
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   588
        }
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   589
        fullpath[index++] = '\0';
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   590
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   591
        jobject str = env->NewStringUTF(fullpath);
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   592
        if (env->ExceptionCheck()) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   593
            return true;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   594
        }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   595
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   596
        env->SetObjectArrayElement(vdata->array, vdata->size, str);
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   597
        if (env->ExceptionCheck()) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   598
            return true;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   599
        }
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   600
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   601
    vdata->size++; // always count so the total size is returned
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   602
    return true;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   603
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   604
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   605
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   606
 * Class:     jdk_internal_jimage_ImageNativeSubstrate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   607
 * Method:    JIMAGE_Resources
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   608
 * Signature: (J)V
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   609
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   610
JNIEXPORT jint JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Resources
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   611
(JNIEnv *env, jclass, jlong jimageHandle,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   612
        jobjectArray outputNames) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   613
    struct VisitorData vdata;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   614
    vdata.env = env;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   615
    vdata.max = 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   616
    vdata.size = 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   617
    vdata.array = outputNames;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   618
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   619
    vdata.max = (outputNames != NULL) ? env->GetArrayLength(outputNames) : 0;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   620
    JIMAGE_ResourceIterator((JImageFile*) jimageHandle, &resourceVisitor, &vdata);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   621
    return vdata.size;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   622
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   623
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   624
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   625
 * Class:     jdk_internal_jimage_ImageNativeSubstrate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   626
 * Method:    JIMAGE_PackageToModule
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   627
 * Signature: (JLjava/lang/String;)Ljava/lang/String;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   628
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   629
JNIEXPORT jstring JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1PackageToModule
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   630
(JNIEnv *env, jclass, jlong jimageHandle, jstring package_name) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   631
    const char *native_package = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   632
    const char *native_module = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   633
    jstring module = NULL;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   634
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   635
    native_package = env->GetStringUTFChars(package_name, NULL);
33492
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   636
    if (env->ExceptionCheck()) {
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   637
        return NULL;
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   638
    }
051df634418c 8139390: Very long classname in jimage causes SIGSEGV
rriggs
parents: 32757
diff changeset
   639
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   640
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   641
    native_module = JIMAGE_PackageToModule((JImageFile*) jimageHandle, native_package);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   642
    if (native_module != NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   643
        module = env->NewStringUTF(native_module);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   644
    }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   645
    env->ReleaseStringUTFChars(package_name, native_package);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   646
    return module;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   647
}
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   648
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   649
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   650
    ImageDecompressor::image_decompressor_close();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   651
}