jdk/src/jdk.pack200/share/native/libunpack/jni.cpp
author bobv
Mon, 19 Oct 2015 13:41:09 -0400
changeset 33653 c1ee09fe3274
parent 29591 51244d1ddffc
permissions -rw-r--r--
8136556: Add the ability to perform static builds of MacOSX x64 binaries Reviewed-by: ihse, bdelsart, gadams, lfoltan, rriggs, hseigel, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 29591
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <com_sun_java_util_jar_pack_NativeUnpack.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "defines.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "bytes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "coding.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "bands.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "constants.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "zip.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "unpack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static jfieldID  unpackerPtrFID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static jmethodID currentInstMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static jmethodID readInputMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static jclass    NIclazz;
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
    53
static jmethodID getUnpackerPtrMID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static char* dbg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#define THROW_IOE(x) JNU_ThrowIOException(env,x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    59
#define CHECK_EXCEPTION_RETURN_VOID_THROW_IOE(CERVTI_exception, CERVTI_message) \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    60
    do { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    61
        if ((env)->ExceptionOccurred()) { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    62
            THROW_IOE(CERVTI_message); \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    63
            return; \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    64
        } \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    65
        if ((CERVTI_exception) == NULL) { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    66
                THROW_IOE(CERVTI_message); \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    67
                return; \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    68
        } \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    69
    } while (JNI_FALSE)
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    70
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    71
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    72
#define CHECK_EXCEPTION_RETURN_VALUE(CERL_exception, CERL_return_value) \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    73
    do { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    74
        if ((env)->ExceptionOccurred()) { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    75
            return CERL_return_value; \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    76
        } \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    77
        if ((CERL_exception) == NULL) { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    78
            return CERL_return_value; \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    79
        } \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    80
    } while (JNI_FALSE)
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    81
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    82
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    83
// If these useful macros aren't defined in jni_util.h then define them here
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    84
#ifndef CHECK_NULL_RETURN
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    85
#define CHECK_NULL_RETURN(x, y) \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    86
    do { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    87
        if ((x) == NULL) return (y); \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    88
    } while (JNI_FALSE)
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    89
#endif
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    90
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    91
#ifndef CHECK_EXCEPTION_RETURN
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    92
#define CHECK_EXCEPTION_RETURN(env, y) \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    93
    do { \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    94
        if ((*env)->ExceptionCheck(env)) return (y); \
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    95
    } while (JNI_FALSE)
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    96
#endif
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
    97
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 29591
diff changeset
    98
/*
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 29591
diff changeset
    99
 * Declare library specific JNI_Onload entry if static build
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 29591
diff changeset
   100
 */
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 29591
diff changeset
   101
DEF_STATIC_JNI_OnLoad
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 29591
diff changeset
   102
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
static jlong read_input_via_jni(unpacker* self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                void* buf, jlong minlen, jlong maxlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   107
  unpacker* uPtr;
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   108
  jlong p = env->CallLongMethod(pObj, getUnpackerPtrMID);
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   109
  uPtr = (unpacker*)jlong2ptr(p);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  if (uPtr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    if (noCreate)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    uPtr = new unpacker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    if (uPtr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      THROW_IOE(ERROR_ENOMEM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    uPtr->init(read_input_via_jni);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   120
    env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  uPtr->jnienv = env;  // keep refreshing this in case of MT access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  return uPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
// This is the harder trick:  Pull the current state out of mid-air.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
static unpacker* get_unpacker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  //fprintf(stderr, "get_unpacker()\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  JavaVM* vm = null;
12680
289f842c0175 7166955: (pack200) JNI_GetCreatedJavaVMs needs additional checking
ksrini
parents: 5506
diff changeset
   130
  jsize nVM = 0;
289f842c0175 7166955: (pack200) JNI_GetCreatedJavaVMs needs additional checking
ksrini
parents: 5506
diff changeset
   131
  jint retval = JNI_GetCreatedJavaVMs(&vm, 1, &nVM);
289f842c0175 7166955: (pack200) JNI_GetCreatedJavaVMs needs additional checking
ksrini
parents: 5506
diff changeset
   132
  // other VM implements may differ, thus for correctness, we need these checks
289f842c0175 7166955: (pack200) JNI_GetCreatedJavaVMs needs additional checking
ksrini
parents: 5506
diff changeset
   133
  if (retval != JNI_OK || nVM != 1)
289f842c0175 7166955: (pack200) JNI_GetCreatedJavaVMs needs additional checking
ksrini
parents: 5506
diff changeset
   134
    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  void* envRaw = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  vm->GetEnv(&envRaw, JNI_VERSION_1_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  JNIEnv* env = (JNIEnv*) envRaw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  //fprintf(stderr, "get_unpacker() env=%p\n", env);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   139
  CHECK_NULL_RETURN(env, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  jobject pObj = env->CallStaticObjectMethod(NIclazz, currentInstMID);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   141
  // We should check upon the known non-null variable because here we want to check
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   142
  // only for pending exceptions. If pObj is null we'll deal with it later.
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   143
  CHECK_EXCEPTION_RETURN_VALUE(env, NULL);
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   144
  //fprintf(stderr, "get_unpacker0() pObj=%p\n", pObj);
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   145
  if (pObj != null) {
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   146
    // Got pObj and env; now do it the easy way.
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   147
    return get_unpacker(env, pObj);
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   148
  }
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   149
  // this should really not happen, if it does something is seriously
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   150
  // wrong throw an exception
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   151
  THROW_IOE(ERROR_INTERNAL);
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   152
  return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
static void free_unpacker(JNIEnv *env, jobject pObj, unpacker* uPtr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  if (uPtr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    //fprintf(stderr, "free_unpacker(%p) uPtr=%p\n", pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    env->DeleteGlobalRef((jobject) uPtr->jniobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    uPtr->jniobj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    uPtr->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    delete uPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    env->SetLongField(pObj, unpackerPtrFID, (jlong)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
unpacker* unpacker::current() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  return get_unpacker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
// Callback for fetching data, Java style.  Calls NativeUnpack.readInputFn().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
static jlong read_input_via_jni(unpacker* self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                void* buf, jlong minlen, jlong maxlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  JNIEnv* env = (JNIEnv*) self->jnienv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  jobject pbuf = env->NewDirectByteBuffer(buf, maxlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  return env->CallLongMethod((jobject) self->jniobj, readInputMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                             pbuf, minlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
Java_com_sun_java_util_jar_pack_NativeUnpack_initIDs(JNIEnv *env, jclass clazz) {
16074
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   181
#ifndef PRODUCT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  dbg = getenv("DEBUG_ATTACH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  while( dbg != null) { sleep(10); }
16074
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   184
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  NIclazz = (jclass) env->NewGlobalRef(clazz);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   186
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  unpackerPtrFID = env->GetFieldID(clazz, "unpackerPtr", "J");
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   188
  CHECK_EXCEPTION_RETURN_VOID_THROW_IOE(unpackerPtrFID, ERROR_INIT);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   189
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  currentInstMID = env->GetStaticMethodID(clazz, "currentInstance",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                          "()Ljava/lang/Object;");
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   192
  CHECK_EXCEPTION_RETURN_VOID_THROW_IOE(currentInstMID, ERROR_INIT);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   193
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  readInputMID = env->GetMethodID(clazz, "readInputFn",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                  "(Ljava/nio/ByteBuffer;J)J");
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   196
  CHECK_EXCEPTION_RETURN_VOID_THROW_IOE(readInputMID, ERROR_INIT);
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   197
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   198
  getUnpackerPtrMID = env->GetMethodID(clazz, "getUnpackerPtr", "()J");
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   199
  CHECK_EXCEPTION_RETURN_VOID_THROW_IOE(getUnpackerPtrMID, ERROR_INIT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
Java_com_sun_java_util_jar_pack_NativeUnpack_start(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                   jobject pBuf, jlong offset) {
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   205
  // try to get the unpacker pointer the hard way first, we do this to ensure
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   206
  // valid object pointers and env is intact, if not now is good time to bail.
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   207
  unpacker* uPtr = get_unpacker();
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   208
  //fprintf(stderr, "start(%p) uPtr=%p initializing\n", pObj, uPtr);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   209
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  // redirect our io to the default log file or whatever.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  uPtr->redirect_stdio();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  void*  buf    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  size_t buflen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  if (pBuf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    buf    = env->GetDirectBufferAddress(pBuf);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   217
    buflen = (size_t)env->GetDirectBufferCapacity(pBuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    if (buflen == 0)  buf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    if ((size_t)offset >= buflen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      { buf = null; buflen = 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      { buf = (char*)buf + (size_t)offset; buflen -= (size_t)offset; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  }
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   225
  // before we start off we make sure there is no other error by the time we
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   226
  // get here
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   227
  if (uPtr->aborting()) {
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   228
    THROW_IOE(uPtr->get_abort_message());
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   229
    return 0;
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16074
diff changeset
   230
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  uPtr->start(buf, buflen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  if (uPtr->aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    THROW_IOE(uPtr->get_abort_message());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  return ((jlong)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
          uPtr->get_segments_remaining() << 32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    + uPtr->get_files_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
Java_com_sun_java_util_jar_pack_NativeUnpack_getNextFile(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                         jobjectArray pParts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  unpacker* uPtr = get_unpacker(env, pObj);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   247
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  unpacker::file* filep = uPtr->get_next_file();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  if (uPtr->aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    THROW_IOE(uPtr->get_abort_message());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   255
  CHECK_NULL_RETURN(filep, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  assert(filep == &uPtr->cur_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  int pidx = 0, iidx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  jintArray pIntParts = (jintArray) env->GetObjectArrayElement(pParts, pidx++);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   260
  CHECK_EXCEPTION_RETURN_VALUE(pIntParts, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  jint*     intParts  = env->GetIntArrayElements(pIntParts, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  intParts[iidx++] = (jint)( (julong)filep->size >> 32 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
  intParts[iidx++] = (jint)( (julong)filep->size >>  0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  intParts[iidx++] = filep->modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
  intParts[iidx++] = filep->deflate_hint() ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  env->ReleaseIntArrayElements(pIntParts, intParts, JNI_COMMIT);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   267
  jstring filename = env->NewStringUTF(filep->name);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   268
  CHECK_EXCEPTION_RETURN_VALUE(filename, false);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   269
  env->SetObjectArrayElement(pParts, pidx++, filename);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   270
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
  jobject pDataBuf = null;
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   272
  if (filep->data[0].len > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    pDataBuf = env->NewDirectByteBuffer(filep->data[0].ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                        filep->data[0].len);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   275
    CHECK_EXCEPTION_RETURN_VALUE(pDataBuf, false);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   276
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  env->SetObjectArrayElement(pParts, pidx++, pDataBuf);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   278
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  pDataBuf = null;
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   280
  if (filep->data[1].len > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    pDataBuf = env->NewDirectByteBuffer(filep->data[1].ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                        filep->data[1].len);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   283
    CHECK_EXCEPTION_RETURN_VALUE(pDataBuf, false);
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   284
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
  env->SetObjectArrayElement(pParts, pidx++, pDataBuf);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   286
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
Java_com_sun_java_util_jar_pack_NativeUnpack_getUnusedInput(JNIEnv *env, jobject pObj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  unpacker* uPtr = get_unpacker(env, pObj);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   295
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
  unpacker::file* filep = &uPtr->cur_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
  if (uPtr->aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    THROW_IOE(uPtr->get_abort_message());
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   300
    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  // We have fetched all the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  // Now swallow up any remaining input.
16074
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   305
  if (uPtr->input_remaining() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    return null;
16074
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   307
  } else {
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   308
    bytes remaining_bytes;
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   309
    remaining_bytes.malloc(uPtr->input_remaining());
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   310
    remaining_bytes.copyFrom(uPtr->input_scan(), uPtr->input_remaining());
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   311
    return env->NewDirectByteBuffer(remaining_bytes.ptr, remaining_bytes.len);
97593512057a 7186945: Unpack200 improvement
ksrini
parents: 12680
diff changeset
   312
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
Java_com_sun_java_util_jar_pack_NativeUnpack_finish(JNIEnv *env, jobject pObj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  unpacker* uPtr = get_unpacker(env, pObj, false);
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   318
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
  size_t consumed = uPtr->input_consumed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
  free_unpacker(env, pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
  return consumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
Java_com_sun_java_util_jar_pack_NativeUnpack_setOption(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                       jstring pProp, jstring pValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
  unpacker*   uPtr  = get_unpacker(env, pObj);
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   328
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  const char* prop  = env->GetStringUTFChars(pProp, JNI_FALSE);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   330
  CHECK_EXCEPTION_RETURN_VALUE(prop, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  const char* value = env->GetStringUTFChars(pValue, JNI_FALSE);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   332
  CHECK_EXCEPTION_RETURN_VALUE(value, false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  jboolean   retval = uPtr->set_option(prop, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
  env->ReleaseStringUTFChars(pProp,  prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
  env->ReleaseStringUTFChars(pValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
Java_com_sun_java_util_jar_pack_NativeUnpack_getOption(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                       jstring pProp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  unpacker*   uPtr  = get_unpacker(env, pObj);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   344
  CHECK_EXCEPTION_RETURN_VALUE(uPtr, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
  const char* prop  = env->GetStringUTFChars(pProp, JNI_FALSE);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   346
  CHECK_EXCEPTION_RETURN_VALUE(prop, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
  const char* value = uPtr->get_option(prop);
25527
9df990320e71 8029177: [Parfait] warnings from b117 for jdk.src.share.native.com.sun.java.util.jar: JNI exception pending
kizune
parents: 16076
diff changeset
   348
  CHECK_EXCEPTION_RETURN_VALUE(value, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
  env->ReleaseStringUTFChars(pProp, prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
  return env->NewStringUTF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}