blob: 67020d874b3defc24e911452ef2ff5685ddf2be7 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Elliott Hughes0c9cd562011-08-12 10:59:29 -070016
Carl Shapiro9b9ba282011-08-14 15:30:39 -070017#include "jni_internal.h"
Elliott Hughes0c9cd562011-08-12 10:59:29 -070018
Elliott Hughesf66330a2012-12-12 17:27:00 -080019#include <cfloat>
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070020#include <cmath>
21
Carl Shapiro9b9ba282011-08-14 15:30:39 -070022#include "common_test.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "mirror/abstract_method-inl.h"
24#include "mirror/object_array-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070025#include "mirror/object-inl.h"
Elliott Hughes726079d2011-10-07 18:43:44 -070026#include "ScopedLocalRef.h"
Ian Rogers1f539342012-10-03 21:09:42 -070027#include "sirt_ref.h"
Elliott Hughes0c9cd562011-08-12 10:59:29 -070028
29namespace art {
30
Brian Carlstromf734cf52011-08-17 16:28:14 -070031class JniInternalTest : public CommonTest {
Elliott Hughesc7ac37f2011-08-12 12:21:58 -070032 protected:
33 virtual void SetUp() {
Brian Carlstromf734cf52011-08-17 16:28:14 -070034 CommonTest::SetUp();
Elliott Hughes5174fe62011-08-23 15:12:35 -070035
Elliott Hughesa2501992011-08-26 19:39:54 -070036 vm_ = Runtime::Current()->GetJavaVM();
37
Elliott Hughes5174fe62011-08-23 15:12:35 -070038 // Turn on -verbose:jni for the JNI tests.
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -080039 gLogVerbosity.jni = true;
Elliott Hughes5174fe62011-08-23 15:12:35 -070040
Brian Carlstrom4d571432012-05-16 00:21:41 -070041 vm_->AttachCurrentThread(&env_, NULL);
Elliott Hughesb465ab02011-08-24 11:21:21 -070042
Elliott Hughes726079d2011-10-07 18:43:44 -070043 ScopedLocalRef<jclass> aioobe(env_, env_->FindClass("java/lang/ArrayIndexOutOfBoundsException"));
44 CHECK(aioobe.get() != NULL);
45 aioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(aioobe.get()));
Elliott Hughesb465ab02011-08-24 11:21:21 -070046
Elliott Hughesb264f082012-04-06 17:10:10 -070047 ScopedLocalRef<jclass> ase(env_, env_->FindClass("java/lang/ArrayStoreException"));
48 CHECK(ase.get() != NULL);
49 ase_ = reinterpret_cast<jclass>(env_->NewGlobalRef(ase.get()));
50
Elliott Hughes726079d2011-10-07 18:43:44 -070051 ScopedLocalRef<jclass> sioobe(env_, env_->FindClass("java/lang/StringIndexOutOfBoundsException"));
52 CHECK(sioobe.get() != NULL);
53 sioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(sioobe.get()));
54 }
55
Brian Carlstrom4d571432012-05-16 00:21:41 -070056 void CleanUpJniEnv() {
57 if (aioobe_ != NULL) {
58 env_->DeleteGlobalRef(aioobe_);
59 aioobe_ = NULL;
60 }
61 if (ase_ != NULL) {
62 env_->DeleteGlobalRef(ase_);
63 ase_ = NULL;
64 }
65 if (sioobe_ != NULL) {
66 env_->DeleteGlobalRef(sioobe_);
67 sioobe_ = NULL;
68 }
69 }
70
Elliott Hughes726079d2011-10-07 18:43:44 -070071 virtual void TearDown() {
Brian Carlstrom4d571432012-05-16 00:21:41 -070072 CleanUpJniEnv();
Elliott Hughes726079d2011-10-07 18:43:44 -070073 CommonTest::TearDown();
Elliott Hughesc7ac37f2011-08-12 12:21:58 -070074 }
Elliott Hughesb465ab02011-08-24 11:21:21 -070075
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 mirror::AbstractMethod::InvokeStub* DoCompile(mirror::AbstractMethod*& method,
77 mirror::Object*& receiver,
78 bool is_static, const char* method_name,
79 const char* method_signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -070080 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Elliott Hughes77405792012-03-15 15:22:12 -070081 const char* class_name = is_static ? "StaticLeafMethods" : "NonStaticLeafMethods";
Ian Rogers00f7d0e2012-07-19 15:28:27 -070082 jobject jclass_loader(LoadDex(class_name));
Ian Rogers1f539342012-10-03 21:09:42 -070083 Thread* self = Thread::Current();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080084 SirtRef<mirror::ClassLoader>
Ian Rogers1f539342012-10-03 21:09:42 -070085 class_loader(self,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080086 ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader));
Elliott Hughes77405792012-03-15 15:22:12 -070087 if (is_static) {
88 CompileDirectMethod(class_loader.get(), class_name, method_name, method_signature);
89 } else {
90 CompileVirtualMethod(NULL, "java.lang.Class", "isFinalizable", "()Z");
91 CompileDirectMethod(NULL, "java.lang.Object", "<init>", "()V");
92 CompileVirtualMethod(class_loader.get(), class_name, method_name, method_signature);
93 }
94
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080095 mirror::Class* c = class_linker_->FindClass(DotToDescriptor(class_name).c_str(), class_loader.get());
Elliott Hughes77405792012-03-15 15:22:12 -070096 CHECK(c != NULL);
97
Ian Rogers00f7d0e2012-07-19 15:28:27 -070098 method = is_static ? c->FindDirectMethod(method_name, method_signature)
99 : c->FindVirtualMethod(method_name, method_signature);
Elliott Hughes77405792012-03-15 15:22:12 -0700100 CHECK(method != NULL);
101
Ian Rogers50b35e22012-10-04 10:09:15 -0700102 receiver = (is_static ? NULL : c->AllocObject(self));
Elliott Hughes77405792012-03-15 15:22:12 -0700103
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800104 mirror::AbstractMethod::InvokeStub* stub = method->GetInvokeStub();
Elliott Hughes77405792012-03-15 15:22:12 -0700105 CHECK(stub != NULL);
106
107 return stub;
108 }
109
Ian Rogersb726dcb2012-09-05 08:57:23 -0700110 void InvokeNopMethod(bool is_static) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800111 mirror::AbstractMethod* method;
112 mirror::Object* receiver;
113 mirror::AbstractMethod::InvokeStub* stub = DoCompile(method, receiver, is_static, "nop", "()V");
Elliott Hughes77405792012-03-15 15:22:12 -0700114 (*stub)(method, receiver, Thread::Current(), NULL, NULL);
115 }
116
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700117 void InvokeIdentityByteMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700118 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800119 mirror::AbstractMethod* method;
120 mirror::Object* receiver;
121 mirror::AbstractMethod::InvokeStub* stub =
122 DoCompile(method, receiver, is_static, "identity", "(B)B");
Elliott Hughes77405792012-03-15 15:22:12 -0700123
124 JValue args[1];
125 JValue result;
126
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700127 args[0].SetB(0);
128 result.SetB(-1);
Elliott Hughes77405792012-03-15 15:22:12 -0700129 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700130 EXPECT_EQ(0, result.GetB());
Elliott Hughes77405792012-03-15 15:22:12 -0700131
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700132 args[0].SetB(-1);
133 result.SetB(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700134 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700135 EXPECT_EQ(-1, result.GetB());
Elliott Hughes77405792012-03-15 15:22:12 -0700136
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700137 args[0].SetB(SCHAR_MAX);
138 result.SetB(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700139 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700140 EXPECT_EQ(SCHAR_MAX, result.GetB());
Elliott Hughes77405792012-03-15 15:22:12 -0700141
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700142 args[0].SetB(SCHAR_MIN);
143 result.SetB(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700144 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700145 EXPECT_EQ(SCHAR_MIN, result.GetB());
Elliott Hughes77405792012-03-15 15:22:12 -0700146 }
147
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700148 void InvokeIdentityIntMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800150 mirror::AbstractMethod* method;
151 mirror::Object* receiver;
152 mirror::AbstractMethod::InvokeStub* stub =
153 DoCompile(method, receiver, is_static, "identity", "(I)I");
Elliott Hughes77405792012-03-15 15:22:12 -0700154
155 JValue args[1];
156 JValue result;
157
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700158 args[0].SetI(0);
159 result.SetI(-1);
Elliott Hughes77405792012-03-15 15:22:12 -0700160 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700161 EXPECT_EQ(0, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700162
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700163 args[0].SetI(-1);
164 result.SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700165 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700166 EXPECT_EQ(-1, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700167
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700168 args[0].SetI(INT_MAX);
169 result.SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700170 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700171 EXPECT_EQ(INT_MAX, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700172
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700173 args[0].SetI(INT_MIN);
174 result.SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700175 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700176 EXPECT_EQ(INT_MIN, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700177 }
178
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700179 void InvokeIdentityDoubleMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700180 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800181 mirror::AbstractMethod* method;
182 mirror::Object* receiver;
183 mirror::AbstractMethod::InvokeStub* stub =
184 DoCompile(method, receiver, is_static, "identity", "(D)D");
Elliott Hughes77405792012-03-15 15:22:12 -0700185
186 JValue args[1];
187 JValue result;
188
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700189 args[0].SetD(0.0);
190 result.SetD(-1.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700191 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700192 EXPECT_EQ(0.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700193
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700194 args[0].SetD(-1.0);
195 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700196 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700197 EXPECT_EQ(-1.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700198
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700199 args[0].SetD(DBL_MAX);
200 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700201 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700202 EXPECT_EQ(DBL_MAX, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700203
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700204 args[0].SetD(DBL_MIN);
205 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700206 (*stub)(method, receiver, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700207 EXPECT_EQ(DBL_MIN, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700208 }
209
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700210 void InvokeSumIntIntMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700211 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800212 mirror::AbstractMethod* method;
213 mirror::Object* receiver;
214 mirror::AbstractMethod::InvokeStub* stub =
215 DoCompile(method, receiver, is_static, "sum", "(II)I");
Elliott Hughes77405792012-03-15 15:22:12 -0700216
217 JValue result;
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700218 result.SetI(-1);
Elliott Hughes77405792012-03-15 15:22:12 -0700219 JValue args[2];
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700220 args[0].SetI(0);
221 args[1].SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700222 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700223 EXPECT_EQ(0, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700224
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700225 result.SetI(0);
226 args[0].SetI(1);
227 args[1].SetI(2);
Elliott Hughes77405792012-03-15 15:22:12 -0700228 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700229 EXPECT_EQ(3, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700230
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700231 result.SetI(0);
232 args[0].SetI(-2);
233 args[1].SetI(5);
Elliott Hughes77405792012-03-15 15:22:12 -0700234 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700235 EXPECT_EQ(3, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700236
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700237 result.SetI(1234);
238 args[0].SetI(INT_MAX);
239 args[1].SetI(INT_MIN);
Elliott Hughes77405792012-03-15 15:22:12 -0700240 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700241 EXPECT_EQ(-1, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700242
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700243 result.SetI(INT_MIN);
244 args[0].SetI(INT_MAX);
245 args[1].SetI(INT_MAX);
Elliott Hughes77405792012-03-15 15:22:12 -0700246 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700247 EXPECT_EQ(-2, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700248 }
249
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700250 void InvokeSumIntIntIntMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800252 mirror::AbstractMethod* method;
253 mirror::Object* receiver;
254 mirror::AbstractMethod::InvokeStub* stub =
255 DoCompile(method, receiver, is_static, "sum", "(III)I");
Elliott Hughes77405792012-03-15 15:22:12 -0700256
257 JValue result;
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700258 result.SetI(-1);
Elliott Hughes77405792012-03-15 15:22:12 -0700259 JValue args[3];
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700260 args[0].SetI(0);
261 args[1].SetI(0);
262 args[2].SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700263 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700264 EXPECT_EQ(0, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700265
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700266 result.SetI(0);
267 args[0].SetI(1);
268 args[1].SetI(2);
269 args[2].SetI(3);
Elliott Hughes77405792012-03-15 15:22:12 -0700270 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700271 EXPECT_EQ(6, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700272
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700273 result.SetI(0);
274 args[0].SetI(-1);
275 args[1].SetI(2);
276 args[2].SetI(-3);
Elliott Hughes77405792012-03-15 15:22:12 -0700277 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700278 EXPECT_EQ(-2, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700279
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700280 result.SetI(1234);
281 args[0].SetI(INT_MAX);
282 args[1].SetI(INT_MIN);
283 args[2].SetI(INT_MAX);
Elliott Hughes77405792012-03-15 15:22:12 -0700284 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700285 EXPECT_EQ(2147483646, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700286
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700287 result.SetI(INT_MIN);
288 args[0].SetI(INT_MAX);
289 args[1].SetI(INT_MAX);
290 args[2].SetI(INT_MAX);
Elliott Hughes77405792012-03-15 15:22:12 -0700291 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700292 EXPECT_EQ(2147483645, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700293 }
294
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700295 void InvokeSumIntIntIntIntMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800297 mirror::AbstractMethod* method;
298 mirror::Object* receiver;
299 mirror::AbstractMethod::InvokeStub* stub =
300 DoCompile(method, receiver, is_static, "sum", "(IIII)I");
Elliott Hughes77405792012-03-15 15:22:12 -0700301
302 JValue result;
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700303 result.SetI(-1);
Elliott Hughes77405792012-03-15 15:22:12 -0700304 JValue args[4];
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700305 args[0].SetI(0);
306 args[1].SetI(0);
307 args[2].SetI(0);
308 args[3].SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700309 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700310 EXPECT_EQ(0, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700311
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700312 result.SetI(0);
313 args[0].SetI(1);
314 args[1].SetI(2);
315 args[2].SetI(3);
316 args[3].SetI(4);
Elliott Hughes77405792012-03-15 15:22:12 -0700317 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700318 EXPECT_EQ(10, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700319
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700320 result.SetI(0);
321 args[0].SetI(-1);
322 args[1].SetI(2);
323 args[2].SetI(-3);
324 args[3].SetI(4);
Elliott Hughes77405792012-03-15 15:22:12 -0700325 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700326 EXPECT_EQ(2, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700327
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700328 result.SetI(1234);
329 args[0].SetI(INT_MAX);
330 args[1].SetI(INT_MIN);
331 args[2].SetI(INT_MAX);
332 args[3].SetI(INT_MIN);
Elliott Hughes77405792012-03-15 15:22:12 -0700333 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700334 EXPECT_EQ(-2, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700335
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700336 result.SetI(INT_MIN);
337 args[0].SetI(INT_MAX);
338 args[1].SetI(INT_MAX);
339 args[2].SetI(INT_MAX);
340 args[3].SetI(INT_MAX);
Elliott Hughes77405792012-03-15 15:22:12 -0700341 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700342 EXPECT_EQ(-4, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700343 }
344
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700345 void InvokeSumIntIntIntIntIntMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700346 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800347 mirror::AbstractMethod* method;
348 mirror::Object* receiver;
349 mirror::AbstractMethod::InvokeStub* stub =
350 DoCompile(method, receiver, is_static, "sum", "(IIIII)I");
Elliott Hughes77405792012-03-15 15:22:12 -0700351
352 JValue result;
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700353 result.SetI(-1.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700354 JValue args[5];
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700355 args[0].SetI(0);
356 args[1].SetI(0);
357 args[2].SetI(0);
358 args[3].SetI(0);
359 args[4].SetI(0);
Elliott Hughes77405792012-03-15 15:22:12 -0700360 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700361 EXPECT_EQ(0, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700362
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700363 result.SetI(0);
364 args[0].SetI(1);
365 args[1].SetI(2);
366 args[2].SetI(3);
367 args[3].SetI(4);
368 args[4].SetI(5);
Elliott Hughes77405792012-03-15 15:22:12 -0700369 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700370 EXPECT_EQ(15, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700371
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700372 result.SetI(0);
373 args[0].SetI(-1);
374 args[1].SetI(2);
375 args[2].SetI(-3);
376 args[3].SetI(4);
377 args[4].SetI(-5);
Elliott Hughes77405792012-03-15 15:22:12 -0700378 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700379 EXPECT_EQ(-3, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700380
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700381 result.SetI(1234);
382 args[0].SetI(INT_MAX);
383 args[1].SetI(INT_MIN);
384 args[2].SetI(INT_MAX);
385 args[3].SetI(INT_MIN);
386 args[4].SetI(INT_MAX);
Elliott Hughes77405792012-03-15 15:22:12 -0700387 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700388 EXPECT_EQ(2147483645, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700389
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700390 result.SetI(INT_MIN);
391 args[0].SetI(INT_MAX);
392 args[1].SetI(INT_MAX);
393 args[2].SetI(INT_MAX);
394 args[3].SetI(INT_MAX);
395 args[4].SetI(INT_MAX);
Elliott Hughes77405792012-03-15 15:22:12 -0700396 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700397 EXPECT_EQ(2147483643, result.GetI());
Elliott Hughes77405792012-03-15 15:22:12 -0700398 }
399
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 void InvokeSumDoubleDoubleMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800402 mirror::AbstractMethod* method;
403 mirror::Object* receiver;
404 mirror::AbstractMethod::InvokeStub* stub =
405 DoCompile(method, receiver, is_static, "sum", "(DD)D");
Elliott Hughes77405792012-03-15 15:22:12 -0700406
407 JValue args[2];
408 JValue result;
409
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700410 args[0].SetD(0.0);
411 args[1].SetD(0.0);
412 result.SetD(-1.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700413 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700414 EXPECT_EQ(0.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700415
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700416 args[0].SetD(1.0);
417 args[1].SetD(2.0);
418 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700419 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700420 EXPECT_EQ(3.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700421
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700422 args[0].SetD(1.0);
423 args[1].SetD(-2.0);
424 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700425 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700426 EXPECT_EQ(-1.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700427
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700428 args[0].SetD(DBL_MAX);
429 args[1].SetD(DBL_MIN);
430 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700431 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700432 EXPECT_EQ(1.7976931348623157e308, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700433
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700434 args[0].SetD(DBL_MAX);
435 args[1].SetD(DBL_MAX);
436 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700437 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700438 EXPECT_EQ(INFINITY, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700439 }
440
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700441 void InvokeSumDoubleDoubleDoubleMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700442 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800443 mirror::AbstractMethod* method;
444 mirror::Object* receiver;
445 mirror::AbstractMethod::InvokeStub* stub =
446 DoCompile(method, receiver, is_static, "sum", "(DDD)D");
Elliott Hughes77405792012-03-15 15:22:12 -0700447
448 JValue args[3];
449 JValue result;
450
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700451 args[0].SetD(0.0);
452 args[1].SetD(0.0);
453 args[2].SetD(0.0);
454 result.SetD(-1.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700455 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700456 EXPECT_EQ(0.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700457
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700458 args[0].SetD(1.0);
459 args[1].SetD(2.0);
460 args[2].SetD(3.0);
461 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700462 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700463 EXPECT_EQ(6.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700464
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700465 args[0].SetD(1.0);
466 args[1].SetD(-2.0);
467 args[2].SetD(3.0);
468 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700469 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700470 EXPECT_EQ(2.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700471 }
472
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700473 void InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800475 mirror::AbstractMethod* method;
476 mirror::Object* receiver;
477 mirror::AbstractMethod::InvokeStub* stub =
478 DoCompile(method, receiver, is_static, "sum", "(DDDD)D");
Elliott Hughes77405792012-03-15 15:22:12 -0700479
480 JValue args[4];
481 JValue result;
482
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700483 args[0].SetD(0.0);
484 args[1].SetD(0.0);
485 args[2].SetD(0.0);
486 args[3].SetD(0.0);
487 result.SetD(-1.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700488 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700489 EXPECT_EQ(0.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700490
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700491 args[0].SetD(1.0);
492 args[1].SetD(2.0);
493 args[2].SetD(3.0);
494 args[3].SetD(4.0);
495 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700496 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700497 EXPECT_EQ(10.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700498
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700499 args[0].SetD(1.0);
500 args[1].SetD(-2.0);
501 args[2].SetD(3.0);
502 args[3].SetD(-4.0);
503 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700504 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700505 EXPECT_EQ(-2.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700506 }
507
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700508 void InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700509 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800510 mirror::AbstractMethod* method;
511 mirror::Object* receiver;
512 mirror::AbstractMethod::InvokeStub* stub =
513 DoCompile(method, receiver, is_static, "sum", "(DDDDD)D");
Elliott Hughes77405792012-03-15 15:22:12 -0700514
515 JValue args[5];
516 JValue result;
517
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700518 args[0].SetD(0.0);
519 args[1].SetD(0.0);
520 args[2].SetD(0.0);
521 args[3].SetD(0.0);
522 args[4].SetD(0.0);
523 result.SetD(-1.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700524 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700525 EXPECT_EQ(0.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700526
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700527 args[0].SetD(1.0);
528 args[1].SetD(2.0);
529 args[2].SetD(3.0);
530 args[3].SetD(4.0);
531 args[4].SetD(5.0);
532 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700533 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700534 EXPECT_EQ(15.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700535
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700536 args[0].SetD(1.0);
537 args[1].SetD(-2.0);
538 args[2].SetD(3.0);
539 args[3].SetD(-4.0);
540 args[4].SetD(5.0);
541 result.SetD(0.0);
Elliott Hughes77405792012-03-15 15:22:12 -0700542 (*stub)(method, NULL, Thread::Current(), args, &result);
Elliott Hughesf24d3ce2012-04-11 17:43:37 -0700543 EXPECT_EQ(3.0, result.GetD());
Elliott Hughes77405792012-03-15 15:22:12 -0700544 }
545
Elliott Hughesa2501992011-08-26 19:39:54 -0700546 JavaVMExt* vm_;
Brian Carlstrom4d571432012-05-16 00:21:41 -0700547 JNIEnv* env_;
Elliott Hughes814e4032011-08-23 12:07:56 -0700548 jclass aioobe_;
Elliott Hughesb264f082012-04-06 17:10:10 -0700549 jclass ase_;
Elliott Hughesb465ab02011-08-24 11:21:21 -0700550 jclass sioobe_;
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700551};
552
Elliott Hughes885c3bd2011-08-22 16:59:20 -0700553TEST_F(JniInternalTest, AllocObject) {
554 jclass c = env_->FindClass("java/lang/String");
555 ASSERT_TRUE(c != NULL);
556 jobject o = env_->AllocObject(c);
557 ASSERT_TRUE(o != NULL);
558
559 // We have an instance of the class we asked for...
560 ASSERT_TRUE(env_->IsInstanceOf(o, c));
561 // ...whose fields haven't been initialized because
562 // we didn't call a constructor.
563 ASSERT_EQ(0, env_->GetIntField(o, env_->GetFieldID(c, "count", "I")));
564 ASSERT_EQ(0, env_->GetIntField(o, env_->GetFieldID(c, "offset", "I")));
565 ASSERT_TRUE(env_->GetObjectField(o, env_->GetFieldID(c, "value", "[C")) == NULL);
566}
567
Elliott Hughesc7ac37f2011-08-12 12:21:58 -0700568TEST_F(JniInternalTest, GetVersion) {
569 ASSERT_EQ(JNI_VERSION_1_6, env_->GetVersion());
570}
571
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700572#define EXPECT_CLASS_FOUND(NAME) \
Elliott Hughesbd935992011-08-22 11:59:34 -0700573 EXPECT_TRUE(env_->FindClass(NAME) != NULL); \
574 EXPECT_FALSE(env_->ExceptionCheck())
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700575
576#define EXPECT_CLASS_NOT_FOUND(NAME) \
Elliott Hughesbd935992011-08-22 11:59:34 -0700577 EXPECT_TRUE(env_->FindClass(NAME) == NULL); \
578 EXPECT_TRUE(env_->ExceptionCheck()); \
579 env_->ExceptionClear()
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700580
581TEST_F(JniInternalTest, FindClass) {
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700582 // Reference types...
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700583 EXPECT_CLASS_FOUND("java/lang/String");
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700584 // ...for arrays too, where you must include "L;".
585 EXPECT_CLASS_FOUND("[Ljava/lang/String;");
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700586 // Primitive arrays are okay too, if the primitive type is valid.
587 EXPECT_CLASS_FOUND("[C");
Elliott Hughesa2501992011-08-26 19:39:54 -0700588
Elliott Hughesb264f082012-04-06 17:10:10 -0700589 {
Elliott Hughesb264f082012-04-06 17:10:10 -0700590 // We support . as well as / for compatibility, if -Xcheck:jni is off.
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700591 CheckJniAbortCatcher check_jni_abort_catcher;
Elliott Hughesb264f082012-04-06 17:10:10 -0700592 EXPECT_CLASS_FOUND("java.lang.String");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700593 check_jni_abort_catcher.Check("illegal class name 'java.lang.String'");
Elliott Hughesb264f082012-04-06 17:10:10 -0700594 EXPECT_CLASS_NOT_FOUND("Ljava.lang.String;");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700595 check_jni_abort_catcher.Check("illegal class name 'Ljava.lang.String;'");
Elliott Hughesb264f082012-04-06 17:10:10 -0700596 EXPECT_CLASS_FOUND("[Ljava.lang.String;");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700597 check_jni_abort_catcher.Check("illegal class name '[Ljava.lang.String;'");
Elliott Hughesb264f082012-04-06 17:10:10 -0700598 EXPECT_CLASS_NOT_FOUND("[java.lang.String");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700599 check_jni_abort_catcher.Check("illegal class name '[java.lang.String'");
Elliott Hughesb264f082012-04-06 17:10:10 -0700600
601 // You can't include the "L;" in a JNI class descriptor.
602 EXPECT_CLASS_NOT_FOUND("Ljava/lang/String;");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700603 check_jni_abort_catcher.Check("illegal class name 'Ljava/lang/String;'");
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700604
Elliott Hughesb264f082012-04-06 17:10:10 -0700605 // But you must include it for an array of any reference type.
606 EXPECT_CLASS_NOT_FOUND("[java/lang/String");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700607 check_jni_abort_catcher.Check("illegal class name '[java/lang/String'");
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700608
609 EXPECT_CLASS_NOT_FOUND("[K");
Elliott Hughes56ef0422012-06-19 14:35:04 -0700610 check_jni_abort_catcher.Check("illegal class name '[K'");
Elliott Hughesb264f082012-04-06 17:10:10 -0700611 }
Elliott Hughesa2501992011-08-26 19:39:54 -0700612
Elliott Hughes0c9cd562011-08-12 10:59:29 -0700613 // But primitive types aren't allowed...
614 EXPECT_CLASS_NOT_FOUND("C");
615 EXPECT_CLASS_NOT_FOUND("K");
616}
617
Elliott Hughescdf53122011-08-19 15:46:09 -0700618#define EXPECT_EXCEPTION(exception_class) \
619 do { \
620 EXPECT_TRUE(env_->ExceptionCheck()); \
621 jthrowable exception = env_->ExceptionOccurred(); \
622 EXPECT_NE(static_cast<jthrowable>(NULL), exception); \
Elliott Hughescdf53122011-08-19 15:46:09 -0700623 env_->ExceptionClear(); \
Elliott Hughesa2501992011-08-26 19:39:54 -0700624 EXPECT_TRUE(env_->IsInstanceOf(exception, exception_class)); \
Elliott Hughescdf53122011-08-19 15:46:09 -0700625 } while (false)
626
627TEST_F(JniInternalTest, GetFieldID) {
628 jclass jlnsfe = env_->FindClass("java/lang/NoSuchFieldError");
629 ASSERT_TRUE(jlnsfe != NULL);
630 jclass c = env_->FindClass("java/lang/String");
631 ASSERT_TRUE(c != NULL);
632
633 // Wrong type.
634 jfieldID fid = env_->GetFieldID(c, "count", "J");
635 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
636 EXPECT_EXCEPTION(jlnsfe);
637
Ian Rogersb17d08b2011-09-02 16:16:49 -0700638 // Wrong type where type doesn't exist.
639 fid = env_->GetFieldID(c, "count", "Lrod/jane/freddy;");
640 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
641 EXPECT_EXCEPTION(jlnsfe);
642
Elliott Hughescdf53122011-08-19 15:46:09 -0700643 // Wrong name.
644 fid = env_->GetFieldID(c, "Count", "I");
645 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
646 EXPECT_EXCEPTION(jlnsfe);
647
648 // Good declared field lookup.
649 fid = env_->GetFieldID(c, "count", "I");
650 EXPECT_NE(static_cast<jfieldID>(NULL), fid);
651 EXPECT_TRUE(fid != NULL);
652 EXPECT_FALSE(env_->ExceptionCheck());
653
654 // Good superclass field lookup.
655 c = env_->FindClass("java/lang/StringBuilder");
656 fid = env_->GetFieldID(c, "count", "I");
657 EXPECT_NE(static_cast<jfieldID>(NULL), fid);
658 EXPECT_TRUE(fid != NULL);
659 EXPECT_FALSE(env_->ExceptionCheck());
660
661 // Not instance.
662 fid = env_->GetFieldID(c, "CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
663 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
664 EXPECT_EXCEPTION(jlnsfe);
665}
666
667TEST_F(JniInternalTest, GetStaticFieldID) {
668 jclass jlnsfe = env_->FindClass("java/lang/NoSuchFieldError");
669 ASSERT_TRUE(jlnsfe != NULL);
670 jclass c = env_->FindClass("java/lang/String");
671 ASSERT_TRUE(c != NULL);
672
673 // Wrong type.
674 jfieldID fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", "J");
675 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
676 EXPECT_EXCEPTION(jlnsfe);
677
Ian Rogersb17d08b2011-09-02 16:16:49 -0700678 // Wrong type where type doesn't exist.
679 fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", "Lrod/jane/freddy;");
680 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
681 EXPECT_EXCEPTION(jlnsfe);
682
Elliott Hughescdf53122011-08-19 15:46:09 -0700683 // Wrong name.
684 fid = env_->GetStaticFieldID(c, "cASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
685 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
686 EXPECT_EXCEPTION(jlnsfe);
687
688 // Good declared field lookup.
689 fid = env_->GetStaticFieldID(c, "CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;");
690 EXPECT_NE(static_cast<jfieldID>(NULL), fid);
691 EXPECT_TRUE(fid != NULL);
692 EXPECT_FALSE(env_->ExceptionCheck());
693
694 // Not static.
695 fid = env_->GetStaticFieldID(c, "count", "I");
696 EXPECT_EQ(static_cast<jfieldID>(NULL), fid);
697 EXPECT_EXCEPTION(jlnsfe);
698}
699
Ian Rogers4dd71f12011-08-16 14:16:02 -0700700TEST_F(JniInternalTest, GetMethodID) {
701 jclass jlobject = env_->FindClass("java/lang/Object");
702 jclass jlstring = env_->FindClass("java/lang/String");
703 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
704
705 // Sanity check that no exceptions are pending
Elliott Hughescdf53122011-08-19 15:46:09 -0700706 ASSERT_FALSE(env_->ExceptionCheck());
Ian Rogers4dd71f12011-08-16 14:16:02 -0700707
708 // Check that java.lang.Object.foo() doesn't exist and NoSuchMethodError is
709 // a pending exception
710 jmethodID method = env_->GetMethodID(jlobject, "foo", "()V");
711 EXPECT_EQ(static_cast<jmethodID>(NULL), method);
Elliott Hughescdf53122011-08-19 15:46:09 -0700712 EXPECT_EXCEPTION(jlnsme);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700713
714 // Check that java.lang.Object.equals() does exist
Ian Rogers4dd71f12011-08-16 14:16:02 -0700715 method = env_->GetMethodID(jlobject, "equals", "(Ljava/lang/Object;)Z");
716 EXPECT_NE(static_cast<jmethodID>(NULL), method);
717 EXPECT_FALSE(env_->ExceptionCheck());
Ian Rogers4dd71f12011-08-16 14:16:02 -0700718
719 // Check that GetMethodID for java.lang.String.valueOf(int) fails as the
720 // method is static
721 method = env_->GetMethodID(jlstring, "valueOf", "(I)Ljava/lang/String;");
722 EXPECT_EQ(static_cast<jmethodID>(NULL), method);
Elliott Hughescdf53122011-08-19 15:46:09 -0700723 EXPECT_EXCEPTION(jlnsme);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700724}
725
726TEST_F(JniInternalTest, GetStaticMethodID) {
727 jclass jlobject = env_->FindClass("java/lang/Object");
728 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
729
730 // Sanity check that no exceptions are pending
Elliott Hughescdf53122011-08-19 15:46:09 -0700731 ASSERT_FALSE(env_->ExceptionCheck());
Ian Rogers4dd71f12011-08-16 14:16:02 -0700732
733 // Check that java.lang.Object.foo() doesn't exist and NoSuchMethodError is
734 // a pending exception
735 jmethodID method = env_->GetStaticMethodID(jlobject, "foo", "()V");
736 EXPECT_EQ(static_cast<jmethodID>(NULL), method);
Elliott Hughescdf53122011-08-19 15:46:09 -0700737 EXPECT_EXCEPTION(jlnsme);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700738
739 // Check that GetStaticMethodID for java.lang.Object.equals(Object) fails as
740 // the method is not static
741 method = env_->GetStaticMethodID(jlobject, "equals", "(Ljava/lang/Object;)Z");
742 EXPECT_EQ(static_cast<jmethodID>(NULL), method);
Elliott Hughescdf53122011-08-19 15:46:09 -0700743 EXPECT_EXCEPTION(jlnsme);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700744
745 // Check that java.lang.String.valueOf(int) does exist
Ian Rogers4dd71f12011-08-16 14:16:02 -0700746 jclass jlstring = env_->FindClass("java/lang/String");
747 method = env_->GetStaticMethodID(jlstring, "valueOf",
748 "(I)Ljava/lang/String;");
749 EXPECT_NE(static_cast<jmethodID>(NULL), method);
750 EXPECT_FALSE(env_->ExceptionCheck());
Ian Rogers4dd71f12011-08-16 14:16:02 -0700751}
752
Elliott Hughescdf53122011-08-19 15:46:09 -0700753TEST_F(JniInternalTest, FromReflectedField_ToReflectedField) {
754 jclass jlrField = env_->FindClass("java/lang/reflect/Field");
755 jclass c = env_->FindClass("java/lang/String");
756 ASSERT_TRUE(c != NULL);
757 jfieldID fid = env_->GetFieldID(c, "count", "I");
758 ASSERT_TRUE(fid != NULL);
759 // Turn the fid into a java.lang.reflect.Field...
760 jobject field = env_->ToReflectedField(c, fid, JNI_FALSE);
761 ASSERT_TRUE(c != NULL);
762 ASSERT_TRUE(env_->IsInstanceOf(field, jlrField));
763 // ...and back again.
764 jfieldID fid2 = env_->FromReflectedField(field);
765 ASSERT_TRUE(fid2 != NULL);
766}
767
768TEST_F(JniInternalTest, FromReflectedMethod_ToReflectedMethod) {
769 jclass jlrMethod = env_->FindClass("java/lang/reflect/Method");
770 jclass c = env_->FindClass("java/lang/String");
771 ASSERT_TRUE(c != NULL);
772 jmethodID mid = env_->GetMethodID(c, "length", "()I");
773 ASSERT_TRUE(mid != NULL);
774 // Turn the mid into a java.lang.reflect.Method...
775 jobject method = env_->ToReflectedMethod(c, mid, JNI_FALSE);
776 ASSERT_TRUE(c != NULL);
777 ASSERT_TRUE(env_->IsInstanceOf(method, jlrMethod));
778 // ...and back again.
779 jmethodID mid2 = env_->FromReflectedMethod(method);
780 ASSERT_TRUE(mid2 != NULL);
781}
782
Elliott Hughes5174fe62011-08-23 15:12:35 -0700783void BogusMethod() {
784 // You can't pass NULL function pointers to RegisterNatives.
785}
786
Ian Rogers4dd71f12011-08-16 14:16:02 -0700787TEST_F(JniInternalTest, RegisterNatives) {
788 jclass jlobject = env_->FindClass("java/lang/Object");
789 jclass jlnsme = env_->FindClass("java/lang/NoSuchMethodError");
790
791 // Sanity check that no exceptions are pending
Elliott Hughescdf53122011-08-19 15:46:09 -0700792 ASSERT_FALSE(env_->ExceptionCheck());
Ian Rogers4dd71f12011-08-16 14:16:02 -0700793
794 // Check that registering to a non-existent java.lang.Object.foo() causes a
795 // NoSuchMethodError
796 {
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700797 JNINativeMethod methods[] = { { "foo", "()V", NULL } };
Ian Rogers4dd71f12011-08-16 14:16:02 -0700798 env_->RegisterNatives(jlobject, methods, 1);
799 }
Elliott Hughescdf53122011-08-19 15:46:09 -0700800 EXPECT_EXCEPTION(jlnsme);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700801
802 // Check that registering non-native methods causes a NoSuchMethodError
803 {
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700804 JNINativeMethod methods[] = { { "equals", "(Ljava/lang/Object;)Z", NULL } };
Ian Rogers4dd71f12011-08-16 14:16:02 -0700805 env_->RegisterNatives(jlobject, methods, 1);
806 }
Elliott Hughescdf53122011-08-19 15:46:09 -0700807 EXPECT_EXCEPTION(jlnsme);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700808
809 // Check that registering native methods is successful
810 {
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700811 JNINativeMethod methods[] = { { "notify", "()V", reinterpret_cast<void*>(BogusMethod) } };
Ian Rogers4dd71f12011-08-16 14:16:02 -0700812 env_->RegisterNatives(jlobject, methods, 1);
813 }
814 EXPECT_FALSE(env_->ExceptionCheck());
Elliott Hughes5174fe62011-08-23 15:12:35 -0700815
816 env_->UnregisterNatives(jlobject);
Ian Rogers4dd71f12011-08-16 14:16:02 -0700817}
818
Elliott Hughes75770752011-08-24 17:52:38 -0700819#define EXPECT_PRIMITIVE_ARRAY(new_fn, get_region_fn, set_region_fn, get_elements_fn, release_elements_fn, scalar_type, expected_class_descriptor) \
Elliott Hughes814e4032011-08-23 12:07:56 -0700820 jsize size = 4; \
821 /* Allocate an array and check it has the right type and length. */ \
822 scalar_type ## Array a = env_->new_fn(size); \
823 EXPECT_TRUE(a != NULL); \
824 EXPECT_TRUE(env_->IsInstanceOf(a, env_->FindClass(expected_class_descriptor))); \
825 EXPECT_EQ(size, env_->GetArrayLength(a)); \
826 /* AIOOBE for negative start offset. */ \
827 env_->get_region_fn(a, -1, 1, NULL); \
828 EXPECT_EXCEPTION(aioobe_); \
829 env_->set_region_fn(a, -1, 1, NULL); \
830 EXPECT_EXCEPTION(aioobe_); \
831 /* AIOOBE for negative length. */ \
832 env_->get_region_fn(a, 0, -1, NULL); \
833 EXPECT_EXCEPTION(aioobe_); \
834 env_->set_region_fn(a, 0, -1, NULL); \
835 EXPECT_EXCEPTION(aioobe_); \
836 /* AIOOBE for buffer overrun. */ \
837 env_->get_region_fn(a, size - 1, size, NULL); \
838 EXPECT_EXCEPTION(aioobe_); \
839 env_->set_region_fn(a, size - 1, size, NULL); \
840 EXPECT_EXCEPTION(aioobe_); \
841 /* Prepare a couple of buffers. */ \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700842 UniquePtr<scalar_type[]> src_buf(new scalar_type[size]); \
843 UniquePtr<scalar_type[]> dst_buf(new scalar_type[size]); \
Elliott Hughes814e4032011-08-23 12:07:56 -0700844 for (jsize i = 0; i < size; ++i) { src_buf[i] = scalar_type(i); } \
845 for (jsize i = 0; i < size; ++i) { dst_buf[i] = scalar_type(-1); } \
846 /* Copy all of src_buf onto the heap. */ \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700847 env_->set_region_fn(a, 0, size, &src_buf[0]); \
Elliott Hughes814e4032011-08-23 12:07:56 -0700848 /* Copy back only part. */ \
849 env_->get_region_fn(a, 1, size - 2, &dst_buf[1]); \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700850 EXPECT_NE(memcmp(&src_buf[0], &dst_buf[0], size * sizeof(scalar_type)), 0) << "short copy equal"; \
Elliott Hughes814e4032011-08-23 12:07:56 -0700851 /* Copy the missing pieces. */ \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700852 env_->get_region_fn(a, 0, 1, &dst_buf[0]); \
Elliott Hughes814e4032011-08-23 12:07:56 -0700853 env_->get_region_fn(a, size - 1, 1, &dst_buf[size - 1]); \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700854 EXPECT_EQ(memcmp(&src_buf[0], &dst_buf[0], size * sizeof(scalar_type)), 0) << "fixed copy not equal"; \
Elliott Hughes814e4032011-08-23 12:07:56 -0700855 /* Copy back the whole array. */ \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700856 env_->get_region_fn(a, 0, size, &dst_buf[0]); \
857 EXPECT_EQ(memcmp(&src_buf[0], &dst_buf[0], size * sizeof(scalar_type)), 0) << "full copy not equal"; \
Elliott Hughes75770752011-08-24 17:52:38 -0700858 /* GetPrimitiveArrayCritical */ \
859 void* v = env_->GetPrimitiveArrayCritical(a, NULL); \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700860 EXPECT_EQ(memcmp(&src_buf[0], v, size * sizeof(scalar_type)), 0) << "GetPrimitiveArrayCritical not equal"; \
Elliott Hughes75770752011-08-24 17:52:38 -0700861 env_->ReleasePrimitiveArrayCritical(a, v, 0); \
862 /* GetXArrayElements */ \
863 scalar_type* xs = env_->get_elements_fn(a, NULL); \
Elliott Hughesee0fa762012-03-26 17:12:41 -0700864 EXPECT_EQ(memcmp(&src_buf[0], xs, size * sizeof(scalar_type)), 0) << # get_elements_fn " not equal"; \
Elliott Hughes75770752011-08-24 17:52:38 -0700865 env_->release_elements_fn(a, xs, 0); \
866 EXPECT_EQ(reinterpret_cast<uintptr_t>(v), reinterpret_cast<uintptr_t>(xs))
Elliott Hughesbd935992011-08-22 11:59:34 -0700867
Elliott Hughes814e4032011-08-23 12:07:56 -0700868TEST_F(JniInternalTest, BooleanArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700869 EXPECT_PRIMITIVE_ARRAY(NewBooleanArray, GetBooleanArrayRegion, SetBooleanArrayRegion, GetBooleanArrayElements, ReleaseBooleanArrayElements, jboolean, "[Z");
Elliott Hughes814e4032011-08-23 12:07:56 -0700870}
871TEST_F(JniInternalTest, ByteArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700872 EXPECT_PRIMITIVE_ARRAY(NewByteArray, GetByteArrayRegion, SetByteArrayRegion, GetByteArrayElements, ReleaseByteArrayElements, jbyte, "[B");
Elliott Hughes814e4032011-08-23 12:07:56 -0700873}
874TEST_F(JniInternalTest, CharArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700875 EXPECT_PRIMITIVE_ARRAY(NewCharArray, GetCharArrayRegion, SetCharArrayRegion, GetCharArrayElements, ReleaseCharArrayElements, jchar, "[C");
Elliott Hughes814e4032011-08-23 12:07:56 -0700876}
877TEST_F(JniInternalTest, DoubleArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700878 EXPECT_PRIMITIVE_ARRAY(NewDoubleArray, GetDoubleArrayRegion, SetDoubleArrayRegion, GetDoubleArrayElements, ReleaseDoubleArrayElements, jdouble, "[D");
Elliott Hughes814e4032011-08-23 12:07:56 -0700879}
880TEST_F(JniInternalTest, FloatArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700881 EXPECT_PRIMITIVE_ARRAY(NewFloatArray, GetFloatArrayRegion, SetFloatArrayRegion, GetFloatArrayElements, ReleaseFloatArrayElements, jfloat, "[F");
Elliott Hughes814e4032011-08-23 12:07:56 -0700882}
883TEST_F(JniInternalTest, IntArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700884 EXPECT_PRIMITIVE_ARRAY(NewIntArray, GetIntArrayRegion, SetIntArrayRegion, GetIntArrayElements, ReleaseIntArrayElements, jint, "[I");
Elliott Hughes814e4032011-08-23 12:07:56 -0700885}
886TEST_F(JniInternalTest, LongArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700887 EXPECT_PRIMITIVE_ARRAY(NewLongArray, GetLongArrayRegion, SetLongArrayRegion, GetLongArrayElements, ReleaseLongArrayElements, jlong, "[J");
Elliott Hughes814e4032011-08-23 12:07:56 -0700888}
889TEST_F(JniInternalTest, ShortArrays) {
Elliott Hughes75770752011-08-24 17:52:38 -0700890 EXPECT_PRIMITIVE_ARRAY(NewShortArray, GetShortArrayRegion, SetShortArrayRegion, GetShortArrayElements, ReleaseShortArrayElements, jshort, "[S");
Elliott Hughesd8ddfd52011-08-15 14:32:53 -0700891}
892
Elliott Hughesf2682d52011-08-15 16:37:04 -0700893TEST_F(JniInternalTest, NewObjectArray) {
894 // TODO: death tests for negative array sizes.
895
Elliott Hughesf2682d52011-08-15 16:37:04 -0700896 // TODO: check non-NULL initial elements.
897
Elliott Hughesbd935992011-08-22 11:59:34 -0700898 jclass element_class = env_->FindClass("java/lang/String");
899 ASSERT_TRUE(element_class != NULL);
900 jclass array_class = env_->FindClass("[Ljava/lang/String;");
901 ASSERT_TRUE(array_class != NULL);
Elliott Hughesf2682d52011-08-15 16:37:04 -0700902
Elliott Hughesbd935992011-08-22 11:59:34 -0700903 jobjectArray a;
Elliott Hughesf2682d52011-08-15 16:37:04 -0700904
Elliott Hughesbd935992011-08-22 11:59:34 -0700905 a = env_->NewObjectArray(0, element_class, NULL);
906 EXPECT_TRUE(a != NULL);
907 EXPECT_TRUE(env_->IsInstanceOf(a, array_class));
908 EXPECT_EQ(0, env_->GetArrayLength(a));
909
910 a = env_->NewObjectArray(1, element_class, NULL);
911 EXPECT_TRUE(a != NULL);
912 EXPECT_TRUE(env_->IsInstanceOf(a, array_class));
913 EXPECT_EQ(1, env_->GetArrayLength(a));
Elliott Hughes75770752011-08-24 17:52:38 -0700914 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(a, 0), NULL));
915
916 jstring s = env_->NewStringUTF("poop");
917 a = env_->NewObjectArray(2, element_class, s);
918 EXPECT_TRUE(a != NULL);
919 EXPECT_TRUE(env_->IsInstanceOf(a, array_class));
920 EXPECT_EQ(2, env_->GetArrayLength(a));
921 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(a, 0), s));
922 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(a, 1), s));
Elliott Hughesbd935992011-08-22 11:59:34 -0700923}
924
925TEST_F(JniInternalTest, GetArrayLength) {
926 // Already tested in NewObjectArray/NewPrimitiveArray.
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700927}
928
Elliott Hughes37f7a402011-08-22 18:56:01 -0700929TEST_F(JniInternalTest, GetObjectClass) {
930 jclass string_class = env_->FindClass("java/lang/String");
931 ASSERT_TRUE(string_class != NULL);
932 jclass class_class = env_->FindClass("java/lang/Class");
933 ASSERT_TRUE(class_class != NULL);
934
935 jstring s = env_->NewStringUTF("poop");
936 jclass c = env_->GetObjectClass(s);
937 ASSERT_TRUE(env_->IsSameObject(string_class, c));
938
939 jclass c2 = env_->GetObjectClass(c);
940 ASSERT_TRUE(env_->IsSameObject(class_class, env_->GetObjectClass(c2)));
941}
942
Elliott Hughes885c3bd2011-08-22 16:59:20 -0700943TEST_F(JniInternalTest, GetSuperclass) {
944 jclass object_class = env_->FindClass("java/lang/Object");
945 ASSERT_TRUE(object_class != NULL);
946 jclass string_class = env_->FindClass("java/lang/String");
947 ASSERT_TRUE(string_class != NULL);
Ian Rogersdc180202012-01-29 14:47:29 -0800948 jclass runnable_interface = env_->FindClass("java/lang/Runnable");
949 ASSERT_TRUE(runnable_interface != NULL);
Elliott Hughes885c3bd2011-08-22 16:59:20 -0700950 ASSERT_TRUE(env_->IsSameObject(object_class, env_->GetSuperclass(string_class)));
951 ASSERT_TRUE(env_->GetSuperclass(object_class) == NULL);
Ian Rogersdc180202012-01-29 14:47:29 -0800952 ASSERT_TRUE(env_->IsSameObject(object_class, env_->GetSuperclass(runnable_interface)));
Elliott Hughes885c3bd2011-08-22 16:59:20 -0700953}
954
Elliott Hughes37f7a402011-08-22 18:56:01 -0700955TEST_F(JniInternalTest, IsAssignableFrom) {
956 jclass object_class = env_->FindClass("java/lang/Object");
957 ASSERT_TRUE(object_class != NULL);
958 jclass string_class = env_->FindClass("java/lang/String");
959 ASSERT_TRUE(string_class != NULL);
960
961 ASSERT_TRUE(env_->IsAssignableFrom(object_class, string_class));
962 ASSERT_FALSE(env_->IsAssignableFrom(string_class, object_class));
963}
964
Elliott Hughesb465ab02011-08-24 11:21:21 -0700965TEST_F(JniInternalTest, GetObjectRefType) {
966 jclass local = env_->FindClass("java/lang/Object");
967 ASSERT_TRUE(local != NULL);
968 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(local));
969
970 jobject global = env_->NewGlobalRef(local);
971 EXPECT_EQ(JNIGlobalRefType, env_->GetObjectRefType(global));
972
973 jweak weak_global = env_->NewWeakGlobalRef(local);
974 EXPECT_EQ(JNIWeakGlobalRefType, env_->GetObjectRefType(weak_global));
975
976 jobject invalid = reinterpret_cast<jobject>(this);
977 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(invalid));
978
979 // TODO: invoke a native method and test that its arguments are considered local references.
980}
981
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700982TEST_F(JniInternalTest, NewStringUTF) {
983 EXPECT_TRUE(env_->NewStringUTF(NULL) == NULL);
Elliott Hughes814e4032011-08-23 12:07:56 -0700984 jstring s;
985
986 s = env_->NewStringUTF("");
987 EXPECT_TRUE(s != NULL);
988 EXPECT_EQ(0, env_->GetStringLength(s));
989 EXPECT_EQ(0, env_->GetStringUTFLength(s));
990 s = env_->NewStringUTF("hello");
991 EXPECT_TRUE(s != NULL);
992 EXPECT_EQ(5, env_->GetStringLength(s));
993 EXPECT_EQ(5, env_->GetStringUTFLength(s));
994
Elliott Hughes8a26c5c2011-08-15 18:35:43 -0700995 // TODO: check some non-ASCII strings.
Elliott Hughesf2682d52011-08-15 16:37:04 -0700996}
997
Elliott Hughes814e4032011-08-23 12:07:56 -0700998TEST_F(JniInternalTest, NewString) {
Elliott Hughes814e4032011-08-23 12:07:56 -0700999 jchar chars[] = { 'h', 'i' };
1000 jstring s;
1001 s = env_->NewString(chars, 0);
1002 EXPECT_TRUE(s != NULL);
1003 EXPECT_EQ(0, env_->GetStringLength(s));
1004 EXPECT_EQ(0, env_->GetStringUTFLength(s));
1005 s = env_->NewString(chars, 2);
1006 EXPECT_TRUE(s != NULL);
1007 EXPECT_EQ(2, env_->GetStringLength(s));
1008 EXPECT_EQ(2, env_->GetStringUTFLength(s));
1009
1010 // TODO: check some non-ASCII strings.
1011}
1012
Jesse Wilson25e79a52011-11-18 15:31:58 -05001013TEST_F(JniInternalTest, NewStringNullCharsZeroLength) {
1014 jstring s = env_->NewString(NULL, 0);
1015 EXPECT_TRUE(s != NULL);
1016 EXPECT_EQ(0, env_->GetStringLength(s));
1017}
1018
Brian Carlstrom36258122011-12-09 12:55:51 -08001019// TODO: fix gtest death tests on host http://b/5690440 (and target)
1020TEST_F(JniInternalTest, DISABLED_NewStringNullCharsNonzeroLength) {
Jesse Wilson25e79a52011-11-18 15:31:58 -05001021 ASSERT_DEATH(env_->NewString(NULL, 1), "");
1022}
1023
Elliott Hughesb465ab02011-08-24 11:21:21 -07001024TEST_F(JniInternalTest, GetStringLength_GetStringUTFLength) {
1025 // Already tested in the NewString/NewStringUTF tests.
1026}
1027
1028TEST_F(JniInternalTest, GetStringRegion_GetStringUTFRegion) {
1029 jstring s = env_->NewStringUTF("hello");
1030 ASSERT_TRUE(s != NULL);
1031
1032 env_->GetStringRegion(s, -1, 0, NULL);
1033 EXPECT_EXCEPTION(sioobe_);
1034 env_->GetStringRegion(s, 0, -1, NULL);
1035 EXPECT_EXCEPTION(sioobe_);
1036 env_->GetStringRegion(s, 0, 10, NULL);
1037 EXPECT_EXCEPTION(sioobe_);
1038 env_->GetStringRegion(s, 10, 1, NULL);
1039 EXPECT_EXCEPTION(sioobe_);
1040
1041 jchar chars[4] = { 'x', 'x', 'x', 'x' };
1042 env_->GetStringRegion(s, 1, 2, &chars[1]);
1043 EXPECT_EQ('x', chars[0]);
1044 EXPECT_EQ('e', chars[1]);
1045 EXPECT_EQ('l', chars[2]);
1046 EXPECT_EQ('x', chars[3]);
1047
1048 env_->GetStringUTFRegion(s, -1, 0, NULL);
1049 EXPECT_EXCEPTION(sioobe_);
1050 env_->GetStringUTFRegion(s, 0, -1, NULL);
1051 EXPECT_EXCEPTION(sioobe_);
1052 env_->GetStringUTFRegion(s, 0, 10, NULL);
1053 EXPECT_EXCEPTION(sioobe_);
1054 env_->GetStringUTFRegion(s, 10, 1, NULL);
1055 EXPECT_EXCEPTION(sioobe_);
1056
1057 char bytes[4] = { 'x', 'x', 'x', 'x' };
1058 env_->GetStringUTFRegion(s, 1, 2, &bytes[1]);
1059 EXPECT_EQ('x', bytes[0]);
1060 EXPECT_EQ('e', bytes[1]);
1061 EXPECT_EQ('l', bytes[2]);
1062 EXPECT_EQ('x', bytes[3]);
1063}
1064
Elliott Hughes75770752011-08-24 17:52:38 -07001065TEST_F(JniInternalTest, GetStringUTFChars_ReleaseStringUTFChars) {
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001066 // Passing in a NULL jstring is ignored normally, but caught by -Xcheck:jni.
Elliott Hughesb264f082012-04-06 17:10:10 -07001067 {
Elliott Hughesb264f082012-04-06 17:10:10 -07001068 CheckJniAbortCatcher check_jni_abort_catcher;
1069 EXPECT_TRUE(env_->GetStringUTFChars(NULL, NULL) == NULL);
Elliott Hughes56ef0422012-06-19 14:35:04 -07001070 check_jni_abort_catcher.Check("GetStringUTFChars received null jstring");
Elliott Hughesb264f082012-04-06 17:10:10 -07001071 }
Elliott Hughes75770752011-08-24 17:52:38 -07001072
1073 jstring s = env_->NewStringUTF("hello");
1074 ASSERT_TRUE(s != NULL);
1075
1076 const char* utf = env_->GetStringUTFChars(s, NULL);
1077 EXPECT_STREQ("hello", utf);
1078 env_->ReleaseStringUTFChars(s, utf);
1079
1080 jboolean is_copy = JNI_FALSE;
1081 utf = env_->GetStringUTFChars(s, &is_copy);
1082 EXPECT_EQ(JNI_TRUE, is_copy);
1083 EXPECT_STREQ("hello", utf);
1084 env_->ReleaseStringUTFChars(s, utf);
1085}
1086
1087TEST_F(JniInternalTest, GetStringChars_ReleaseStringChars) {
1088 jstring s = env_->NewStringUTF("hello");
1089 ASSERT_TRUE(s != NULL);
1090
1091 jchar expected[] = { 'h', 'e', 'l', 'l', 'o' };
1092 const jchar* chars = env_->GetStringChars(s, NULL);
1093 EXPECT_EQ(expected[0], chars[0]);
1094 EXPECT_EQ(expected[1], chars[1]);
1095 EXPECT_EQ(expected[2], chars[2]);
1096 EXPECT_EQ(expected[3], chars[3]);
1097 EXPECT_EQ(expected[4], chars[4]);
1098 env_->ReleaseStringChars(s, chars);
1099
1100 jboolean is_copy = JNI_FALSE;
1101 chars = env_->GetStringChars(s, &is_copy);
1102 EXPECT_EQ(JNI_FALSE, is_copy);
1103 EXPECT_EQ(expected[0], chars[0]);
1104 EXPECT_EQ(expected[1], chars[1]);
1105 EXPECT_EQ(expected[2], chars[2]);
1106 EXPECT_EQ(expected[3], chars[3]);
1107 EXPECT_EQ(expected[4], chars[4]);
1108 env_->ReleaseStringChars(s, chars);
1109}
1110
1111TEST_F(JniInternalTest, GetStringCritical_ReleaseStringCritical) {
1112 jstring s = env_->NewStringUTF("hello");
1113 ASSERT_TRUE(s != NULL);
1114
1115 jchar expected[] = { 'h', 'e', 'l', 'l', 'o' };
1116 const jchar* chars = env_->GetStringCritical(s, NULL);
1117 EXPECT_EQ(expected[0], chars[0]);
1118 EXPECT_EQ(expected[1], chars[1]);
1119 EXPECT_EQ(expected[2], chars[2]);
1120 EXPECT_EQ(expected[3], chars[3]);
1121 EXPECT_EQ(expected[4], chars[4]);
1122 env_->ReleaseStringCritical(s, chars);
1123
1124 jboolean is_copy = JNI_FALSE;
1125 chars = env_->GetStringCritical(s, &is_copy);
1126 EXPECT_EQ(JNI_FALSE, is_copy);
1127 EXPECT_EQ(expected[0], chars[0]);
1128 EXPECT_EQ(expected[1], chars[1]);
1129 EXPECT_EQ(expected[2], chars[2]);
1130 EXPECT_EQ(expected[3], chars[3]);
1131 EXPECT_EQ(expected[4], chars[4]);
1132 env_->ReleaseStringCritical(s, chars);
1133}
1134
Elliott Hughes814e4032011-08-23 12:07:56 -07001135TEST_F(JniInternalTest, GetObjectArrayElement_SetObjectArrayElement) {
Elliott Hughesb264f082012-04-06 17:10:10 -07001136 jclass java_lang_Class = env_->FindClass("java/lang/Class");
1137 ASSERT_TRUE(java_lang_Class != NULL);
Elliott Hughes289da822011-08-16 10:11:20 -07001138
Elliott Hughesb264f082012-04-06 17:10:10 -07001139 jobjectArray array = env_->NewObjectArray(1, java_lang_Class, NULL);
Elliott Hughes289da822011-08-16 10:11:20 -07001140 EXPECT_TRUE(array != NULL);
Elliott Hughes814e4032011-08-23 12:07:56 -07001141 EXPECT_TRUE(env_->GetObjectArrayElement(array, 0) == NULL);
Elliott Hughesb264f082012-04-06 17:10:10 -07001142 env_->SetObjectArrayElement(array, 0, java_lang_Class);
1143 EXPECT_TRUE(env_->IsSameObject(env_->GetObjectArrayElement(array, 0), java_lang_Class));
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001144
1145 // ArrayIndexOutOfBounds for negative index.
Elliott Hughesb264f082012-04-06 17:10:10 -07001146 env_->SetObjectArrayElement(array, -1, java_lang_Class);
Elliott Hughes814e4032011-08-23 12:07:56 -07001147 EXPECT_EXCEPTION(aioobe_);
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001148
1149 // ArrayIndexOutOfBounds for too-large index.
Elliott Hughesb264f082012-04-06 17:10:10 -07001150 env_->SetObjectArrayElement(array, 1, java_lang_Class);
Elliott Hughes814e4032011-08-23 12:07:56 -07001151 EXPECT_EXCEPTION(aioobe_);
Elliott Hughesa5b897e2011-08-16 11:33:06 -07001152
Elliott Hughesb264f082012-04-06 17:10:10 -07001153 // ArrayStoreException thrown for bad types.
1154 env_->SetObjectArrayElement(array, 0, env_->NewStringUTF("not a jclass!"));
1155 EXPECT_EXCEPTION(ase_);
Elliott Hughes289da822011-08-16 10:11:20 -07001156}
1157
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001158#define EXPECT_STATIC_PRIMITIVE_FIELD(type, field_name, sig, value1, value2) \
1159 do { \
1160 jfieldID fid = env_->GetStaticFieldID(c, field_name, sig); \
1161 EXPECT_TRUE(fid != NULL); \
1162 env_->SetStatic ## type ## Field(c, fid, value1); \
Brian Carlstrom2e3d1b22012-01-09 18:01:56 -08001163 EXPECT_TRUE(value1 == env_->GetStatic ## type ## Field(c, fid)); \
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001164 env_->SetStatic ## type ## Field(c, fid, value2); \
Brian Carlstrom2e3d1b22012-01-09 18:01:56 -08001165 EXPECT_TRUE(value2 == env_->GetStatic ## type ## Field(c, fid)); \
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001166 } while (false)
1167
1168#define EXPECT_PRIMITIVE_FIELD(instance, type, field_name, sig, value1, value2) \
1169 do { \
1170 jfieldID fid = env_->GetFieldID(c, field_name, sig); \
1171 EXPECT_TRUE(fid != NULL); \
1172 env_->Set ## type ## Field(instance, fid, value1); \
Brian Carlstrom2e3d1b22012-01-09 18:01:56 -08001173 EXPECT_TRUE(value1 == env_->Get ## type ## Field(instance, fid)); \
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001174 env_->Set ## type ## Field(instance, fid, value2); \
Brian Carlstrom2e3d1b22012-01-09 18:01:56 -08001175 EXPECT_TRUE(value2 == env_->Get ## type ## Field(instance, fid)); \
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001176 } while (false)
1177
1178
Ian Rogersc928de92013-02-27 14:30:44 -08001179#if !defined(ART_USE_PORTABLE_COMPILER)
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001180TEST_F(JniInternalTest, GetPrimitiveField_SetPrimitiveField) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001181 Thread::Current()->TransitionFromSuspendedToRunnable();
1182 LoadDex("AllFields");
Brian Carlstrombd86bcc2013-03-10 20:26:16 -07001183 bool started = runtime_->Start();
1184 CHECK(started);
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001185
1186 jclass c = env_->FindClass("AllFields");
1187 ASSERT_TRUE(c != NULL);
1188 jobject o = env_->AllocObject(c);
1189 ASSERT_TRUE(o != NULL);
1190
1191 EXPECT_STATIC_PRIMITIVE_FIELD(Boolean, "sZ", "Z", true, false);
1192 EXPECT_STATIC_PRIMITIVE_FIELD(Byte, "sB", "B", 1, 2);
1193 EXPECT_STATIC_PRIMITIVE_FIELD(Char, "sC", "C", 'a', 'b');
1194 EXPECT_STATIC_PRIMITIVE_FIELD(Double, "sD", "D", 1.0, 2.0);
1195 EXPECT_STATIC_PRIMITIVE_FIELD(Float, "sF", "F", 1.0, 2.0);
1196 EXPECT_STATIC_PRIMITIVE_FIELD(Int, "sI", "I", 1, 2);
1197 EXPECT_STATIC_PRIMITIVE_FIELD(Long, "sJ", "J", 1, 2);
1198 EXPECT_STATIC_PRIMITIVE_FIELD(Short, "sS", "S", 1, 2);
1199
1200 EXPECT_PRIMITIVE_FIELD(o, Boolean, "iZ", "Z", true, false);
1201 EXPECT_PRIMITIVE_FIELD(o, Byte, "iB", "B", 1, 2);
1202 EXPECT_PRIMITIVE_FIELD(o, Char, "iC", "C", 'a', 'b');
1203 EXPECT_PRIMITIVE_FIELD(o, Double, "iD", "D", 1.0, 2.0);
1204 EXPECT_PRIMITIVE_FIELD(o, Float, "iF", "F", 1.0, 2.0);
1205 EXPECT_PRIMITIVE_FIELD(o, Int, "iI", "I", 1, 2);
1206 EXPECT_PRIMITIVE_FIELD(o, Long, "iJ", "J", 1, 2);
1207 EXPECT_PRIMITIVE_FIELD(o, Short, "iS", "S", 1, 2);
1208}
1209
1210TEST_F(JniInternalTest, GetObjectField_SetObjectField) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001211 Thread::Current()->TransitionFromSuspendedToRunnable();
1212 LoadDex("AllFields");
Brian Carlstrom25c33252011-09-18 15:58:35 -07001213 runtime_->Start();
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001214
1215 jclass c = env_->FindClass("AllFields");
1216 ASSERT_TRUE(c != NULL);
1217 jobject o = env_->AllocObject(c);
1218 ASSERT_TRUE(o != NULL);
1219
1220 jstring s1 = env_->NewStringUTF("hello");
1221 ASSERT_TRUE(s1 != NULL);
1222 jstring s2 = env_->NewStringUTF("world");
1223 ASSERT_TRUE(s2 != NULL);
1224
1225 jfieldID s_fid = env_->GetStaticFieldID(c, "sObject", "Ljava/lang/Object;");
1226 ASSERT_TRUE(s_fid != NULL);
1227 jfieldID i_fid = env_->GetFieldID(c, "iObject", "Ljava/lang/Object;");
1228 ASSERT_TRUE(i_fid != NULL);
1229
1230 env_->SetStaticObjectField(c, s_fid, s1);
1231 ASSERT_TRUE(env_->IsSameObject(s1, env_->GetStaticObjectField(c, s_fid)));
1232 env_->SetStaticObjectField(c, s_fid, s2);
1233 ASSERT_TRUE(env_->IsSameObject(s2, env_->GetStaticObjectField(c, s_fid)));
1234
1235 env_->SetObjectField(o, i_fid, s1);
1236 ASSERT_TRUE(env_->IsSameObject(s1, env_->GetObjectField(o, i_fid)));
1237 env_->SetObjectField(o, i_fid, s2);
1238 ASSERT_TRUE(env_->IsSameObject(s2, env_->GetObjectField(o, i_fid)));
1239}
Shih-wei Liao5b8b1ed2012-02-23 23:48:21 -08001240#endif
Elliott Hughes885c3bd2011-08-22 16:59:20 -07001241
Elliott Hughes18c07532011-08-18 15:50:51 -07001242TEST_F(JniInternalTest, NewLocalRef_NULL) {
1243 EXPECT_TRUE(env_->NewLocalRef(NULL) == NULL);
1244}
1245
1246TEST_F(JniInternalTest, NewLocalRef) {
1247 jstring s = env_->NewStringUTF("");
1248 ASSERT_TRUE(s != NULL);
1249 jobject o = env_->NewLocalRef(s);
1250 EXPECT_TRUE(o != NULL);
1251 EXPECT_TRUE(o != s);
1252
Elliott Hughes2ced6a52011-10-16 18:44:48 -07001253 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(o));
Elliott Hughes18c07532011-08-18 15:50:51 -07001254}
1255
1256TEST_F(JniInternalTest, DeleteLocalRef_NULL) {
1257 env_->DeleteLocalRef(NULL);
1258}
1259
1260TEST_F(JniInternalTest, DeleteLocalRef) {
1261 jstring s = env_->NewStringUTF("");
1262 ASSERT_TRUE(s != NULL);
1263 env_->DeleteLocalRef(s);
1264
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001265 // Currently, deleting an already-deleted reference is just a CheckJNI warning.
Elliott Hughesb264f082012-04-06 17:10:10 -07001266 {
Elliott Hughesb264f082012-04-06 17:10:10 -07001267 CheckJniAbortCatcher check_jni_abort_catcher;
1268 env_->DeleteLocalRef(s);
Elliott Hughesa9137c62013-01-09 10:55:21 -08001269
1270 std::string expected(StringPrintf("native code passing in reference to invalid local reference: %p", s));
1271 check_jni_abort_catcher.Check(expected.c_str());
Elliott Hughesb264f082012-04-06 17:10:10 -07001272 }
Elliott Hughes18c07532011-08-18 15:50:51 -07001273
1274 s = env_->NewStringUTF("");
1275 ASSERT_TRUE(s != NULL);
1276 jobject o = env_->NewLocalRef(s);
1277 ASSERT_TRUE(o != NULL);
1278
1279 env_->DeleteLocalRef(s);
1280 env_->DeleteLocalRef(o);
1281}
1282
Elliott Hughes2ced6a52011-10-16 18:44:48 -07001283TEST_F(JniInternalTest, PushLocalFrame_PopLocalFrame) {
1284 jobject original = env_->NewStringUTF("");
1285 ASSERT_TRUE(original != NULL);
1286
1287 jobject outer;
1288 jobject inner1, inner2;
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001289 ScopedObjectAccess soa(env_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001290 mirror::Object* inner2_direct_pointer;
Elliott Hughes2ced6a52011-10-16 18:44:48 -07001291 {
1292 env_->PushLocalFrame(4);
1293 outer = env_->NewLocalRef(original);
1294
1295 {
1296 env_->PushLocalFrame(4);
1297 inner1 = env_->NewLocalRef(outer);
1298 inner2 = env_->NewStringUTF("survivor");
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001299 inner2_direct_pointer = soa.Decode<mirror::Object*>(inner2);
Elliott Hughes2ced6a52011-10-16 18:44:48 -07001300 env_->PopLocalFrame(inner2);
1301 }
1302
1303 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(original));
1304 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(outer));
1305 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner1));
1306
1307 // Our local reference for the survivor is invalid because the survivor
1308 // gets a new local reference...
1309 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner2));
1310 // ...but the survivor should be in the local reference table.
Brian Carlstrom4d571432012-05-16 00:21:41 -07001311 JNIEnvExt* env = reinterpret_cast<JNIEnvExt*>(env_);
1312 EXPECT_TRUE(env->locals.ContainsDirectPointer(inner2_direct_pointer));
Elliott Hughes2ced6a52011-10-16 18:44:48 -07001313
1314 env_->PopLocalFrame(NULL);
1315 }
1316 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(original));
1317 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(outer));
1318 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner1));
1319 EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(inner2));
1320}
1321
Elliott Hughes18c07532011-08-18 15:50:51 -07001322TEST_F(JniInternalTest, NewGlobalRef_NULL) {
1323 EXPECT_TRUE(env_->NewGlobalRef(NULL) == NULL);
1324}
1325
1326TEST_F(JniInternalTest, NewGlobalRef) {
1327 jstring s = env_->NewStringUTF("");
1328 ASSERT_TRUE(s != NULL);
1329 jobject o = env_->NewGlobalRef(s);
1330 EXPECT_TRUE(o != NULL);
1331 EXPECT_TRUE(o != s);
1332
1333 // TODO: check that o is a global reference.
1334}
1335
1336TEST_F(JniInternalTest, DeleteGlobalRef_NULL) {
1337 env_->DeleteGlobalRef(NULL);
1338}
1339
1340TEST_F(JniInternalTest, DeleteGlobalRef) {
1341 jstring s = env_->NewStringUTF("");
1342 ASSERT_TRUE(s != NULL);
1343
1344 jobject o = env_->NewGlobalRef(s);
1345 ASSERT_TRUE(o != NULL);
1346 env_->DeleteGlobalRef(o);
1347
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001348 // Currently, deleting an already-deleted reference is just a CheckJNI warning.
Elliott Hughesb264f082012-04-06 17:10:10 -07001349 {
Elliott Hughesb264f082012-04-06 17:10:10 -07001350 CheckJniAbortCatcher check_jni_abort_catcher;
1351 env_->DeleteGlobalRef(o);
Elliott Hughesa9137c62013-01-09 10:55:21 -08001352
1353 std::string expected(StringPrintf("native code passing in reference to invalid global reference: %p", o));
1354 check_jni_abort_catcher.Check(expected.c_str());
Elliott Hughesb264f082012-04-06 17:10:10 -07001355 }
Elliott Hughes18c07532011-08-18 15:50:51 -07001356
1357 jobject o1 = env_->NewGlobalRef(s);
1358 ASSERT_TRUE(o1 != NULL);
1359 jobject o2 = env_->NewGlobalRef(s);
1360 ASSERT_TRUE(o2 != NULL);
1361
1362 env_->DeleteGlobalRef(o1);
1363 env_->DeleteGlobalRef(o2);
1364}
1365
1366TEST_F(JniInternalTest, NewWeakGlobalRef_NULL) {
1367 EXPECT_TRUE(env_->NewWeakGlobalRef(NULL) == NULL);
1368}
1369
1370TEST_F(JniInternalTest, NewWeakGlobalRef) {
1371 jstring s = env_->NewStringUTF("");
1372 ASSERT_TRUE(s != NULL);
1373 jobject o = env_->NewWeakGlobalRef(s);
1374 EXPECT_TRUE(o != NULL);
1375 EXPECT_TRUE(o != s);
1376
1377 // TODO: check that o is a weak global reference.
1378}
1379
1380TEST_F(JniInternalTest, DeleteWeakGlobalRef_NULL) {
1381 env_->DeleteWeakGlobalRef(NULL);
1382}
1383
1384TEST_F(JniInternalTest, DeleteWeakGlobalRef) {
1385 jstring s = env_->NewStringUTF("");
1386 ASSERT_TRUE(s != NULL);
1387
1388 jobject o = env_->NewWeakGlobalRef(s);
1389 ASSERT_TRUE(o != NULL);
1390 env_->DeleteWeakGlobalRef(o);
1391
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001392 // Currently, deleting an already-deleted reference is just a CheckJNI warning.
Elliott Hughesb264f082012-04-06 17:10:10 -07001393 {
Elliott Hughesb264f082012-04-06 17:10:10 -07001394 CheckJniAbortCatcher check_jni_abort_catcher;
1395 env_->DeleteWeakGlobalRef(o);
Elliott Hughesa9137c62013-01-09 10:55:21 -08001396
1397 std::string expected(StringPrintf("native code passing in reference to invalid weak global reference: %p", o));
1398 check_jni_abort_catcher.Check(expected.c_str());
Elliott Hughesb264f082012-04-06 17:10:10 -07001399 }
Elliott Hughes18c07532011-08-18 15:50:51 -07001400
1401 jobject o1 = env_->NewWeakGlobalRef(s);
1402 ASSERT_TRUE(o1 != NULL);
1403 jobject o2 = env_->NewWeakGlobalRef(s);
1404 ASSERT_TRUE(o2 != NULL);
1405
1406 env_->DeleteWeakGlobalRef(o1);
1407 env_->DeleteWeakGlobalRef(o2);
1408}
1409
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001410TEST_F(JniInternalTest, StaticMainMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001411 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001412 ScopedObjectAccess soa(Thread::Current());
1413 jobject jclass_loader = LoadDex("Main");
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001414 SirtRef<mirror::ClassLoader>
1415 class_loader(soa.Self(), soa.Decode<mirror::ClassLoader*>(jclass_loader));
Brian Carlstrom40381fb2011-10-19 14:13:40 -07001416 CompileDirectMethod(class_loader.get(), "Main", "main", "([Ljava/lang/String;)V");
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001417
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001418 mirror::Class* klass = class_linker_->FindClass("LMain;", class_loader.get());
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001419 ASSERT_TRUE(klass != NULL);
1420
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001421 mirror::AbstractMethod* method = klass->FindDirectMethod("main", "([Ljava/lang/String;)V");
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001422 ASSERT_TRUE(method != NULL);
1423
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001424 mirror::AbstractMethod::InvokeStub* stub = method->GetInvokeStub();
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001425
Elliott Hughes77405792012-03-15 15:22:12 -07001426 JValue args[1];
Elliott Hughesf24d3ce2012-04-11 17:43:37 -07001427 args[0].SetL(NULL);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001428
Elliott Hughes77405792012-03-15 15:22:12 -07001429 (*stub)(method, NULL, Thread::Current(), args, NULL);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001430}
1431
1432TEST_F(JniInternalTest, StaticNopMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001433 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001434 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001435 InvokeNopMethod(true);
1436}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001437
Elliott Hughes77405792012-03-15 15:22:12 -07001438TEST_F(JniInternalTest, NonStaticNopMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001439 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001440 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001441 InvokeNopMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001442}
1443
1444TEST_F(JniInternalTest, StaticIdentityByteMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001445 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001446 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001447 InvokeIdentityByteMethod(true);
1448}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001449
Elliott Hughes77405792012-03-15 15:22:12 -07001450TEST_F(JniInternalTest, NonStaticIdentityByteMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001451 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001452 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001453 InvokeIdentityByteMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001454}
1455
1456TEST_F(JniInternalTest, StaticIdentityIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001457 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001458 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001459 InvokeIdentityIntMethod(true);
1460}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001461
Elliott Hughes77405792012-03-15 15:22:12 -07001462TEST_F(JniInternalTest, NonStaticIdentityIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001463 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001464 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001465 InvokeIdentityIntMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001466}
1467
1468TEST_F(JniInternalTest, StaticIdentityDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001469 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001470 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001471 InvokeIdentityDoubleMethod(true);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001472}
1473
Elliott Hughes77405792012-03-15 15:22:12 -07001474TEST_F(JniInternalTest, NonStaticIdentityDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001475 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001476 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001477 InvokeIdentityDoubleMethod(false);
Shih-wei Liao5b8b1ed2012-02-23 23:48:21 -08001478}
1479
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001480TEST_F(JniInternalTest, StaticSumIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001481 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001482 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001483 InvokeSumIntIntMethod(true);
1484}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001485
Elliott Hughes77405792012-03-15 15:22:12 -07001486TEST_F(JniInternalTest, NonStaticSumIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001487 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001488 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001489 InvokeSumIntIntMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001490}
1491
1492TEST_F(JniInternalTest, StaticSumIntIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001493 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001494 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001495 InvokeSumIntIntIntMethod(true);
1496}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001497
Elliott Hughes77405792012-03-15 15:22:12 -07001498TEST_F(JniInternalTest, NonStaticSumIntIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001499 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001500 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001501 InvokeSumIntIntIntMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001502}
1503
1504TEST_F(JniInternalTest, StaticSumIntIntIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001505 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001506 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001507 InvokeSumIntIntIntIntMethod(true);
1508}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001509
Elliott Hughes77405792012-03-15 15:22:12 -07001510TEST_F(JniInternalTest, NonStaticSumIntIntIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001511 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001512 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001513 InvokeSumIntIntIntIntMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001514}
1515
1516TEST_F(JniInternalTest, StaticSumIntIntIntIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001517 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001518 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001519 InvokeSumIntIntIntIntIntMethod(true);
1520}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001521
Elliott Hughes77405792012-03-15 15:22:12 -07001522TEST_F(JniInternalTest, NonStaticSumIntIntIntIntIntMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001523 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001524 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001525 InvokeSumIntIntIntIntIntMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001526}
1527
1528TEST_F(JniInternalTest, StaticSumDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001529 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001530 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001531 InvokeSumDoubleDoubleMethod(true);
1532}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001533
Elliott Hughes77405792012-03-15 15:22:12 -07001534TEST_F(JniInternalTest, NonStaticSumDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001535 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001536 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001537 InvokeSumDoubleDoubleMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001538}
1539
1540TEST_F(JniInternalTest, StaticSumDoubleDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001541 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001542 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001543 InvokeSumDoubleDoubleDoubleMethod(true);
1544}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001545
Elliott Hughes77405792012-03-15 15:22:12 -07001546TEST_F(JniInternalTest, NonStaticSumDoubleDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001547 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001548 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001549 InvokeSumDoubleDoubleDoubleMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001550}
1551
1552TEST_F(JniInternalTest, StaticSumDoubleDoubleDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001553 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001554 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001555 InvokeSumDoubleDoubleDoubleDoubleMethod(true);
1556}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001557
Elliott Hughes77405792012-03-15 15:22:12 -07001558TEST_F(JniInternalTest, NonStaticSumDoubleDoubleDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001559 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001560 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001561 InvokeSumDoubleDoubleDoubleDoubleMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001562}
1563
1564TEST_F(JniInternalTest, StaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001565 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001566 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001567 InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(true);
1568}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001569
Elliott Hughes77405792012-03-15 15:22:12 -07001570TEST_F(JniInternalTest, NonStaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
Brian Carlstrom265091e2013-01-30 14:08:26 -08001571 TEST_DISABLED_FOR_PORTABLE();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001572 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes77405792012-03-15 15:22:12 -07001573 InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(false);
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001574}
Carl Shapiro9b9ba282011-08-14 15:30:39 -07001575
Elliott Hughes37f7a402011-08-22 18:56:01 -07001576TEST_F(JniInternalTest, Throw) {
1577 EXPECT_EQ(JNI_ERR, env_->Throw(NULL));
1578
1579 jclass exception_class = env_->FindClass("java/lang/RuntimeException");
1580 ASSERT_TRUE(exception_class != NULL);
1581 jthrowable exception = reinterpret_cast<jthrowable>(env_->AllocObject(exception_class));
1582 ASSERT_TRUE(exception != NULL);
1583
1584 EXPECT_EQ(JNI_OK, env_->Throw(exception));
1585 EXPECT_TRUE(env_->ExceptionCheck());
Elliott Hughesa2501992011-08-26 19:39:54 -07001586 jthrowable thrown_exception = env_->ExceptionOccurred();
Elliott Hughes37f7a402011-08-22 18:56:01 -07001587 env_->ExceptionClear();
Elliott Hughesa2501992011-08-26 19:39:54 -07001588 EXPECT_TRUE(env_->IsSameObject(exception, thrown_exception));
Elliott Hughes37f7a402011-08-22 18:56:01 -07001589}
1590
1591TEST_F(JniInternalTest, ThrowNew) {
1592 EXPECT_EQ(JNI_ERR, env_->Throw(NULL));
1593
1594 jclass exception_class = env_->FindClass("java/lang/RuntimeException");
1595 ASSERT_TRUE(exception_class != NULL);
1596
Elliott Hughes5cb5ad22011-10-02 12:13:39 -07001597 jthrowable thrown_exception;
1598
Elliott Hughes37f7a402011-08-22 18:56:01 -07001599 EXPECT_EQ(JNI_OK, env_->ThrowNew(exception_class, "hello world"));
1600 EXPECT_TRUE(env_->ExceptionCheck());
Elliott Hughes5cb5ad22011-10-02 12:13:39 -07001601 thrown_exception = env_->ExceptionOccurred();
1602 env_->ExceptionClear();
1603 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, exception_class));
1604
1605 EXPECT_EQ(JNI_OK, env_->ThrowNew(exception_class, NULL));
1606 EXPECT_TRUE(env_->ExceptionCheck());
1607 thrown_exception = env_->ExceptionOccurred();
Elliott Hughes37f7a402011-08-22 18:56:01 -07001608 env_->ExceptionClear();
Elliott Hughesa2501992011-08-26 19:39:54 -07001609 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, exception_class));
Elliott Hughes37f7a402011-08-22 18:56:01 -07001610}
1611
Elliott Hughesb465ab02011-08-24 11:21:21 -07001612// TODO: this test is DISABLED until we can actually run java.nio.Buffer's <init>.
1613TEST_F(JniInternalTest, DISABLED_NewDirectBuffer_GetDirectBufferAddress_GetDirectBufferCapacity) {
1614 jclass buffer_class = env_->FindClass("java/nio/Buffer");
1615 ASSERT_TRUE(buffer_class != NULL);
1616
1617 char bytes[1024];
1618 jobject buffer = env_->NewDirectByteBuffer(bytes, sizeof(bytes));
1619 ASSERT_TRUE(buffer != NULL);
1620 ASSERT_TRUE(env_->IsInstanceOf(buffer, buffer_class));
1621 ASSERT_TRUE(env_->GetDirectBufferAddress(buffer) == bytes);
1622 ASSERT_TRUE(env_->GetDirectBufferCapacity(buffer) == sizeof(bytes));
1623}
1624
Ian Rogers6d0b13e2012-02-07 09:25:29 -08001625TEST_F(JniInternalTest, MonitorEnterExit) {
1626 // Create an object to torture
1627 jclass object_class = env_->FindClass("java/lang/Object");
1628 ASSERT_TRUE(object_class != NULL);
1629 jobject object = env_->AllocObject(object_class);
1630 ASSERT_TRUE(object != NULL);
1631
1632 // Expected class of exceptions
1633 jclass imse_class = env_->FindClass("java/lang/IllegalMonitorStateException");
1634 ASSERT_TRUE(imse_class != NULL);
1635
1636 jthrowable thrown_exception;
1637
1638 // Unlock of unowned monitor
1639 env_->MonitorExit(object);
1640 EXPECT_TRUE(env_->ExceptionCheck());
1641 thrown_exception = env_->ExceptionOccurred();
1642 env_->ExceptionClear();
1643 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, imse_class));
1644
1645 // Lock of unowned monitor
1646 env_->MonitorEnter(object);
1647 EXPECT_FALSE(env_->ExceptionCheck());
1648 // Regular unlock
1649 env_->MonitorExit(object);
1650 EXPECT_FALSE(env_->ExceptionCheck());
1651
1652 // Recursively lock a lot
1653 size_t max_recursive_lock = 1024;
1654 for (size_t i = 0; i < max_recursive_lock; i++) {
1655 env_->MonitorEnter(object);
1656 EXPECT_FALSE(env_->ExceptionCheck());
1657 }
1658 // Recursively unlock a lot
1659 for (size_t i = 0; i < max_recursive_lock; i++) {
1660 env_->MonitorExit(object);
1661 EXPECT_FALSE(env_->ExceptionCheck());
1662 }
1663
1664 // Unlock of unowned monitor
1665 env_->MonitorExit(object);
1666 EXPECT_TRUE(env_->ExceptionCheck());
1667 thrown_exception = env_->ExceptionOccurred();
1668 env_->ExceptionClear();
1669 EXPECT_TRUE(env_->IsInstanceOf(thrown_exception, imse_class));
Elliott Hughesa92853e2012-02-07 16:09:27 -08001670
1671 // It's an error to call MonitorEnter or MonitorExit on NULL.
Elliott Hughesb264f082012-04-06 17:10:10 -07001672 {
1673 CheckJniAbortCatcher check_jni_abort_catcher;
1674 env_->MonitorEnter(NULL);
1675 check_jni_abort_catcher.Check("in call to MonitorEnter");
Elliott Hughesb264f082012-04-06 17:10:10 -07001676
Elliott Hughesb264f082012-04-06 17:10:10 -07001677 env_->MonitorExit(NULL);
1678 check_jni_abort_catcher.Check("in call to MonitorExit");
1679 }
Ian Rogers6d0b13e2012-02-07 09:25:29 -08001680}
1681
Brian Carlstrom4d571432012-05-16 00:21:41 -07001682TEST_F(JniInternalTest, DetachCurrentThread) {
1683 CleanUpJniEnv(); // cleanup now so TearDown won't have junk from wrong JNIEnv
1684 jint ok = vm_->DetachCurrentThread();
1685 EXPECT_EQ(JNI_OK, ok);
1686
1687 jint err = vm_->DetachCurrentThread();
1688 EXPECT_EQ(JNI_ERR, err);
1689 vm_->AttachCurrentThread(&env_, NULL); // need attached thread for CommonTest::TearDown
1690}
1691
Ian Rogers0cfe1fb2011-08-26 03:29:44 -07001692} // namespace art