Add callback for notifying that startup is completed

Add a callback that can be called to denote that application startup
is completed. This may affect how the profile is collected and how
startup related caches are managed.

Bug: 123377072
Bug: 120671223
Test: test-art-host
Change-Id: If7eb8909cc5e99082a2243b5029380244b46174d
diff --git a/test/1002-notify-startup/expected.txt b/test/1002-notify-startup/expected.txt
new file mode 100644
index 0000000..a86b9aa
--- /dev/null
+++ b/test/1002-notify-startup/expected.txt
@@ -0,0 +1,3 @@
+JNI_OnLoad called
+Startup completed: false
+Startup completed: true
diff --git a/test/1002-notify-startup/info.txt b/test/1002-notify-startup/info.txt
new file mode 100644
index 0000000..1ebca87
--- /dev/null
+++ b/test/1002-notify-startup/info.txt
@@ -0,0 +1 @@
+Test that the startup completed callback works.
diff --git a/test/1002-notify-startup/src-art/Main.java b/test/1002-notify-startup/src-art/Main.java
new file mode 100644
index 0000000..9a1e442
--- /dev/null
+++ b/test/1002-notify-startup/src-art/Main.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2019 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 dalvik.system.VMRuntime;
+
+public class Main {
+  public static void main(String[] args) {
+    System.loadLibrary(args[0]);
+    System.out.println("Startup completed: " + hasStartupCompleted());
+    VMRuntime.getRuntime().notifyStartupCompleted();
+    System.out.println("Startup completed: " + hasStartupCompleted());
+  }
+
+  private static native boolean hasStartupCompleted();
+}
diff --git a/test/1002-notify-startup/startup_interface.cc b/test/1002-notify-startup/startup_interface.cc
new file mode 100644
index 0000000..8705bb2
--- /dev/null
+++ b/test/1002-notify-startup/startup_interface.cc
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2019 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 "gc/heap.h"
+#include "runtime.h"
+
+namespace art {
+namespace {
+
+extern "C" bool JNICALL Java_Main_hasStartupCompleted(JNIEnv*, jclass) {
+  return Runtime::Current()->GetStartupCompleted();
+}
+
+}  // namespace
+}  // namespace art