1286 jsize result = UNCHECKED()->GetStringLength(env,str); |
1286 jsize result = UNCHECKED()->GetStringLength(env,str); |
1287 functionExit(env); |
1287 functionExit(env); |
1288 return result; |
1288 return result; |
1289 JNI_END |
1289 JNI_END |
1290 |
1290 |
|
1291 // Arbitrary (but well-known) tag |
|
1292 const jint STRING_TAG = 0x47114711; |
|
1293 |
1291 JNI_ENTRY_CHECKED(const jchar *, |
1294 JNI_ENTRY_CHECKED(const jchar *, |
1292 checked_jni_GetStringChars(JNIEnv *env, |
1295 checked_jni_GetStringChars(JNIEnv *env, |
1293 jstring str, |
1296 jstring str, |
1294 jboolean *isCopy)) |
1297 jboolean *isCopy)) |
1295 functionEnter(thr); |
1298 functionEnter(thr); |
1296 IN_VM( |
1299 IN_VM( |
1297 checkString(thr, str); |
1300 checkString(thr, str); |
1298 ) |
1301 ) |
1299 const jchar *result = UNCHECKED()->GetStringChars(env,str,isCopy); |
1302 const jchar *result = UNCHECKED()->GetStringChars(env,str,isCopy); |
1300 functionExit(env); |
1303 assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringChars didn't return a copy as expected"); |
1301 return result; |
1304 |
|
1305 size_t len = UNCHECKED()->GetStringLength(env,str) + 1; // + 1 for NULL termination |
|
1306 jint* tagLocation = (jint*) AllocateHeap(len * sizeof(jchar) + sizeof(jint), "checked_jni_GetStringChars"); |
|
1307 *tagLocation = STRING_TAG; |
|
1308 jchar* newResult = (jchar*) (tagLocation + 1); |
|
1309 memcpy(newResult, result, len * sizeof(jchar)); |
|
1310 // Avoiding call to UNCHECKED()->ReleaseStringChars() since that will fire unexpected dtrace probes |
|
1311 // Note that the dtrace arguments for the allocated memory will not match up with this solution. |
|
1312 FreeHeap((char*)result); |
|
1313 |
|
1314 functionExit(env); |
|
1315 return newResult; |
1302 JNI_END |
1316 JNI_END |
1303 |
1317 |
1304 JNI_ENTRY_CHECKED(void, |
1318 JNI_ENTRY_CHECKED(void, |
1305 checked_jni_ReleaseStringChars(JNIEnv *env, |
1319 checked_jni_ReleaseStringChars(JNIEnv *env, |
1306 jstring str, |
1320 jstring str, |
1307 const jchar *chars)) |
1321 const jchar *chars)) |
1308 functionEnterExceptionAllowed(thr); |
1322 functionEnterExceptionAllowed(thr); |
1309 IN_VM( |
1323 IN_VM( |
1310 checkString(thr, str); |
1324 checkString(thr, str); |
1311 ) |
1325 ) |
1312 /* cannot check validity of copy, unless every request is logged by |
1326 if (chars == NULL) { |
1313 * checking code. Implementation of this check is deferred until a |
1327 // still do the unchecked call to allow dtrace probes |
1314 * subsequent release. |
1328 UNCHECKED()->ReleaseStringChars(env,str,chars); |
1315 */ |
1329 } |
1316 UNCHECKED()->ReleaseStringChars(env,str,chars); |
1330 else { |
|
1331 jint* tagLocation = ((jint*) chars) - 1; |
|
1332 if (*tagLocation != STRING_TAG) { |
|
1333 NativeReportJNIFatalError(thr, "ReleaseStringChars called on something not allocated by GetStringChars"); |
|
1334 } |
|
1335 UNCHECKED()->ReleaseStringChars(env,str,(const jchar*)tagLocation); |
|
1336 } |
1317 functionExit(env); |
1337 functionExit(env); |
1318 JNI_END |
1338 JNI_END |
1319 |
1339 |
1320 JNI_ENTRY_CHECKED(jstring, |
1340 JNI_ENTRY_CHECKED(jstring, |
1321 checked_jni_NewStringUTF(JNIEnv *env, |
1341 checked_jni_NewStringUTF(JNIEnv *env, |
1335 ) |
1355 ) |
1336 jsize result = UNCHECKED()->GetStringUTFLength(env,str); |
1356 jsize result = UNCHECKED()->GetStringUTFLength(env,str); |
1337 functionExit(env); |
1357 functionExit(env); |
1338 return result; |
1358 return result; |
1339 JNI_END |
1359 JNI_END |
|
1360 |
|
1361 // Arbitrary (but well-known) tag - different than GetStringChars |
|
1362 const jint STRING_UTF_TAG = 0x48124812; |
1340 |
1363 |
1341 JNI_ENTRY_CHECKED(const char *, |
1364 JNI_ENTRY_CHECKED(const char *, |
1342 checked_jni_GetStringUTFChars(JNIEnv *env, |
1365 checked_jni_GetStringUTFChars(JNIEnv *env, |
1343 jstring str, |
1366 jstring str, |
1344 jboolean *isCopy)) |
1367 jboolean *isCopy)) |
1345 functionEnter(thr); |
1368 functionEnter(thr); |
1346 IN_VM( |
1369 IN_VM( |
1347 checkString(thr, str); |
1370 checkString(thr, str); |
1348 ) |
1371 ) |
1349 const char *result = UNCHECKED()->GetStringUTFChars(env,str,isCopy); |
1372 const char *result = UNCHECKED()->GetStringUTFChars(env,str,isCopy); |
1350 functionExit(env); |
1373 assert (isCopy == NULL || *isCopy == JNI_TRUE, "GetStringUTFChars didn't return a copy as expected"); |
1351 return result; |
1374 |
|
1375 size_t len = strlen(result) + 1; // + 1 for NULL termination |
|
1376 jint* tagLocation = (jint*) AllocateHeap(len + sizeof(jint), "checked_jni_GetStringUTFChars"); |
|
1377 *tagLocation = STRING_UTF_TAG; |
|
1378 char* newResult = (char*) (tagLocation + 1); |
|
1379 strcpy(newResult, result); |
|
1380 // Avoiding call to UNCHECKED()->ReleaseStringUTFChars() since that will fire unexpected dtrace probes |
|
1381 // Note that the dtrace arguments for the allocated memory will not match up with this solution. |
|
1382 FreeHeap((char*)result); |
|
1383 |
|
1384 functionExit(env); |
|
1385 return newResult; |
1352 JNI_END |
1386 JNI_END |
1353 |
1387 |
1354 JNI_ENTRY_CHECKED(void, |
1388 JNI_ENTRY_CHECKED(void, |
1355 checked_jni_ReleaseStringUTFChars(JNIEnv *env, |
1389 checked_jni_ReleaseStringUTFChars(JNIEnv *env, |
1356 jstring str, |
1390 jstring str, |
1357 const char* chars)) |
1391 const char* chars)) |
1358 functionEnterExceptionAllowed(thr); |
1392 functionEnterExceptionAllowed(thr); |
1359 IN_VM( |
1393 IN_VM( |
1360 checkString(thr, str); |
1394 checkString(thr, str); |
1361 ) |
1395 ) |
1362 /* cannot check validity of copy, unless every request is logged by |
1396 if (chars == NULL) { |
1363 * checking code. Implementation of this check is deferred until a |
1397 // still do the unchecked call to allow dtrace probes |
1364 * subsequent release. |
1398 UNCHECKED()->ReleaseStringUTFChars(env,str,chars); |
1365 */ |
1399 } |
1366 UNCHECKED()->ReleaseStringUTFChars(env,str,chars); |
1400 else { |
|
1401 jint* tagLocation = ((jint*) chars) - 1; |
|
1402 if (*tagLocation != STRING_UTF_TAG) { |
|
1403 NativeReportJNIFatalError(thr, "ReleaseStringUTFChars called on something not allocated by GetStringUTFChars"); |
|
1404 } |
|
1405 UNCHECKED()->ReleaseStringUTFChars(env,str,(const char*)tagLocation); |
|
1406 } |
1367 functionExit(env); |
1407 functionExit(env); |
1368 JNI_END |
1408 JNI_END |
1369 |
1409 |
1370 JNI_ENTRY_CHECKED(jsize, |
1410 JNI_ENTRY_CHECKED(jsize, |
1371 checked_jni_GetArrayLength(JNIEnv *env, |
1411 checked_jni_GetArrayLength(JNIEnv *env, |