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