author | jcbeyler |
Wed, 24 Apr 2019 19:51:38 -0700 | |
changeset 54614 | fe9f33555993 |
parent 54599 | f5657f30bb01 |
child 54661 | 616618caad5e |
permissions | -rw-r--r-- |
52098 | 1 |
/* |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
3 |
* Copyright (c) 2018, 2019, Google and/or its affiliates. All rights reserved. |
52098 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
*/ |
|
24 |
||
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
25 |
#include <stdlib.h> |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
26 |
#include <string.h> |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
27 |
|
52098 | 28 |
#include "ExceptionCheckingJniEnv.hpp" |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
29 |
#include "nsk_tools.h" |
52098 | 30 |
|
31 |
namespace { |
|
32 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
33 |
static const char* get_dirname(const char* fullname) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
34 |
const char* p; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
35 |
const char* base = fullname;; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
36 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
37 |
if (fullname == NULL) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
38 |
return NULL; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
39 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
40 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
41 |
for (p = fullname; *p != '\0'; p++) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
42 |
if (*p == '/' || *p == '\\') { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
43 |
base = p + 1; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
44 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
45 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
46 |
return base; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
47 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
48 |
|
52098 | 49 |
template<class T = void*> |
50 |
class JNIVerifier { |
|
51 |
public: |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
52 |
JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
53 |
int line, const char* file) |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
54 |
: _env(env), _base_message(base_message), _error_message(NULL), |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
55 |
_line(line), _file(get_dirname(file)) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
56 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
57 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
58 |
// Until C++11 is supported, we have to write multiple template constructors. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
59 |
template <typename U> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
60 |
JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
61 |
U parameter, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
62 |
int line, const char* file) |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
63 |
: _env(env), _base_message(base_message), _error_message(NULL), |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
64 |
_line(line), _file(get_dirname(file)) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
65 |
PrintPreCall(parameter); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
66 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
67 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
68 |
template <typename U, typename V> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
69 |
JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
70 |
U parameter1, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
71 |
V parameter2, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
72 |
int line, const char* file) |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
73 |
: _env(env), _base_message(base_message), _error_message(NULL), |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
74 |
_line(line), _file(get_dirname(file)) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
75 |
PrintPreCall(parameter1, parameter2); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
76 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
77 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
78 |
template <typename U, typename V, typename W> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
79 |
JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
80 |
U parameter1, V parameter2, W parameter3, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
81 |
int line, const char* file) |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
82 |
: _env(env), _base_message(base_message), _error_message(NULL), |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
83 |
_line(line), _file(get_dirname(file)) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
84 |
PrintPreCall(parameter1, parameter2, parameter3); |
52098 | 85 |
} |
86 |
||
87 |
~JNIVerifier() { |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
88 |
PrintPostCall(); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
89 |
|
52098 | 90 |
JNIEnv* jni_env = _env->GetJNIEnv(); |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
91 |
if (jni_env->ExceptionCheck() && !_error_message) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
92 |
_error_message = "internal error"; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
93 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
94 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
95 |
if (_error_message != NULL) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
96 |
GenerateErrorMessage(); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
97 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
98 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
99 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
100 |
int DecimalToAsciiRec(char *str, long line) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
101 |
if (line == 0) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
102 |
return 0; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
103 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
104 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
105 |
int remainder = line % 10; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
106 |
long quotient = line / 10; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
107 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
108 |
int pos = DecimalToAsciiRec(str, quotient); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
109 |
str[pos] = '0' + remainder; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
110 |
return pos + 1; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
111 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
112 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
113 |
// Implementing a simple version of sprintf for "%d"... |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
114 |
void DecimalToAscii(char *str, int line) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
115 |
// Go to long so that the INT_MIN case can be handled seemlessly. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
116 |
long internal_line = line; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
117 |
if (internal_line == 0) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
118 |
str[0] = '0'; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
119 |
str[1] = '\0'; |
52098 | 120 |
return; |
121 |
} |
|
122 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
123 |
if (internal_line < 0) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
124 |
*str = '-'; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
125 |
internal_line *= -1; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
126 |
str++; |
52098 | 127 |
} |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
128 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
129 |
str[DecimalToAsciiRec(str, internal_line)] = '\0'; |
52098 | 130 |
} |
131 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
132 |
void GenerateErrorMessage() { |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
133 |
// This is error prone, but: |
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
134 |
// - Seems like we cannot use std::string (due to windows/solaris not |
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
135 |
// building when used, seemingly due to exception libraries not linking). |
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
136 |
// - Seems like we cannot use sprintf due to VS2013 (JDK-8213622). |
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
137 |
// |
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
138 |
// We are aiming to do: |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
139 |
// snprintf(full_message, len, "JNI method %s : %s from %s : %d", _base_message, _error_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
140 |
// _file, _line); |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
141 |
// but will use strlen + memcpy instead. |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
142 |
const char* pre_message = "JNI method "; |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
143 |
const char* between_msg = " : "; |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
144 |
const char* from_msg = " from "; |
52098 | 145 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
146 |
const char* file_name = _file ? _file : "Unknown File"; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
147 |
const char* strs[] = { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
148 |
pre_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
149 |
_base_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
150 |
between_msg, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
151 |
_error_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
152 |
from_msg, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
153 |
file_name, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
154 |
between_msg, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
155 |
}; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
156 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
157 |
size_t msg_number = sizeof(strs) / sizeof(strs[0]); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
158 |
size_t len = 0; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
159 |
for (size_t i = 0; i < msg_number; i++) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
160 |
len += strlen(strs[i]); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
161 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
162 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
163 |
// 32-bit signed means 11 characters due to the '-'. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
164 |
const int MAX_INTEGER_DIGITS = 11; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
165 |
// Add for the line number and 1 for the '\0'. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
166 |
len += MAX_INTEGER_DIGITS + 1; |
52098 | 167 |
|
168 |
char* full_message = (char*) malloc(len); |
|
169 |
if (full_message == NULL) { |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
170 |
_env->HandleError(_error_message); |
52098 | 171 |
return; |
172 |
} |
|
173 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
174 |
// Now we construct the string using strcat to not use sprintf/std::string |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
175 |
// instead of: |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
176 |
// snprintf(full_message, len, "JNI method %s : %s from %s:%d", _base_message, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
177 |
// _error_message, _file, _line); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
178 |
full_message[0] = '\0'; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
179 |
for (size_t i = 0; i < msg_number; i++) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
180 |
strcat(full_message, strs[i]); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
181 |
} |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
182 |
|
54614 | 183 |
// Add line number to end of the string. |
184 |
DecimalToAscii(full_message + strlen(full_message), _line); |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
185 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
186 |
if (strlen(full_message) >= len) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
187 |
_env->GetJNIEnv()->FatalError("Final length of message is not what was expected"); |
52561
40098289d580
8213622: Windows VS2013 build failure - "'snprintf': identifier not found"
jcbeyler
parents:
52132
diff
changeset
|
188 |
} |
52098 | 189 |
|
190 |
_env->HandleError(full_message); |
|
191 |
free(full_message); |
|
192 |
} |
|
193 |
||
194 |
T ResultNotNull(T ptr) { |
|
195 |
if (ptr == NULL) { |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
196 |
_error_message = "Return is NULL"; |
52098 | 197 |
} |
198 |
return ptr; |
|
199 |
} |
|
200 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
201 |
T ResultIsZero(T value) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
202 |
if (value != 0) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
203 |
_error_message = "Return is not zero"; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
204 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
205 |
return value; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
206 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
207 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
208 |
void PrintPreCallHeader() { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
209 |
if (!nsk_getVerboseMode()) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
210 |
return; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
211 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
212 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
213 |
fprintf(stdout, ">> Calling JNI method %s from %s:%d\n", |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
214 |
_base_message, _file, _line); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
215 |
fprintf(stdout, ">> Calling with these parameter(s):\n"); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
216 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
217 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
218 |
// Until we can actually link with C++ more uniformely across architectures, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
219 |
// we have to do this... |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
220 |
template<class U> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
221 |
void PrintParameter(U* ptr) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
222 |
fprintf(stdout, "\t%p\n", ptr); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
223 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
224 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
225 |
void PrintParameter(int value) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
226 |
fprintf(stdout, "\t%d\n", value); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
227 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
228 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
229 |
// Until C++11 is supported, we have to write multiple PrintPreCall. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
230 |
template<class U> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
231 |
void PrintPreCall(U first_parameter) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
232 |
if (!nsk_getVerboseMode()) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
233 |
return; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
234 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
235 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
236 |
PrintPreCallHeader(); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
237 |
PrintParameter(first_parameter); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
238 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
239 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
240 |
template<class U, class V> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
241 |
void PrintPreCall(U parameter1, V parameter2) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
242 |
if (!nsk_getVerboseMode()) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
243 |
return; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
244 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
245 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
246 |
PrintPreCallHeader(); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
247 |
PrintParameter(parameter1); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
248 |
PrintParameter(parameter2); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
249 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
250 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
251 |
template<class U, class V, class W> |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
252 |
void PrintPreCall(U parameter1, V parameter2, W parameter3) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
253 |
if (!nsk_getVerboseMode()) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
254 |
return; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
255 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
256 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
257 |
PrintPreCallHeader(); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
258 |
PrintParameter(parameter1); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
259 |
PrintParameter(parameter2); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
260 |
PrintParameter(parameter3); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
261 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
262 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
263 |
void PrintPostCall() { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
264 |
if (!nsk_getVerboseMode()) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
265 |
return; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
266 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
267 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
268 |
fprintf(stderr, "<< Called JNI method %s from %s:%d\n", |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
269 |
_base_message, _file, _line); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
270 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
271 |
|
52098 | 272 |
private: |
273 |
ExceptionCheckingJniEnv* _env; |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
274 |
const char* const _base_message; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
275 |
const char* _error_message; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
276 |
int _line; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
277 |
const char* const _file; |
52098 | 278 |
}; |
279 |
||
280 |
} |
|
281 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
282 |
jclass ExceptionCheckingJniEnv::FindClass(const char *class_name, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
283 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
284 |
JNIVerifier<jclass> marker(this, "FindClass", class_name, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
285 |
return marker.ResultNotNull(_jni_env->FindClass(class_name)); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
286 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
287 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
288 |
jint ExceptionCheckingJniEnv::RegisterNatives(jclass clazz, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
289 |
const JNINativeMethod *methods, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
290 |
jint nMethods, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
291 |
int line, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
292 |
const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
293 |
JNIVerifier<jint> marker(this, "RegisterNatives", methods, nMethods, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
294 |
return marker.ResultIsZero(_jni_env->RegisterNatives(clazz, methods, nMethods)); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
295 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
296 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
297 |
jclass ExceptionCheckingJniEnv::GetObjectClass(jobject obj, int line, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
298 |
const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
299 |
JNIVerifier<jclass> marker(this, "GetObjectClass", obj, line, file_name); |
52098 | 300 |
return marker.ResultNotNull(_jni_env->GetObjectClass(obj)); |
301 |
} |
|
302 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
303 |
jfieldID ExceptionCheckingJniEnv::GetStaticFieldID(jclass klass, const char *name, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
304 |
const char* type, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
305 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
306 |
JNIVerifier<jfieldID> marker(this, "GetStaticFieldID", klass, name, type, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
307 |
line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
308 |
return marker.ResultNotNull(_jni_env->GetStaticFieldID(klass, name, type)); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
309 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
310 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
311 |
jfieldID ExceptionCheckingJniEnv::GetFieldID(jclass klass, const char *name, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
312 |
const char* type, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
313 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
314 |
JNIVerifier<jfieldID> marker(this, "GetFieldID", klass, name, type, line, file_name); |
52098 | 315 |
return marker.ResultNotNull(_jni_env->GetFieldID(klass, name, type)); |
316 |
} |
|
317 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
318 |
jobject ExceptionCheckingJniEnv::GetStaticObjectField(jclass klass, jfieldID field, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
319 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
320 |
JNIVerifier<jobject> marker(this, "GetStaticObjectField", klass, field, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
321 |
line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
322 |
return marker.ResultNotNull(_jni_env->GetStaticObjectField(klass, field)); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
323 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
324 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
325 |
jobject ExceptionCheckingJniEnv::GetObjectField(jobject obj, jfieldID field, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
326 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
327 |
JNIVerifier<jobject> marker(this, "GetObjectField", obj, field, line, file_name); |
52098 | 328 |
return marker.ResultNotNull(_jni_env->GetObjectField(obj, field)); |
329 |
} |
|
330 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
331 |
void ExceptionCheckingJniEnv::SetObjectField(jobject obj, jfieldID field, jobject value, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
332 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
333 |
JNIVerifier<> marker(this, "SetObjectField", obj, field, value, line, file_name); |
52098 | 334 |
_jni_env->SetObjectField(obj, field, value); |
335 |
} |
|
336 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
337 |
jobject ExceptionCheckingJniEnv::NewGlobalRef(jobject obj, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
338 |
JNIVerifier<jobject> marker(this, "NewGlobalRef", obj, line, file_name); |
52098 | 339 |
return marker.ResultNotNull(_jni_env->NewGlobalRef(obj)); |
340 |
} |
|
341 |
||
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
342 |
void ExceptionCheckingJniEnv::DeleteGlobalRef(jobject obj, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
343 |
JNIVerifier<> marker(this, "DeleteGlobalRef", obj, line, file_name); |
52098 | 344 |
_jni_env->DeleteGlobalRef(obj); |
345 |
} |
|
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
346 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
347 |
jobject ExceptionCheckingJniEnv::NewLocalRef(jobject obj, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
348 |
JNIVerifier<jobject> marker(this, "NewLocalRef", obj, line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
349 |
return marker.ResultNotNull(_jni_env->NewLocalRef(obj)); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
350 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
351 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
352 |
void ExceptionCheckingJniEnv::DeleteLocalRef(jobject obj, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
353 |
JNIVerifier<> marker(this, "DeleteLocalRef", obj, line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
354 |
_jni_env->DeleteLocalRef(obj); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
355 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
356 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
357 |
jweak ExceptionCheckingJniEnv::NewWeakGlobalRef(jobject obj, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
358 |
JNIVerifier<jweak> marker(this, "NewWeakGlobalRef", obj, line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
359 |
return marker.ResultNotNull(_jni_env->NewWeakGlobalRef(obj)); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
360 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
361 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
362 |
void ExceptionCheckingJniEnv::DeleteWeakGlobalRef(jweak weak_ref, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
363 |
JNIVerifier<> marker(this, "DeleteWeakGlobalRef", weak_ref, line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
364 |
_jni_env->DeleteWeakGlobalRef(weak_ref); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
365 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
366 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
367 |
jsize ExceptionCheckingJniEnv::GetArrayLength(jarray array, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
368 |
JNIVerifier<> marker(this, "GetArrayLength", array, line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
369 |
return _jni_env->GetArrayLength(array); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
370 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
371 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
372 |
jsize ExceptionCheckingJniEnv::GetStringLength(jstring str, int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
373 |
JNIVerifier<> marker(this, "GetStringLength", str, line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
374 |
return _jni_env->GetStringLength(str); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
375 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
376 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
377 |
void* ExceptionCheckingJniEnv::GetPrimitiveArrayCritical(jarray array, jboolean* is_copy, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
378 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
379 |
JNIVerifier<> marker(this, "GetPrimitiveArrayCritical", array, is_copy, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
380 |
return marker.ResultNotNull(_jni_env->GetPrimitiveArrayCritical(array, is_copy)); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
381 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
382 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
383 |
void ExceptionCheckingJniEnv::ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
384 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
385 |
JNIVerifier<> marker(this, "ReleasePrimitiveArrayCritical", array, carray, mode, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
386 |
line, file_name); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
387 |
_jni_env->ReleasePrimitiveArrayCritical(array, carray, mode); |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
388 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
389 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
390 |
const jchar* ExceptionCheckingJniEnv::GetStringCritical(jstring str, jboolean* is_copy, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
391 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
392 |
JNIVerifier<const jchar*> marker(this, "GetPrimitiveArrayCritical", str, is_copy, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
393 |
line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
394 |
return marker.ResultNotNull(_jni_env->GetStringCritical(str, is_copy)); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
395 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
396 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
397 |
void ExceptionCheckingJniEnv::ReleaseStringCritical(jstring str, const jchar* carray, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
398 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
399 |
JNIVerifier<> marker(this, "ReleaseStringCritical", str, carray, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
400 |
_jni_env->ReleaseStringCritical(str, carray); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
401 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
402 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
403 |
jbyte* ExceptionCheckingJniEnv::GetByteArrayElements(jbyteArray array, jboolean* is_copy, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
404 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
405 |
JNIVerifier<jbyte*> marker(this, "GetByteArrayElements", array, is_copy, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
406 |
return marker.ResultNotNull(_jni_env->GetByteArrayElements(array, is_copy)); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
407 |
} |
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
408 |
|
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
409 |
void ExceptionCheckingJniEnv::ReleaseByteArrayElements(jbyteArray array, jbyte* byte_array, jint mode, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
410 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
411 |
JNIVerifier<> marker(this, "ReleaseByteArrayElements", array, byte_array, mode, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
412 |
line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
413 |
_jni_env->ReleaseByteArrayElements(array, byte_array, mode); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
414 |
} |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
415 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
416 |
jmethodID ExceptionCheckingJniEnv::GetMethodID(jclass klass, const char* name, const char* sig, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
417 |
int line, const char* file_name) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
418 |
JNIVerifier<jmethodID> marker(this, "GetMethodID", klass, name, sig, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
419 |
return marker.ResultNotNull(_jni_env->GetMethodID(klass, name, sig)); |
52132
04d4f1e4aff2
8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents:
52098
diff
changeset
|
420 |
} |
54599
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
421 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
422 |
jobject ExceptionCheckingJniEnv::NewObject(jclass klass, jmethodID methodID, |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
423 |
int line, const char* file_name, ...) { |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
424 |
// In the case of NewObject, we miss the extra arguments passed to NewObject sadly. |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
425 |
JNIVerifier<jobject> marker(this, "NewObject", klass, methodID, line, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
426 |
|
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
427 |
va_list args; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
428 |
va_start(args, file_name); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
429 |
jobject result = marker.ResultNotNull(_jni_env->NewObjectV(klass, methodID, args)); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
430 |
va_end(args); |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
431 |
return result; |
f5657f30bb01
8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents:
52561
diff
changeset
|
432 |
} |