blob: 1597c4a65dcdba66f83f433f30b1b307ecf2a72c [file] [log] [blame]
Nicolas Geoffray32c9ea52015-06-12 14:52:33 +01001/*
2 * Copyright (C) 2015 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 "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070018#include "base/enums.h"
Nicolas Geoffray32c9ea52015-06-12 14:52:33 +010019#include "jni.h"
20#include "scoped_thread_state_change.h"
21#include "stack.h"
22#include "thread.h"
23
24namespace art {
25
26namespace {
27
Vladimir Marko05792b92015-08-03 11:56:49 +010028extern "C" JNIEXPORT jobject JNICALL Java_Main_cloneResolvedMethods(JNIEnv* env,
29 jclass,
30 jclass cls) {
Nicolas Geoffray32c9ea52015-06-12 14:52:33 +010031 ScopedObjectAccess soa(Thread::Current());
Vladimir Marko05792b92015-08-03 11:56:49 +010032 mirror::DexCache* dex_cache = soa.Decode<mirror::Class*>(cls)->GetDexCache();
33 size_t num_methods = dex_cache->NumResolvedMethods();
34 ArtMethod** methods = dex_cache->GetResolvedMethods();
35 CHECK_EQ(num_methods != 0u, methods != nullptr);
36 if (num_methods == 0u) {
37 return nullptr;
38 }
39 jarray array;
40 if (sizeof(void*) == 4) {
41 array = env->NewIntArray(num_methods);
42 } else {
43 array = env->NewLongArray(num_methods);
44 }
45 CHECK(array != nullptr);
46 mirror::PointerArray* pointer_array = soa.Decode<mirror::PointerArray*>(array);
47 for (size_t i = 0; i != num_methods; ++i) {
Andreas Gampe542451c2016-07-26 09:02:02 -070048 ArtMethod* method = mirror::DexCache::GetElementPtrSize(methods, i, kRuntimePointerSize);
49 pointer_array->SetElementPtrSize(i, method, kRuntimePointerSize);
Vladimir Marko05792b92015-08-03 11:56:49 +010050 }
51 return array;
Nicolas Geoffray32c9ea52015-06-12 14:52:33 +010052}
53
54extern "C" JNIEXPORT void JNICALL Java_Main_restoreResolvedMethods(
55 JNIEnv*, jclass, jclass cls, jobject old_cache) {
56 ScopedObjectAccess soa(Thread::Current());
Vladimir Marko05792b92015-08-03 11:56:49 +010057 mirror::DexCache* dex_cache = soa.Decode<mirror::Class*>(cls)->GetDexCache();
58 size_t num_methods = dex_cache->NumResolvedMethods();
59 ArtMethod** methods = soa.Decode<mirror::Class*>(cls)->GetDexCache()->GetResolvedMethods();
60 CHECK_EQ(num_methods != 0u, methods != nullptr);
Nicolas Geoffray32c9ea52015-06-12 14:52:33 +010061 mirror::PointerArray* old = soa.Decode<mirror::PointerArray*>(old_cache);
Vladimir Marko05792b92015-08-03 11:56:49 +010062 CHECK_EQ(methods != nullptr, old != nullptr);
63 CHECK_EQ(num_methods, static_cast<size_t>(old->GetLength()));
64 for (size_t i = 0; i != num_methods; ++i) {
Andreas Gampe542451c2016-07-26 09:02:02 -070065 ArtMethod* method = old->GetElementPtrSize<ArtMethod*>(i, kRuntimePointerSize);
66 mirror::DexCache::SetElementPtrSize(methods, i, method, kRuntimePointerSize);
Nicolas Geoffray32c9ea52015-06-12 14:52:33 +010067 }
68}
69
70} // namespace
71
72} // namespace art