diff options
| -rw-r--r-- | runtime/openjdkjvmti/OpenjdkJvmTi.cc | 2 | ||||
| -rw-r--r-- | runtime/openjdkjvmti/heap.cc | 6 | ||||
| -rw-r--r-- | runtime/openjdkjvmti/heap.h | 2 | ||||
| -rwxr-xr-x | test/913-heaps/build | 17 | ||||
| -rw-r--r-- | test/913-heaps/expected.txt | 4 | ||||
| -rw-r--r-- | test/913-heaps/heaps.cc | 53 | ||||
| -rw-r--r-- | test/913-heaps/heaps.h | 30 | ||||
| -rw-r--r-- | test/913-heaps/info.txt | 1 | ||||
| -rwxr-xr-x | test/913-heaps/run | 43 | ||||
| -rw-r--r-- | test/913-heaps/src/Main.java | 52 | ||||
| -rw-r--r-- | test/Android.bp | 1 | ||||
| -rw-r--r-- | test/Android.run-test.mk | 4 | ||||
| -rw-r--r-- | test/ti-agent/common_load.cc | 2 |
13 files changed, 215 insertions, 2 deletions
diff --git a/runtime/openjdkjvmti/OpenjdkJvmTi.cc b/runtime/openjdkjvmti/OpenjdkJvmTi.cc index 50b50d6661..d867727b88 100644 --- a/runtime/openjdkjvmti/OpenjdkJvmTi.cc +++ b/runtime/openjdkjvmti/OpenjdkJvmTi.cc @@ -346,7 +346,7 @@ class JvmtiFunctions { } static jvmtiError ForceGarbageCollection(jvmtiEnv* env) { - return ERR(NOT_IMPLEMENTED); + return HeapUtil::ForceGarbageCollection(env); } static jvmtiError IterateOverObjectsReachableFromObject( diff --git a/runtime/openjdkjvmti/heap.cc b/runtime/openjdkjvmti/heap.cc index 1799e1957d..df33abdf81 100644 --- a/runtime/openjdkjvmti/heap.cc +++ b/runtime/openjdkjvmti/heap.cc @@ -210,4 +210,10 @@ jvmtiError HeapUtil::GetLoadedClasses(jvmtiEnv* env, return ERR(NONE); } +jvmtiError HeapUtil::ForceGarbageCollection(jvmtiEnv* env ATTRIBUTE_UNUSED) { + art::Runtime::Current()->GetHeap()->CollectGarbage(false); + + return ERR(NONE); +} + } // namespace openjdkjvmti diff --git a/runtime/openjdkjvmti/heap.h b/runtime/openjdkjvmti/heap.h index b6becb97bb..b0c7f6f9ce 100644 --- a/runtime/openjdkjvmti/heap.h +++ b/runtime/openjdkjvmti/heap.h @@ -36,6 +36,8 @@ class HeapUtil { const jvmtiHeapCallbacks* callbacks, const void* user_data); + static jvmtiError ForceGarbageCollection(jvmtiEnv* env); + ObjectTagTable* GetTags() { return tags_; } diff --git a/test/913-heaps/build b/test/913-heaps/build new file mode 100755 index 0000000000..898e2e54a2 --- /dev/null +++ b/test/913-heaps/build @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +./default-build "$@" --experimental agents diff --git a/test/913-heaps/expected.txt b/test/913-heaps/expected.txt new file mode 100644 index 0000000000..a127f4e16d --- /dev/null +++ b/test/913-heaps/expected.txt @@ -0,0 +1,4 @@ +--- +false false +--- +true true diff --git a/test/913-heaps/heaps.cc b/test/913-heaps/heaps.cc new file mode 100644 index 0000000000..437779a5f4 --- /dev/null +++ b/test/913-heaps/heaps.cc @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "heaps.h" + +#include <stdio.h> +#include <string.h> + +#include "base/macros.h" +#include "jni.h" +#include "openjdkjvmti/jvmti.h" + +#include "ti-agent/common_load.h" + +namespace art { +namespace Test913Heaps { + +extern "C" JNIEXPORT void JNICALL Java_Main_forceGarbageCollection(JNIEnv* env ATTRIBUTE_UNUSED, + jclass klass ATTRIBUTE_UNUSED) { + jvmtiError ret = jvmti_env->ForceGarbageCollection(); + if (ret != JVMTI_ERROR_NONE) { + char* err; + jvmti_env->GetErrorName(ret, &err); + printf("Error forcing a garbage collection: %s\n", err); + } +} + +// Don't do anything +jint OnLoad(JavaVM* vm, + char* options ATTRIBUTE_UNUSED, + void* reserved ATTRIBUTE_UNUSED) { + if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) { + printf("Unable to get jvmti env!\n"); + return 1; + } + return 0; +} + +} // namespace Test913Heaps +} // namespace art diff --git a/test/913-heaps/heaps.h b/test/913-heaps/heaps.h new file mode 100644 index 0000000000..bd828aca33 --- /dev/null +++ b/test/913-heaps/heaps.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_TEST_913_HEAPS_HEAPS_H_ +#define ART_TEST_913_HEAPS_HEAPS_H_ + +#include <jni.h> + +namespace art { +namespace Test913Heaps { + +jint OnLoad(JavaVM* vm, char* options, void* reserved); + +} // namespace Test913Heaps +} // namespace art + +#endif // ART_TEST_913_HEAPS_HEAPS_H_ diff --git a/test/913-heaps/info.txt b/test/913-heaps/info.txt new file mode 100644 index 0000000000..875a5f6ec1 --- /dev/null +++ b/test/913-heaps/info.txt @@ -0,0 +1 @@ +Tests basic functions in the jvmti plugin. diff --git a/test/913-heaps/run b/test/913-heaps/run new file mode 100755 index 0000000000..7bd8cbd1dd --- /dev/null +++ b/test/913-heaps/run @@ -0,0 +1,43 @@ +#!/bin/bash +# +# Copyright 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +plugin=libopenjdkjvmtid.so +agent=libtiagentd.so +lib=tiagentd +if [[ "$@" == *"-O"* ]]; then + agent=libtiagent.so + plugin=libopenjdkjvmti.so + lib=tiagent +fi + +if [[ "$@" == *"--jvm"* ]]; then + arg="jvm" +else + arg="art" +fi + +if [[ "$@" != *"--debuggable"* ]]; then + other_args=" -Xcompiler-option --debuggable " +else + other_args="" +fi + +./default-run "$@" --experimental agents \ + --experimental runtime-plugins \ + --runtime-option -agentpath:${agent}=913-heaps,${arg} \ + --android-runtime-option -Xplugin:${plugin} \ + ${other_args} \ + --args ${lib} diff --git a/test/913-heaps/src/Main.java b/test/913-heaps/src/Main.java new file mode 100644 index 0000000000..0d1c92be22 --- /dev/null +++ b/test/913-heaps/src/Main.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) throws Exception { + System.loadLibrary(args[1]); + + doTest(); + } + + public static void doTest() throws Exception { + setupGcCallback(); + + enableGcTracking(true); + run(); + enableGcTracking(false); + } + + private static void run() { + printStats(); + forceGarbageCollection(); + printStats(); + } + + private static void printStats() { + System.out.println("---"); + int s = getGcStarts(); + int f = getGcFinishes(); + System.out.println((s > 0) + " " + (f > 0)); + } + + private static native void setupGcCallback(); + private static native void enableGcTracking(boolean enable); + private static native int getGcStarts(); + private static native int getGcFinishes(); + private static native void forceGarbageCollection(); +} diff --git a/test/Android.bp b/test/Android.bp index af70486abf..bdb7f80eb0 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -256,6 +256,7 @@ art_cc_defaults { "910-methods/methods.cc", "911-get-stack-trace/stack_trace.cc", "912-classes/classes.cc", + "913-heaps/heaps.cc", ], shared_libs: [ "libbase", diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk index 2251b7e163..ae569f91a3 100644 --- a/test/Android.run-test.mk +++ b/test/Android.run-test.mk @@ -279,6 +279,7 @@ TEST_ART_BROKEN_TARGET_TESTS += \ 910-methods \ 911-get-stack-trace \ 912-classes \ + 913-heaps \ ifneq (,$(filter target,$(TARGET_TYPES))) ART_TEST_KNOWN_BROKEN += $(call all-run-test-names,target,$(RUN_TYPES),$(PREBUILD_TYPES), \ @@ -374,13 +375,14 @@ TEST_ART_BROKEN_INTERPRETER_ACCESS_CHECK_TESTS := # * 137-cfi needs to unwind a second forked process. We're using a primitive sleep to wait till we # hope the second process got into the expected state. The slowness of gcstress makes this bad. # * 908-gc-start-finish expects GCs only to be run at clear points. The reduced heap size makes -# this non-deterministic. +# this non-deterministic. Same for 913. # * 961-default-iface-resolution-gen and 964-default-iface-init-genare very long tests that often # will take more than the timeout to run when gcstress is enabled. This is because gcstress # slows down allocations significantly which these tests do a lot. TEST_ART_BROKEN_GCSTRESS_RUN_TESTS := \ 137-cfi \ 908-gc-start-finish \ + 913-heaps \ 961-default-iface-resolution-gen \ 964-default-iface-init-gen \ diff --git a/test/ti-agent/common_load.cc b/test/ti-agent/common_load.cc index 4db953cc4a..a959482772 100644 --- a/test/ti-agent/common_load.cc +++ b/test/ti-agent/common_load.cc @@ -36,6 +36,7 @@ #include "910-methods/methods.h" #include "911-get-stack-trace/stack_trace.h" #include "912-classes/classes.h" +#include "913-heaps/heaps.h" namespace art { @@ -64,6 +65,7 @@ AgentLib agents[] = { { "910-methods", Test910Methods::OnLoad, nullptr }, { "911-get-stack-trace", Test911GetStackTrace::OnLoad, nullptr }, { "912-classes", Test912Classes::OnLoad, nullptr }, + { "913-heaps", Test913Heaps::OnLoad, nullptr }, }; static AgentLib* FindAgent(char* name) { |