jdk/src/java.base/share/native/libjimage/jimage.hpp
author jlaskey
Sun, 14 Feb 2016 17:42:16 -0400
changeset 35784 ddeed53a1c5a
parent 32757 79d34d4b9627
child 36511 9d0388c6b336
permissions -rw-r--r--
8149776: BSD license for jimage code Reviewed-by: alanb
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
/*
35784
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     2
 * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     3
 *
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     5
 * modification, are permitted provided that the following conditions
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     6
 * are met:
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
     7
 *
35784
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    10
 *
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    14
 *
35784
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    17
 *     from this software without specific prior written permission.
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    18
 *
35784
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ddeed53a1c5a 8149776: BSD license for jimage code
jlaskey
parents: 32757
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    30
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    31
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    32
#include "jni.h"
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    33
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    34
// Opaque reference to a JImage file.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    35
class JImageFile;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    36
// Opaque reference to an image file resource location.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    37
typedef jlong JImageLocationRef;
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
// Max path length limit independent of platform.  Windows max path is 1024,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    40
// other platforms use 4096.  The JCK fails several tests when 1024 is used.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    41
#define JIMAGE_MAX_PATH 4096
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    42
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    43
// JImage Error Codes
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    44
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    45
// The image file is not prefixed with 0xCAFEDADA
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    46
#define JIMAGE_BAD_MAGIC (-1)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    47
// The image file does not have a compatible (translatable) version
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    48
#define JIMAGE_BAD_VERSION (-2)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    49
// The image file content is malformed
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    50
#define JIMAGE_CORRUPTED (-3)
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    51
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    52
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    53
 * JImageOpen - Given the supplied full path file name, open an image file. This
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    54
 * function will also initialize tables and retrieve meta-data necessary to
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    55
 * satisfy other functions in the API. If the image file has been previously
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    56
 * open, a new open request will share memory and resources used by the previous
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    57
 * open. A call to JImageOpen should be balanced by a call to JImageClose, to
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    58
 * release memory and resources used. If the image file is not found or cannot
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    59
 * be open, then NULL is returned and error will contain a reason for the
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    60
 * failure; a positive value for a system error number, negative for a jimage
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    61
 * specific error (see JImage Error Codes.)
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
 *  Ex.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    64
 *   jint error;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    65
 *   JImageFile* jimage = (*JImageOpen)(JAVA_HOME "lib/modules/bootmodules.jimage", &error);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    66
 *   if (image == NULL) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    67
 *     tty->print_cr("JImage failed to open: %d", error);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    68
 *     ...
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    69
 *   }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    70
 *   ...
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
extern "C" JImageFile* JIMAGE_Open(const char *name, jint* error);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    74
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    75
typedef JImageFile* (*JImageOpen_t)(const char *name, jint* error);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    76
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    77
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    78
 * JImageClose - Given the supplied open image file (see JImageOpen), release
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    79
 * memory and resources used by the open file and close the file. If the image
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    80
 * file is shared by other uses, release and close is deferred until the last use
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    81
 * is also closed.
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
 * Ex.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    84
 *  (*JImageClose)(image);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    85
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    86
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    87
extern "C" void JIMAGE_Close(JImageFile* jimage);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    88
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    89
typedef void (*JImageClose_t)(JImageFile* jimage);
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
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    93
 * JImagePackageToModule - Given an open image file (see JImageOpen) and the name
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    94
 * of a package, return the name of module where the package resides. If the
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    95
 * package does not exist in the image file, the function returns NULL.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    96
 * The resulting string does/should not have to be released. All strings are
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    97
 * utf-8, zero byte terminated.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    98
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
    99
 * Ex.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   100
 *  const char* package = (*JImagePackageToModule)(image, "java/lang");
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   101
 *  tty->print_cr(package);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   102
 *  —> java.base
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   103
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   104
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   105
extern "C" const char * JIMAGE_PackageToModule(JImageFile* jimage, const char* package_name);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   106
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   107
typedef const char* (*JImagePackageToModule_t)(JImageFile* jimage, const char* package_name);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   108
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   109
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   110
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   111
 * JImageFindResource - Given an open image file (see JImageOpen), a module
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   112
 * name, a version string and the name of a class/resource, return location
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   113
 * information describing the resource and its size. If no resource is found, the
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   114
 * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   115
 * The version number should be "9.0" and is not used in locating the resource.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   116
 * The resulting location does/should not have to be released.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   117
 * All strings are utf-8, zero byte terminated.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   118
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   119
 *  Ex.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   120
 *   jlong size;
32757
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
   121
 *   JImageLocationRef location = (*JImageFindResource)(image,
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
   122
 *                                "java.base", "9.0", "java/lang/String.class", &size);
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   123
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   124
extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* jimage,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   125
        const char* module_name, const char* version, const char* name,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   126
        jlong* size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   127
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   128
typedef JImageLocationRef(*JImageFindResource_t)(JImageFile* jimage,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   129
        const char* module_name, const char* version, const char* name,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   130
        jlong* size);
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
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   134
 * JImageGetResource - Given an open image file (see JImageOpen), a resource’s
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   135
 * location information (see JImageFindResource), a buffer of appropriate
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   136
 * size and the size, retrieve the bytes associated with the
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   137
 * resource. If the size is less than the resource size then the read is truncated.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   138
 * If the size is greater than the resource size then the remainder of the buffer
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   139
 * is zero filled.  The function will return the actual size of the resource.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   140
 *
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   141
 * Ex.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   142
 *  jlong size;
32757
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
   143
 *  JImageLocationRef location = (*JImageFindResource)(image,
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
   144
 *                               "java.base", "9.0", "java/lang/String.class", &size);
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   145
 *  char* buffer = new char[size];
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   146
 *  (*JImageGetResource)(image, location, buffer, size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   147
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   148
extern "C" jlong JIMAGE_GetResource(JImageFile* jimage, JImageLocationRef location,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   149
        char* buffer, jlong size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   150
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   151
typedef jlong(*JImageGetResource_t)(JImageFile* jimage, JImageLocationRef location,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   152
        char* buffer, jlong size);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   153
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   154
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   155
/*
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   156
 * JImageResourceIterator - Given an open image file (see JImageOpen), a visitor
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   157
 * function and a visitor argument, iterator through each of the image's resources.
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   158
 * The visitor function is called with the image file, the module name, the
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   159
 * package name, the base name, the extension and the visitor argument. The return
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   160
 * value of the visitor function should be true, unless an early iteration exit is
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   161
 * required. All strings are utf-8, zero byte terminated.file.
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
 * Ex.
32757
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
   164
 *   bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version,
79d34d4b9627 8135197: libjimage code needs translation from hotspot-ish to jdk-ish
jlaskey
parents: 32641
diff changeset
   165
 *                  const char* package, const char* name, const char* extension, void* arg) {
32641
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   166
 *     if (strcmp(extension, “class”) == 0) {
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   167
 *       char path[JIMAGE_MAX_PATH];
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   168
 *       Thread* THREAD = Thread::current();
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   169
 *       jio_snprintf(path, JIMAGE_MAX_PATH - 1, "/%s/%s", package, name);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   170
 *       ClassLoader::compile_the_world_in(path, (Handle)arg, THREAD);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   171
 *       return !HAS_PENDING_EXCEPTION;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   172
 *     }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   173
 *     return true;
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   174
 *   }
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   175
 *   (*JImageResourceIterator)(image, ctw_visitor, loader);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   176
 */
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   177
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   178
typedef bool (*JImageResourceVisitor_t)(JImageFile* jimage,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   179
        const char* module_name, const char* version, const char* package,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   180
        const char* name, const char* extension, void* arg);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   181
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   182
extern "C" void JIMAGE_ResourceIterator(JImageFile* jimage,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   183
        JImageResourceVisitor_t visitor, void *arg);
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   184
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   185
typedef void (*JImageResourceIterator_t)(JImageFile* jimage,
ac2c73b45253 8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff changeset
   186
        JImageResourceVisitor_t visitor, void* arg);