• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 public class Main {
18     // TODO: Reduce it once the userfaultfd GC is tested long enough.
19     static final long DURATION_IN_MILLIS = 10_000;
20 
21     static public Object obj = null;
22     static public Object[] array = new Object[4096];
23 
main(String args[])24     public static void main(String args[]) {
25       final long start_time = System.currentTimeMillis();
26       long end_time = start_time;
27       int idx = 0;
28       while (end_time - start_time < DURATION_IN_MILLIS) {
29         try {
30           // Trigger a null-pointer exception
31           System.out.println(obj.toString());
32         } catch (NullPointerException npe) {
33           // Small enough to be not allocated in large-object space and hence keep the compaction
34           // phase longer, while keeping marking phase shorter (as there aren't any references to
35           // chase).
36           array[idx++] = new byte[3000];
37           idx %= array.length;
38         }
39         end_time = System.currentTimeMillis();
40       }
41       System.out.println("Done");
42     }
43 }
44