< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page
rev 50331 : 8198285: More consistent Access API for arraycopy
rev 50332 : [mq]: JDK-8203232-2.patch
rev 50333 : [mq]: JDK-8198285-3.patch


2449  HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(ret);
2450   return ret;
2451 JNI_END
2452 
2453 
2454 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars(
2455   JNIEnv *env, jstring string, jboolean *isCopy))
2456   JNIWrapper("GetStringChars");
2457  HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(env, string, (uintptr_t *) isCopy);
2458   jchar* buf = NULL;
2459   oop s = JNIHandles::resolve_non_null(string);
2460   typeArrayOop s_value = java_lang_String::value(s);
2461   if (s_value != NULL) {
2462     int s_len = java_lang_String::length(s);
2463     bool is_latin1 = java_lang_String::is_latin1(s);
2464     buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
2465     /* JNI Specification states return NULL on OOM */
2466     if (buf != NULL) {
2467       if (s_len > 0) {
2468         if (!is_latin1) {
2469           memcpy(buf, s_value->char_at_addr(0), sizeof(jchar)*s_len);

2470         } else {
2471           for (int i = 0; i < s_len; i++) {
2472             buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
2473           }
2474         }
2475       }
2476       buf[s_len] = 0;
2477       //%note jni_5
2478       if (isCopy != NULL) {
2479         *isCopy = JNI_TRUE;
2480       }
2481     }
2482   }
2483   HOTSPOT_JNI_GETSTRINGCHARS_RETURN(buf);
2484   return buf;
2485 JNI_END
2486 
2487 
2488 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars))
2489   JNIWrapper("ReleaseStringChars");


2705                                       , EntryProbe, ReturnProbe) \
2706 \
2707 JNI_QUICK_ENTRY(ElementType*, \
2708           jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
2709   JNIWrapper("Get" XSTR(Result) "ArrayElements"); \
2710   EntryProbe; \
2711   /* allocate an chunk of memory in c land */ \
2712   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2713   ElementType* result; \
2714   int len = a->length(); \
2715   if (len == 0) { \
2716     /* Empty array: legal but useless, can't return NULL. \
2717      * Return a pointer to something useless. \
2718      * Avoid asserts in typeArrayOop. */ \
2719     result = (ElementType*)get_bad_address(); \
2720   } else { \
2721     /* JNI Specification states return NULL on OOM */                    \
2722     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
2723     if (result != NULL) {                                                \
2724       /* copy the array to the c chunk */                                \
2725       memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len);      \

2726       if (isCopy) {                                                      \
2727         *isCopy = JNI_TRUE;                                              \
2728       }                                                                  \
2729     }                                                                    \
2730   } \
2731   ReturnProbe; \
2732   return result; \
2733 JNI_END
2734 
2735 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2736                               , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2737                               HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result))
2738 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2739                               , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2740                               HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result))
2741 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2742                               , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
2743                               HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result))
2744 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2745                               , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),


2754 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
2755                               , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2756                               HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result))
2757 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
2758                               , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2759                               HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result))
2760 
2761 
2762 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \
2763                                           , EntryProbe, ReturnProbe);\
2764 \
2765 JNI_QUICK_ENTRY(void, \
2766           jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
2767                                              ElementType *buf, jint mode)) \
2768   JNIWrapper("Release" XSTR(Result) "ArrayElements"); \
2769   EntryProbe; \
2770   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2771   int len = a->length(); \
2772   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
2773     if ((mode == 0) || (mode == JNI_COMMIT)) { \
2774       memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \
2775     } \
2776     if ((mode == 0) || (mode == JNI_ABORT)) { \
2777       FreeHeap(buf); \
2778     } \
2779   } \
2780   ReturnProbe; \
2781 JNI_END
2782 
2783 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2784                                   , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
2785                                   HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN())
2786 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2787                                   , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode),
2788                                   HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN())
2789 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2790                                   ,  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2791                                   HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN())
2792 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2793                                   ,  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2794                                   HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN())


2805                                   , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode),
2806                                   HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN())
2807 
2808 
2809 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2810                                     , EntryProbe, ReturnProbe); \
2811   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \
2812                            , ReturnProbe); \
2813 \
2814 JNI_ENTRY(void, \
2815 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2816              jsize len, ElementType *buf)) \
2817   JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \
2818   EntryProbe; \
2819   DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
2820   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2821   if (start < 0 || len < 0 || (start > src->length() - len)) { \
2822     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
2823   } else { \
2824     if (len > 0) { \
2825       int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \
2826       memcpy((u_char*) buf, \
2827              (u_char*) src->Tag##_at_addr(start), \
2828              len << sc);                          \
2829     } \
2830   } \
2831 JNI_END
2832 
2833 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool
2834                             , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2835                             HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN());
2836 DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte
2837                             ,  HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2838                             HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN());
2839 DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short
2840                             , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2841                             HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN());
2842 DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char
2843                             ,  HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf),
2844                             HOTSPOT_JNI_GETCHARARRAYREGION_RETURN());
2845 DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int
2846                             , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf),
2847                             HOTSPOT_JNI_GETINTARRAYREGION_RETURN());
2848 DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long


2855                             , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2856                             HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN());
2857 
2858 
2859 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2860                                     , EntryProbe, ReturnProbe); \
2861   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \
2862                            ,ReturnProbe);           \
2863 \
2864 JNI_ENTRY(void, \
2865 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2866              jsize len, const ElementType *buf)) \
2867   JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \
2868   EntryProbe; \
2869   DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
2870   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2871   if (start < 0 || len < 0 || (start > dst->length() - len)) { \
2872     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
2873   } else { \
2874     if (len > 0) { \
2875       int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \
2876       memcpy((u_char*) dst->Tag##_at_addr(start), \
2877              (u_char*) buf, \
2878              len << sc);    \
2879     } \
2880   } \
2881 JNI_END
2882 
2883 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool
2884                             , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf),
2885                             HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN())
2886 DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte
2887                             , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2888                             HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN())
2889 DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short
2890                             , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2891                             HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
2892 DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char
2893                             , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2894                             HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
2895 DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int
2896                             , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
2897                             HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
2898 DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long


3094 //
3095 // Extensions
3096 //
3097 
3098 DT_VOID_RETURN_MARK_DECL(GetStringRegion
3099                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
3100 
3101 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
3102   JNIWrapper("GetStringRegion");
3103  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(env, string, start, len, buf);
3104   DT_VOID_RETURN_MARK(GetStringRegion);
3105   oop s = JNIHandles::resolve_non_null(string);
3106   int s_len = java_lang_String::length(s);
3107   if (start < 0 || len < 0 || start > s_len - len) {
3108     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
3109   } else {
3110     if (len > 0) {
3111       typeArrayOop s_value = java_lang_String::value(s);
3112       bool is_latin1 = java_lang_String::is_latin1(s);
3113       if (!is_latin1) {
3114         memcpy(buf, s_value->char_at_addr(start), sizeof(jchar)*len);

3115       } else {
3116         for (int i = 0; i < len; i++) {
3117           buf[i] = ((jchar) s_value->byte_at(i + start)) & 0xff;
3118         }
3119       }
3120     }
3121   }
3122 JNI_END
3123 
3124 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion
3125                          , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN());
3126 
3127 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf))
3128   JNIWrapper("GetStringUTFRegion");
3129  HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(env, string, start, len, buf);
3130   DT_VOID_RETURN_MARK(GetStringUTFRegion);
3131   oop s = JNIHandles::resolve_non_null(string);
3132   int s_len = java_lang_String::length(s);
3133   if (start < 0 || len < 0 || start > s_len - len) {
3134     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());




2449  HOTSPOT_JNI_GETSTRINGLENGTH_RETURN(ret);
2450   return ret;
2451 JNI_END
2452 
2453 
2454 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars(
2455   JNIEnv *env, jstring string, jboolean *isCopy))
2456   JNIWrapper("GetStringChars");
2457  HOTSPOT_JNI_GETSTRINGCHARS_ENTRY(env, string, (uintptr_t *) isCopy);
2458   jchar* buf = NULL;
2459   oop s = JNIHandles::resolve_non_null(string);
2460   typeArrayOop s_value = java_lang_String::value(s);
2461   if (s_value != NULL) {
2462     int s_len = java_lang_String::length(s);
2463     bool is_latin1 = java_lang_String::is_latin1(s);
2464     buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal);  // add one for zero termination
2465     /* JNI Specification states return NULL on OOM */
2466     if (buf != NULL) {
2467       if (s_len > 0) {
2468         if (!is_latin1) {
2469           ArrayAccess<>::arraycopy_to_native<>(s_value, (size_t) typeArrayOopDesc::element_offset<jchar>(0),
2470                                                buf, s_len);
2471         } else {
2472           for (int i = 0; i < s_len; i++) {
2473             buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
2474           }
2475         }
2476       }
2477       buf[s_len] = 0;
2478       //%note jni_5
2479       if (isCopy != NULL) {
2480         *isCopy = JNI_TRUE;
2481       }
2482     }
2483   }
2484   HOTSPOT_JNI_GETSTRINGCHARS_RETURN(buf);
2485   return buf;
2486 JNI_END
2487 
2488 
2489 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars))
2490   JNIWrapper("ReleaseStringChars");


2706                                       , EntryProbe, ReturnProbe) \
2707 \
2708 JNI_QUICK_ENTRY(ElementType*, \
2709           jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \
2710   JNIWrapper("Get" XSTR(Result) "ArrayElements"); \
2711   EntryProbe; \
2712   /* allocate an chunk of memory in c land */ \
2713   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2714   ElementType* result; \
2715   int len = a->length(); \
2716   if (len == 0) { \
2717     /* Empty array: legal but useless, can't return NULL. \
2718      * Return a pointer to something useless. \
2719      * Avoid asserts in typeArrayOop. */ \
2720     result = (ElementType*)get_bad_address(); \
2721   } else { \
2722     /* JNI Specification states return NULL on OOM */                    \
2723     result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \
2724     if (result != NULL) {                                                \
2725       /* copy the array to the c chunk */                                \
2726       ArrayAccess<>::arraycopy_to_native<>(a, typeArrayOopDesc::element_offset<ElementType>(0), \
2727                                            result, len);                 \
2728       if (isCopy) {                                                      \
2729         *isCopy = JNI_TRUE;                                              \
2730       }                                                                  \
2731     }                                                                    \
2732   } \
2733   ReturnProbe; \
2734   return result; \
2735 JNI_END
2736 
2737 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2738                               , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2739                               HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result))
2740 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2741                               , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2742                               HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result))
2743 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2744                               , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),
2745                               HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result))
2746 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2747                               , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy),


2756 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT,   jfloat,   Float,   float
2757                               , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2758                               HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result))
2759 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE,  jdouble,  Double,  double
2760                               , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy),
2761                               HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result))
2762 
2763 
2764 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \
2765                                           , EntryProbe, ReturnProbe);\
2766 \
2767 JNI_QUICK_ENTRY(void, \
2768           jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \
2769                                              ElementType *buf, jint mode)) \
2770   JNIWrapper("Release" XSTR(Result) "ArrayElements"); \
2771   EntryProbe; \
2772   typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2773   int len = a->length(); \
2774   if (len != 0) {   /* Empty array:  nothing to free or copy. */  \
2775     if ((mode == 0) || (mode == JNI_COMMIT)) { \
2776       ArrayAccess<>::arraycopy_from_native<>(buf, a, typeArrayOopDesc::element_offset<ElementType>(0), len); \
2777     } \
2778     if ((mode == 0) || (mode == JNI_ABORT)) { \
2779       FreeHeap(buf); \
2780     } \
2781   } \
2782   ReturnProbe; \
2783 JNI_END
2784 
2785 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool
2786                                   , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode),
2787                                   HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN())
2788 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE,    jbyte,    Byte,    byte
2789                                   , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode),
2790                                   HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN())
2791 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT,   jshort,   Short,   short
2792                                   ,  HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2793                                   HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN())
2794 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR,    jchar,    Char,    char
2795                                   ,  HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode),
2796                                   HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN())


2807                                   , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode),
2808                                   HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN())
2809 
2810 
2811 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2812                                     , EntryProbe, ReturnProbe); \
2813   DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \
2814                            , ReturnProbe); \
2815 \
2816 JNI_ENTRY(void, \
2817 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2818              jsize len, ElementType *buf)) \
2819   JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \
2820   EntryProbe; \
2821   DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \
2822   typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2823   if (start < 0 || len < 0 || (start > src->length() - len)) { \
2824     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
2825   } else { \
2826     if (len > 0) { \
2827       ArrayAccess<>::arraycopy_to_native<>(src, typeArrayOopDesc::element_offset<ElementType>(start), buf, len); \



2828     } \
2829   } \
2830 JNI_END
2831 
2832 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool
2833                             , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2834                             HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN());
2835 DEFINE_GETSCALARARRAYREGION(T_BYTE,    jbyte,   Byte,    byte
2836                             ,  HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2837                             HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN());
2838 DEFINE_GETSCALARARRAYREGION(T_SHORT,   jshort,  Short,   short
2839                             , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2840                             HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN());
2841 DEFINE_GETSCALARARRAYREGION(T_CHAR,    jchar,   Char,    char
2842                             ,  HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf),
2843                             HOTSPOT_JNI_GETCHARARRAYREGION_RETURN());
2844 DEFINE_GETSCALARARRAYREGION(T_INT,     jint,    Int,     int
2845                             , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf),
2846                             HOTSPOT_JNI_GETINTARRAYREGION_RETURN());
2847 DEFINE_GETSCALARARRAYREGION(T_LONG,    jlong,   Long,    long


2854                             , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2855                             HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN());
2856 
2857 
2858 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \
2859                                     , EntryProbe, ReturnProbe); \
2860   DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \
2861                            ,ReturnProbe);           \
2862 \
2863 JNI_ENTRY(void, \
2864 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \
2865              jsize len, const ElementType *buf)) \
2866   JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \
2867   EntryProbe; \
2868   DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \
2869   typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \
2870   if (start < 0 || len < 0 || (start > dst->length() - len)) { \
2871     THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \
2872   } else { \
2873     if (len > 0) { \
2874       ArrayAccess<>::arraycopy_from_native<>(buf, dst, typeArrayOopDesc::element_offset<ElementType>(start), len); \



2875     } \
2876   } \
2877 JNI_END
2878 
2879 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool
2880                             , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf),
2881                             HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN())
2882 DEFINE_SETSCALARARRAYREGION(T_BYTE,    jbyte,    Byte,    byte
2883                             , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf),
2884                             HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN())
2885 DEFINE_SETSCALARARRAYREGION(T_SHORT,   jshort,   Short,   short
2886                             , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2887                             HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
2888 DEFINE_SETSCALARARRAYREGION(T_CHAR,    jchar,    Char,    char
2889                             , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2890                             HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
2891 DEFINE_SETSCALARARRAYREGION(T_INT,     jint,     Int,     int
2892                             , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
2893                             HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
2894 DEFINE_SETSCALARARRAYREGION(T_LONG,    jlong,    Long,    long


3090 //
3091 // Extensions
3092 //
3093 
3094 DT_VOID_RETURN_MARK_DECL(GetStringRegion
3095                          , HOTSPOT_JNI_GETSTRINGREGION_RETURN());
3096 
3097 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf))
3098   JNIWrapper("GetStringRegion");
3099  HOTSPOT_JNI_GETSTRINGREGION_ENTRY(env, string, start, len, buf);
3100   DT_VOID_RETURN_MARK(GetStringRegion);
3101   oop s = JNIHandles::resolve_non_null(string);
3102   int s_len = java_lang_String::length(s);
3103   if (start < 0 || len < 0 || start > s_len - len) {
3104     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
3105   } else {
3106     if (len > 0) {
3107       typeArrayOop s_value = java_lang_String::value(s);
3108       bool is_latin1 = java_lang_String::is_latin1(s);
3109       if (!is_latin1) {
3110         ArrayAccess<>::arraycopy_to_native<>(s_value, typeArrayOopDesc::element_offset<jchar>(start),
3111                                              buf, len);
3112       } else {
3113         for (int i = 0; i < len; i++) {
3114           buf[i] = ((jchar) s_value->byte_at(i + start)) & 0xff;
3115         }
3116       }
3117     }
3118   }
3119 JNI_END
3120 
3121 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion
3122                          , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN());
3123 
3124 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf))
3125   JNIWrapper("GetStringUTFRegion");
3126  HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY(env, string, start, len, buf);
3127   DT_VOID_RETURN_MARK(GetStringUTFRegion);
3128   oop s = JNIHandles::resolve_non_null(string);
3129   int s_len = java_lang_String::length(s);
3130   if (start < 0 || len < 0 || start > s_len - len) {
3131     THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());


< prev index next >