Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [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 | */ |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 16 | |
Mathieu Chartier | ba17f45 | 2016-05-05 15:31:12 -0700 | [diff] [blame] | 17 | #include "art_method-inl.h" |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 18 | #include "check_reference_map_visitor.h" |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 19 | #include "jni.h" |
| 20 | |
| 21 | namespace art { |
| 22 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 23 | #define CHECK_REGS(...) do { \ |
| 24 | int t[] = {__VA_ARGS__}; \ |
| 25 | int t_size = sizeof(t) / sizeof(*t); \ |
| 26 | CheckReferences(t, t_size, GetNativePcOffset()); \ |
| 27 | } while (false); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 28 | |
| 29 | static int gJava_StackWalk_refmap_calls = 0; |
| 30 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 31 | class TestReferenceMapVisitor : public CheckReferenceMapVisitor { |
| 32 | public: |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 33 | explicit TestReferenceMapVisitor(Thread* thread) SHARED_REQUIRES(Locks::mutator_lock_) |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 34 | : CheckReferenceMapVisitor(thread) {} |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 35 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 36 | bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 37 | if (CheckReferenceMapVisitor::VisitFrame()) { |
Elliott Hughes | 530fa00 | 2012-03-12 11:44:49 -0700 | [diff] [blame] | 38 | return true; |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 39 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 40 | ArtMethod* m = GetMethod(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 41 | StringPiece m_name(m->GetName()); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 42 | |
| 43 | // Given the method name and the number of times the method has been called, |
| 44 | // we know the Dex registers with live reference values. Assert that what we |
| 45 | // find is what is expected. |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 46 | if (m_name == "$noinline$f") { |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 47 | if (gJava_StackWalk_refmap_calls == 1) { |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 48 | CHECK_EQ(1U, GetDexPc()); |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 49 | CHECK_REGS(1); // v1: this |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 50 | } else { |
Elliott Hughes | f5a7a47 | 2011-10-07 14:31:02 -0700 | [diff] [blame] | 51 | CHECK_EQ(gJava_StackWalk_refmap_calls, 2); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 52 | CHECK_EQ(5U, GetDexPc()); |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 53 | CHECK_REGS(1); // v1: this |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 54 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 55 | } else if (m_name == "g") { |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 56 | if (gJava_StackWalk_refmap_calls == 1) { |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 57 | CHECK_EQ(0xdU, GetDexPc()); |
| 58 | CHECK_REGS(0, 2); // v2: this (Note that v1 is not in the minimal root set) |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 59 | } else { |
Elliott Hughes | f5a7a47 | 2011-10-07 14:31:02 -0700 | [diff] [blame] | 60 | CHECK_EQ(gJava_StackWalk_refmap_calls, 2); |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 61 | CHECK_EQ(0xdU, GetDexPc()); |
Shih-wei Liao | 0839bdb | 2011-10-12 10:50:44 -0700 | [diff] [blame] | 62 | CHECK_REGS(0, 2); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 63 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 64 | } else if (m_name == "shlemiel") { |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 65 | if (gJava_StackWalk_refmap_calls == 1) { |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 66 | CHECK_EQ(0x393U, GetDexPc()); |
Shih-wei Liao | 0839bdb | 2011-10-12 10:50:44 -0700 | [diff] [blame] | 67 | CHECK_REGS(2, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 25); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 68 | } else { |
Elliott Hughes | f5a7a47 | 2011-10-07 14:31:02 -0700 | [diff] [blame] | 69 | CHECK_EQ(gJava_StackWalk_refmap_calls, 2); |
Sebastien Hertz | f27e2a9 | 2016-02-29 16:54:16 +0100 | [diff] [blame] | 70 | CHECK_EQ(0x393U, GetDexPc()); |
Shih-wei Liao | 0839bdb | 2011-10-12 10:50:44 -0700 | [diff] [blame] | 71 | CHECK_REGS(2, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 25); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 72 | } |
| 73 | } |
Elliott Hughes | 530fa00 | 2012-03-12 11:44:49 -0700 | [diff] [blame] | 74 | |
| 75 | return true; |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 76 | } |
| 77 | }; |
| 78 | |
Andreas Gampe | 1c83cbc | 2014-07-22 18:52:29 -0700 | [diff] [blame] | 79 | extern "C" JNIEXPORT jint JNICALL Java_Main_stackmap(JNIEnv*, jobject, jint count) { |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 80 | ScopedObjectAccess soa(Thread::Current()); |
Shih-wei Liao | 0839bdb | 2011-10-12 10:50:44 -0700 | [diff] [blame] | 81 | CHECK_EQ(count, 0); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 82 | gJava_StackWalk_refmap_calls++; |
| 83 | |
| 84 | // Visitor |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 85 | TestReferenceMapVisitor mapper(soa.Self()); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 86 | mapper.WalkStack(); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 87 | |
| 88 | return count + 1; |
| 89 | } |
| 90 | |
Andreas Gampe | 1c83cbc | 2014-07-22 18:52:29 -0700 | [diff] [blame] | 91 | extern "C" JNIEXPORT jint JNICALL Java_Main_refmap2(JNIEnv*, jobject, jint count) { |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 92 | ScopedObjectAccess soa(Thread::Current()); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 93 | gJava_StackWalk_refmap_calls++; |
| 94 | |
| 95 | // Visitor |
Ian Rogers | 7a22fa6 | 2013-01-23 12:16:16 -0800 | [diff] [blame] | 96 | TestReferenceMapVisitor mapper(soa.Self()); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 97 | mapper.WalkStack(); |
Shih-wei Liao | 9407c60 | 2011-09-16 10:36:43 -0700 | [diff] [blame] | 98 | |
| 99 | return count + 1; |
| 100 | } |
| 101 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 102 | } // namespace art |