< prev index next >

src/jdk.pack200/share/native/libunpack/jni.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  77         if ((CERL_exception) == NULL) { \
  78             return CERL_return_value; \
  79         } \
  80     } while (JNI_FALSE)
  81 
  82 
  83 // If these useful macros aren't defined in jni_util.h then define them here
  84 #ifndef CHECK_NULL_RETURN
  85 #define CHECK_NULL_RETURN(x, y) \
  86     do { \
  87         if ((x) == NULL) return (y); \
  88     } while (JNI_FALSE)
  89 #endif
  90 
  91 #ifndef CHECK_EXCEPTION_RETURN
  92 #define CHECK_EXCEPTION_RETURN(env, y) \
  93     do { \
  94         if ((*env)->ExceptionCheck(env)) return (y); \
  95     } while (JNI_FALSE)
  96 #endif





  97 
  98 static jlong read_input_via_jni(unpacker* self,
  99                                 void* buf, jlong minlen, jlong maxlen);
 100 
 101 static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
 102   unpacker* uPtr;
 103   jlong p = env->CallLongMethod(pObj, getUnpackerPtrMID);
 104   uPtr = (unpacker*)jlong2ptr(p);
 105   if (uPtr == null) {
 106     if (noCreate)  return null;
 107     uPtr = new unpacker();
 108     if (uPtr == null) {
 109       THROW_IOE(ERROR_ENOMEM);
 110       return null;
 111     }
 112     //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
 113     uPtr->init(read_input_via_jni);
 114     uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
 115     env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr));
 116   }


   1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  77         if ((CERL_exception) == NULL) { \
  78             return CERL_return_value; \
  79         } \
  80     } while (JNI_FALSE)
  81 
  82 
  83 // If these useful macros aren't defined in jni_util.h then define them here
  84 #ifndef CHECK_NULL_RETURN
  85 #define CHECK_NULL_RETURN(x, y) \
  86     do { \
  87         if ((x) == NULL) return (y); \
  88     } while (JNI_FALSE)
  89 #endif
  90 
  91 #ifndef CHECK_EXCEPTION_RETURN
  92 #define CHECK_EXCEPTION_RETURN(env, y) \
  93     do { \
  94         if ((*env)->ExceptionCheck(env)) return (y); \
  95     } while (JNI_FALSE)
  96 #endif
  97 
  98 /*
  99  * Declare library specific JNI_Onload entry if static build
 100  */
 101 DEF_STATIC_JNI_OnLoad
 102 
 103 static jlong read_input_via_jni(unpacker* self,
 104                                 void* buf, jlong minlen, jlong maxlen);
 105 
 106 static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
 107   unpacker* uPtr;
 108   jlong p = env->CallLongMethod(pObj, getUnpackerPtrMID);
 109   uPtr = (unpacker*)jlong2ptr(p);
 110   if (uPtr == null) {
 111     if (noCreate)  return null;
 112     uPtr = new unpacker();
 113     if (uPtr == null) {
 114       THROW_IOE(ERROR_ENOMEM);
 115       return null;
 116     }
 117     //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
 118     uPtr->init(read_input_via_jni);
 119     uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
 120     env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr));
 121   }


< prev index next >