blob: fe229e4fff6a31c6f17c98999e75ba6c97eb1089 [file] [log] [blame]
Mingyao Yang504a6902016-04-28 16:23:01 -07001/*
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"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070018
Mingyao Yang504a6902016-04-28 16:23:01 -070019#include "gc/gc_cause.h"
20#include "gc/scoped_gc_critical_section.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070021#include "mirror/class-inl.h"
22#include "runtime.h"
Andreas Gamped4901292017-05-30 18:41:34 -070023#include "scoped_thread_state_change-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070024#include "thread_list.h"
25#include "thread_state.h"
Mingyao Yang504a6902016-04-28 16:23:01 -070026
27namespace art {
28
29extern "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
48extern "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