1 /*
2 * Copyright (C) 2016 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 "jni.h"
18
19 #include "gc/gc_cause.h"
20 #include "gc/scoped_gc_critical_section.h"
21 #include "mirror/class-inl.h"
22 #include "runtime.h"
23 #include "scoped_thread_state_change-inl.h"
24 #include "thread_list.h"
25 #include "thread_state.h"
26
27 namespace art {
28
Java_Main_deoptimizeAll(JNIEnv * env,jclass cls ATTRIBUTE_UNUSED)29 extern "C" JNIEXPORT void JNICALL Java_Main_deoptimizeAll(
30 JNIEnv* env,
31 jclass cls ATTRIBUTE_UNUSED) {
32 ScopedObjectAccess soa(env);
33 ScopedThreadSuspension sts(Thread::Current(), kWaitingForDeoptimization);
34 gc::ScopedGCCriticalSection gcs(Thread::Current(),
35 gc::kGcCauseInstrumentation,
36 gc::kCollectorTypeInstrumentation);
37 // We need to suspend mutator threads first.
38 ScopedSuspendAll ssa(__FUNCTION__);
39 static bool first = true;
40 if (first) {
41 // We need to enable deoptimization once in order to call DeoptimizeEverything().
42 Runtime::Current()->GetInstrumentation()->EnableDeoptimization();
43 first = false;
44 }
45 Runtime::Current()->GetInstrumentation()->DeoptimizeEverything("test");
46 }
47
Java_Main_undeoptimizeAll(JNIEnv * env,jclass cls ATTRIBUTE_UNUSED)48 extern "C" JNIEXPORT void JNICALL Java_Main_undeoptimizeAll(
49 JNIEnv* env,
50 jclass cls ATTRIBUTE_UNUSED) {
51 ScopedObjectAccess soa(env);
52 ScopedThreadSuspension sts(Thread::Current(), kWaitingForDeoptimization);
53 gc::ScopedGCCriticalSection gcs(Thread::Current(),
54 gc::kGcCauseInstrumentation,
55 gc::kCollectorTypeInstrumentation);
56 // We need to suspend mutator threads first.
57 ScopedSuspendAll ssa(__FUNCTION__);
58 Runtime::Current()->GetInstrumentation()->UndeoptimizeEverything("test");
59 }
60
61 } // namespace art
62