Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | |
| 17 | #include "reflection.h" |
| 18 | |
Brian Carlstrom | 8edba0b | 2014-03-14 16:11:43 -0700 | [diff] [blame] | 19 | #include <float.h> |
Ian Rogers | 88e46a3 | 2014-03-14 14:37:59 -0700 | [diff] [blame] | 20 | #include <limits.h> |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 21 | #include "ScopedLocalRef.h" |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 22 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "art_method-inl.h" |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 24 | #include "common_compiler_test.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 25 | #include "scoped_thread_state_change.h" |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | // TODO: Convert to CommonRuntimeTest. Currently MakeExecutable is used. |
| 30 | class ReflectionTest : public CommonCompilerTest { |
| 31 | protected: |
| 32 | virtual void SetUp() { |
| 33 | CommonCompilerTest::SetUp(); |
| 34 | |
| 35 | vm_ = Runtime::Current()->GetJavaVM(); |
| 36 | |
| 37 | // Turn on -verbose:jni for the JNI tests. |
| 38 | // gLogVerbosity.jni = true; |
| 39 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 40 | vm_->AttachCurrentThread(&env_, nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 41 | |
| 42 | ScopedLocalRef<jclass> aioobe(env_, |
| 43 | env_->FindClass("java/lang/ArrayIndexOutOfBoundsException")); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 44 | CHECK(aioobe.get() != nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 45 | aioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(aioobe.get())); |
| 46 | |
| 47 | ScopedLocalRef<jclass> ase(env_, env_->FindClass("java/lang/ArrayStoreException")); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 48 | CHECK(ase.get() != nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 49 | ase_ = reinterpret_cast<jclass>(env_->NewGlobalRef(ase.get())); |
| 50 | |
| 51 | ScopedLocalRef<jclass> sioobe(env_, |
| 52 | env_->FindClass("java/lang/StringIndexOutOfBoundsException")); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 53 | CHECK(sioobe.get() != nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 54 | sioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(sioobe.get())); |
| 55 | } |
| 56 | |
| 57 | void CleanUpJniEnv() { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 58 | if (aioobe_ != nullptr) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 59 | env_->DeleteGlobalRef(aioobe_); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 60 | aioobe_ = nullptr; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 61 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 62 | if (ase_ != nullptr) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 63 | env_->DeleteGlobalRef(ase_); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 64 | ase_ = nullptr; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 65 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 66 | if (sioobe_ != nullptr) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 67 | env_->DeleteGlobalRef(sioobe_); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 68 | sioobe_ = nullptr; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | virtual void TearDown() { |
| 73 | CleanUpJniEnv(); |
| 74 | CommonCompilerTest::TearDown(); |
| 75 | } |
| 76 | |
| 77 | jclass GetPrimitiveClass(char descriptor) { |
| 78 | ScopedObjectAccess soa(env_); |
| 79 | mirror::Class* c = class_linker_->FindPrimitiveClass(descriptor); |
| 80 | CHECK(c != nullptr); |
| 81 | return soa.AddLocalReference<jclass>(c); |
| 82 | } |
| 83 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 84 | void ReflectionTestMakeExecutable(ArtMethod** method, |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 85 | mirror::Object** receiver, |
| 86 | bool is_static, const char* method_name, |
| 87 | const char* method_signature) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 88 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 89 | const char* class_name = is_static ? "StaticLeafMethods" : "NonStaticLeafMethods"; |
| 90 | jobject jclass_loader(LoadDex(class_name)); |
| 91 | Thread* self = Thread::Current(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 92 | StackHandleScope<2> hs(self); |
| 93 | Handle<mirror::ClassLoader> class_loader( |
| 94 | hs.NewHandle( |
| 95 | ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader))); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 96 | if (is_static) { |
| 97 | MakeExecutable(ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader), |
| 98 | class_name); |
| 99 | } else { |
| 100 | MakeExecutable(nullptr, "java.lang.Class"); |
| 101 | MakeExecutable(nullptr, "java.lang.Object"); |
| 102 | MakeExecutable(ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader), |
| 103 | class_name); |
| 104 | } |
| 105 | |
| 106 | mirror::Class* c = class_linker_->FindClass(self, DotToDescriptor(class_name).c_str(), |
| 107 | class_loader); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 108 | CHECK(c != nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 109 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 110 | *method = is_static ? c->FindDirectMethod(method_name, method_signature, sizeof(void*)) |
| 111 | : c->FindVirtualMethod(method_name, method_signature, sizeof(void*)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 112 | CHECK(method != nullptr); |
| 113 | |
Sebastien Hertz | 4e99b3d | 2014-06-24 14:35:40 +0200 | [diff] [blame] | 114 | if (is_static) { |
| 115 | *receiver = nullptr; |
| 116 | } else { |
| 117 | // Ensure class is initialized before allocating object |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 118 | StackHandleScope<1> hs2(self); |
| 119 | Handle<mirror::Class> h_class(hs2.NewHandle(c)); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 120 | bool initialized = class_linker_->EnsureInitialized(self, h_class, true, true); |
Sebastien Hertz | 4e99b3d | 2014-06-24 14:35:40 +0200 | [diff] [blame] | 121 | CHECK(initialized); |
| 122 | *receiver = c->AllocObject(self); |
| 123 | } |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 124 | |
| 125 | // Start runtime. |
| 126 | bool started = runtime_->Start(); |
| 127 | CHECK(started); |
| 128 | self->TransitionFromSuspendedToRunnable(); |
| 129 | } |
| 130 | |
| 131 | void InvokeNopMethod(bool is_static) { |
| 132 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 133 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 134 | mirror::Object* receiver; |
| 135 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "nop", "()V"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 136 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
| 137 | InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void InvokeIdentityByteMethod(bool is_static) { |
| 141 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 142 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 143 | mirror::Object* receiver; |
| 144 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(B)B"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 145 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 146 | jvalue args[1]; |
| 147 | |
| 148 | args[0].b = 0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 149 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 150 | EXPECT_EQ(0, result.GetB()); |
| 151 | |
| 152 | args[0].b = -1; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 153 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 154 | EXPECT_EQ(-1, result.GetB()); |
| 155 | |
| 156 | args[0].b = SCHAR_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 157 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 158 | EXPECT_EQ(SCHAR_MAX, result.GetB()); |
| 159 | |
| 160 | args[0].b = (SCHAR_MIN << 24) >> 24; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 161 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 162 | EXPECT_EQ(SCHAR_MIN, result.GetB()); |
| 163 | } |
| 164 | |
| 165 | void InvokeIdentityIntMethod(bool is_static) { |
| 166 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 167 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 168 | mirror::Object* receiver; |
| 169 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(I)I"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 170 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 171 | jvalue args[1]; |
| 172 | |
| 173 | args[0].i = 0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 174 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 175 | EXPECT_EQ(0, result.GetI()); |
| 176 | |
| 177 | args[0].i = -1; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 178 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 179 | EXPECT_EQ(-1, result.GetI()); |
| 180 | |
| 181 | args[0].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 182 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 183 | EXPECT_EQ(INT_MAX, result.GetI()); |
| 184 | |
| 185 | args[0].i = INT_MIN; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 186 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 187 | EXPECT_EQ(INT_MIN, result.GetI()); |
| 188 | } |
| 189 | |
| 190 | void InvokeIdentityDoubleMethod(bool is_static) { |
| 191 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 192 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 193 | mirror::Object* receiver; |
| 194 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(D)D"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 195 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 196 | jvalue args[1]; |
| 197 | |
| 198 | args[0].d = 0.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 199 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 200 | EXPECT_DOUBLE_EQ(0.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 201 | |
| 202 | args[0].d = -1.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 203 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 204 | EXPECT_DOUBLE_EQ(-1.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 205 | |
| 206 | args[0].d = DBL_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 207 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 208 | EXPECT_DOUBLE_EQ(DBL_MAX, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 209 | |
| 210 | args[0].d = DBL_MIN; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 211 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 212 | EXPECT_DOUBLE_EQ(DBL_MIN, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void InvokeSumIntIntMethod(bool is_static) { |
| 216 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 217 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 218 | mirror::Object* receiver; |
| 219 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(II)I"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 220 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 221 | jvalue args[2]; |
| 222 | |
| 223 | args[0].i = 1; |
| 224 | args[1].i = 2; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 225 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 226 | EXPECT_EQ(3, result.GetI()); |
| 227 | |
| 228 | args[0].i = -2; |
| 229 | args[1].i = 5; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 230 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 231 | EXPECT_EQ(3, result.GetI()); |
| 232 | |
| 233 | args[0].i = INT_MAX; |
| 234 | args[1].i = INT_MIN; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 235 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 236 | EXPECT_EQ(-1, result.GetI()); |
| 237 | |
| 238 | args[0].i = INT_MAX; |
| 239 | args[1].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 240 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 241 | EXPECT_EQ(-2, result.GetI()); |
| 242 | } |
| 243 | |
| 244 | void InvokeSumIntIntIntMethod(bool is_static) { |
| 245 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 246 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 247 | mirror::Object* receiver; |
| 248 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(III)I"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 249 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 250 | jvalue args[3]; |
| 251 | |
| 252 | args[0].i = 0; |
| 253 | args[1].i = 0; |
| 254 | args[2].i = 0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 255 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 256 | EXPECT_EQ(0, result.GetI()); |
| 257 | |
| 258 | args[0].i = 1; |
| 259 | args[1].i = 2; |
| 260 | args[2].i = 3; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 261 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 262 | EXPECT_EQ(6, result.GetI()); |
| 263 | |
| 264 | args[0].i = -1; |
| 265 | args[1].i = 2; |
| 266 | args[2].i = -3; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 267 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 268 | EXPECT_EQ(-2, result.GetI()); |
| 269 | |
| 270 | args[0].i = INT_MAX; |
| 271 | args[1].i = INT_MIN; |
| 272 | args[2].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 273 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 274 | EXPECT_EQ(2147483646, result.GetI()); |
| 275 | |
| 276 | args[0].i = INT_MAX; |
| 277 | args[1].i = INT_MAX; |
| 278 | args[2].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 279 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 280 | EXPECT_EQ(2147483645, result.GetI()); |
| 281 | } |
| 282 | |
| 283 | void InvokeSumIntIntIntIntMethod(bool is_static) { |
| 284 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 285 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 286 | mirror::Object* receiver; |
| 287 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(IIII)I"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 288 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 289 | jvalue args[4]; |
| 290 | |
| 291 | args[0].i = 0; |
| 292 | args[1].i = 0; |
| 293 | args[2].i = 0; |
| 294 | args[3].i = 0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 295 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 296 | EXPECT_EQ(0, result.GetI()); |
| 297 | |
| 298 | args[0].i = 1; |
| 299 | args[1].i = 2; |
| 300 | args[2].i = 3; |
| 301 | args[3].i = 4; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 302 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 303 | EXPECT_EQ(10, result.GetI()); |
| 304 | |
| 305 | args[0].i = -1; |
| 306 | args[1].i = 2; |
| 307 | args[2].i = -3; |
| 308 | args[3].i = 4; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 309 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 310 | EXPECT_EQ(2, result.GetI()); |
| 311 | |
| 312 | args[0].i = INT_MAX; |
| 313 | args[1].i = INT_MIN; |
| 314 | args[2].i = INT_MAX; |
| 315 | args[3].i = INT_MIN; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 316 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 317 | EXPECT_EQ(-2, result.GetI()); |
| 318 | |
| 319 | args[0].i = INT_MAX; |
| 320 | args[1].i = INT_MAX; |
| 321 | args[2].i = INT_MAX; |
| 322 | args[3].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 323 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 324 | EXPECT_EQ(-4, result.GetI()); |
| 325 | } |
| 326 | |
| 327 | void InvokeSumIntIntIntIntIntMethod(bool is_static) { |
| 328 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 329 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 330 | mirror::Object* receiver; |
| 331 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(IIIII)I"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 332 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 333 | jvalue args[5]; |
| 334 | |
| 335 | args[0].i = 0; |
| 336 | args[1].i = 0; |
| 337 | args[2].i = 0; |
| 338 | args[3].i = 0; |
| 339 | args[4].i = 0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 340 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 341 | EXPECT_EQ(0, result.GetI()); |
| 342 | |
| 343 | args[0].i = 1; |
| 344 | args[1].i = 2; |
| 345 | args[2].i = 3; |
| 346 | args[3].i = 4; |
| 347 | args[4].i = 5; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 348 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 349 | EXPECT_EQ(15, result.GetI()); |
| 350 | |
| 351 | args[0].i = -1; |
| 352 | args[1].i = 2; |
| 353 | args[2].i = -3; |
| 354 | args[3].i = 4; |
| 355 | args[4].i = -5; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 356 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 357 | EXPECT_EQ(-3, result.GetI()); |
| 358 | |
| 359 | args[0].i = INT_MAX; |
| 360 | args[1].i = INT_MIN; |
| 361 | args[2].i = INT_MAX; |
| 362 | args[3].i = INT_MIN; |
| 363 | args[4].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 364 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 365 | EXPECT_EQ(2147483645, result.GetI()); |
| 366 | |
| 367 | args[0].i = INT_MAX; |
| 368 | args[1].i = INT_MAX; |
| 369 | args[2].i = INT_MAX; |
| 370 | args[3].i = INT_MAX; |
| 371 | args[4].i = INT_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 372 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 373 | EXPECT_EQ(2147483643, result.GetI()); |
| 374 | } |
| 375 | |
| 376 | void InvokeSumDoubleDoubleMethod(bool is_static) { |
| 377 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 378 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 379 | mirror::Object* receiver; |
| 380 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DD)D"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 381 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 382 | jvalue args[2]; |
| 383 | |
| 384 | args[0].d = 0.0; |
| 385 | args[1].d = 0.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 386 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 387 | EXPECT_DOUBLE_EQ(0.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 388 | |
| 389 | args[0].d = 1.0; |
| 390 | args[1].d = 2.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 391 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 392 | EXPECT_DOUBLE_EQ(3.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 393 | |
| 394 | args[0].d = 1.0; |
| 395 | args[1].d = -2.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 396 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 397 | EXPECT_DOUBLE_EQ(-1.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 398 | |
| 399 | args[0].d = DBL_MAX; |
| 400 | args[1].d = DBL_MIN; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 401 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 402 | EXPECT_DOUBLE_EQ(1.7976931348623157e308, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 403 | |
| 404 | args[0].d = DBL_MAX; |
| 405 | args[1].d = DBL_MAX; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 406 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 407 | EXPECT_DOUBLE_EQ(INFINITY, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void InvokeSumDoubleDoubleDoubleMethod(bool is_static) { |
| 411 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 412 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 413 | mirror::Object* receiver; |
| 414 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDD)D"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 415 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 416 | jvalue args[3]; |
| 417 | |
| 418 | args[0].d = 0.0; |
| 419 | args[1].d = 0.0; |
| 420 | args[2].d = 0.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 421 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 422 | EXPECT_DOUBLE_EQ(0.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 423 | |
| 424 | args[0].d = 1.0; |
| 425 | args[1].d = 2.0; |
| 426 | args[2].d = 3.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 427 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 428 | EXPECT_DOUBLE_EQ(6.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 429 | |
| 430 | args[0].d = 1.0; |
| 431 | args[1].d = -2.0; |
| 432 | args[2].d = 3.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 433 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 434 | EXPECT_DOUBLE_EQ(2.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static) { |
| 438 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 439 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 440 | mirror::Object* receiver; |
| 441 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDDD)D"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 442 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 443 | jvalue args[4]; |
| 444 | |
| 445 | args[0].d = 0.0; |
| 446 | args[1].d = 0.0; |
| 447 | args[2].d = 0.0; |
| 448 | args[3].d = 0.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 449 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 450 | EXPECT_DOUBLE_EQ(0.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 451 | |
| 452 | args[0].d = 1.0; |
| 453 | args[1].d = 2.0; |
| 454 | args[2].d = 3.0; |
| 455 | args[3].d = 4.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 456 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 457 | EXPECT_DOUBLE_EQ(10.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 458 | |
| 459 | args[0].d = 1.0; |
| 460 | args[1].d = -2.0; |
| 461 | args[2].d = 3.0; |
| 462 | args[3].d = -4.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 463 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 464 | EXPECT_DOUBLE_EQ(-2.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | void InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static) { |
| 468 | ScopedObjectAccess soa(env_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 469 | ArtMethod* method; |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 470 | mirror::Object* receiver; |
| 471 | ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDDDD)D"); |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 472 | ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver)); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 473 | jvalue args[5]; |
| 474 | |
| 475 | args[0].d = 0.0; |
| 476 | args[1].d = 0.0; |
| 477 | args[2].d = 0.0; |
| 478 | args[3].d = 0.0; |
| 479 | args[4].d = 0.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 480 | JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 481 | EXPECT_DOUBLE_EQ(0.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 482 | |
| 483 | args[0].d = 1.0; |
| 484 | args[1].d = 2.0; |
| 485 | args[2].d = 3.0; |
| 486 | args[3].d = 4.0; |
| 487 | args[4].d = 5.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 488 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 489 | EXPECT_DOUBLE_EQ(15.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 490 | |
| 491 | args[0].d = 1.0; |
| 492 | args[1].d = -2.0; |
| 493 | args[2].d = 3.0; |
| 494 | args[3].d = -4.0; |
| 495 | args[4].d = 5.0; |
Jeff Hao | 39b6c24 | 2015-05-19 20:30:23 -0700 | [diff] [blame] | 496 | result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args); |
Ian Rogers | 647b1a8 | 2014-10-10 11:02:11 -0700 | [diff] [blame] | 497 | EXPECT_DOUBLE_EQ(3.0, result.GetD()); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | JavaVMExt* vm_; |
| 501 | JNIEnv* env_; |
| 502 | jclass aioobe_; |
| 503 | jclass ase_; |
| 504 | jclass sioobe_; |
| 505 | }; |
| 506 | |
| 507 | TEST_F(ReflectionTest, StaticMainMethod) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 508 | TEST_DISABLED_FOR_HEAP_REFERENCE_POISONING_WITH_QUICK(); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 509 | ScopedObjectAccess soa(Thread::Current()); |
| 510 | jobject jclass_loader = LoadDex("Main"); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 511 | StackHandleScope<1> hs(soa.Self()); |
| 512 | Handle<mirror::ClassLoader> class_loader( |
| 513 | hs.NewHandle(soa.Decode<mirror::ClassLoader*>(jclass_loader))); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 514 | CompileDirectMethod(class_loader, "Main", "main", "([Ljava/lang/String;)V"); |
| 515 | |
| 516 | mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 517 | ASSERT_TRUE(klass != nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 518 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 519 | ArtMethod* method = klass->FindDirectMethod("main", "([Ljava/lang/String;)V", sizeof(void*)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 520 | ASSERT_TRUE(method != nullptr); |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 521 | |
| 522 | // Start runtime. |
| 523 | bool started = runtime_->Start(); |
| 524 | CHECK(started); |
| 525 | soa.Self()->TransitionFromSuspendedToRunnable(); |
| 526 | |
| 527 | jvalue args[1]; |
| 528 | args[0].l = nullptr; |
| 529 | InvokeWithJValues(soa, nullptr, soa.EncodeMethod(method), args); |
| 530 | } |
| 531 | |
| 532 | TEST_F(ReflectionTest, StaticNopMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 533 | InvokeNopMethod(true); |
| 534 | } |
| 535 | |
| 536 | TEST_F(ReflectionTest, NonStaticNopMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 537 | InvokeNopMethod(false); |
| 538 | } |
| 539 | |
| 540 | TEST_F(ReflectionTest, StaticIdentityByteMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 541 | InvokeIdentityByteMethod(true); |
| 542 | } |
| 543 | |
| 544 | TEST_F(ReflectionTest, NonStaticIdentityByteMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 545 | InvokeIdentityByteMethod(false); |
| 546 | } |
| 547 | |
| 548 | TEST_F(ReflectionTest, StaticIdentityIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 549 | InvokeIdentityIntMethod(true); |
| 550 | } |
| 551 | |
| 552 | TEST_F(ReflectionTest, NonStaticIdentityIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 553 | InvokeIdentityIntMethod(false); |
| 554 | } |
| 555 | |
| 556 | TEST_F(ReflectionTest, StaticIdentityDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 557 | InvokeIdentityDoubleMethod(true); |
| 558 | } |
| 559 | |
| 560 | TEST_F(ReflectionTest, NonStaticIdentityDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 561 | InvokeIdentityDoubleMethod(false); |
| 562 | } |
| 563 | |
| 564 | TEST_F(ReflectionTest, StaticSumIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 565 | InvokeSumIntIntMethod(true); |
| 566 | } |
| 567 | |
| 568 | TEST_F(ReflectionTest, NonStaticSumIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 569 | InvokeSumIntIntMethod(false); |
| 570 | } |
| 571 | |
| 572 | TEST_F(ReflectionTest, StaticSumIntIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 573 | InvokeSumIntIntIntMethod(true); |
| 574 | } |
| 575 | |
| 576 | TEST_F(ReflectionTest, NonStaticSumIntIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 577 | InvokeSumIntIntIntMethod(false); |
| 578 | } |
| 579 | |
| 580 | TEST_F(ReflectionTest, StaticSumIntIntIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 581 | InvokeSumIntIntIntIntMethod(true); |
| 582 | } |
| 583 | |
| 584 | TEST_F(ReflectionTest, NonStaticSumIntIntIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 585 | InvokeSumIntIntIntIntMethod(false); |
| 586 | } |
| 587 | |
| 588 | TEST_F(ReflectionTest, StaticSumIntIntIntIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 589 | InvokeSumIntIntIntIntIntMethod(true); |
| 590 | } |
| 591 | |
| 592 | TEST_F(ReflectionTest, NonStaticSumIntIntIntIntIntMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 593 | InvokeSumIntIntIntIntIntMethod(false); |
| 594 | } |
| 595 | |
| 596 | TEST_F(ReflectionTest, StaticSumDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 597 | InvokeSumDoubleDoubleMethod(true); |
| 598 | } |
| 599 | |
| 600 | TEST_F(ReflectionTest, NonStaticSumDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 601 | InvokeSumDoubleDoubleMethod(false); |
| 602 | } |
| 603 | |
| 604 | TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 605 | InvokeSumDoubleDoubleDoubleMethod(true); |
| 606 | } |
| 607 | |
| 608 | TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 609 | InvokeSumDoubleDoubleDoubleMethod(false); |
| 610 | } |
| 611 | |
| 612 | TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 613 | InvokeSumDoubleDoubleDoubleDoubleMethod(true); |
| 614 | } |
| 615 | |
| 616 | TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 617 | InvokeSumDoubleDoubleDoubleDoubleMethod(false); |
| 618 | } |
| 619 | |
| 620 | TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 621 | InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(true); |
| 622 | } |
| 623 | |
| 624 | TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleDoubleDoubleMethod) { |
Ian Rogers | 53b8b09 | 2014-03-13 23:45:53 -0700 | [diff] [blame] | 625 | InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(false); |
| 626 | } |
| 627 | |
| 628 | } // namespace art |