1 /*
2  * Copyright (C) 2011 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 package art;
18 
19 public class Test901 {
run()20   public static void run() {
21     System.out.println("Hello, world!");
22 
23     if (checkLivePhase()) {
24       System.out.println("Agent in live phase.");
25     }
26     if (checkUnattached()) {
27       System.out.println("Received expected error for unattached JVMTI calls");
28     }
29 
30     set(0);  // OTHER
31     set(1);  // GC
32     set(2);  // CLASS
33     set(4);  // JNI
34     set(8);  // Error.
35 
36     testErrorNames();
37   }
38 
set(int i)39   private static void set(int i) {
40     System.out.println(i);
41     try {
42       setVerboseFlag(i, true);
43       setVerboseFlag(i, false);
44     } catch (RuntimeException e) {
45       System.out.println(e.getMessage());
46     }
47   }
48 
testErrorNames()49   private static void testErrorNames() {
50       int consecutiveErrors = 0;
51       String lastError = null;
52       for (int i = -1; i <= 117; i++) {
53           String errorName = null;
54           String error = null;
55           try {
56               errorName = getErrorName(i);
57           } catch (RuntimeException e) {
58               error = e.getMessage();
59           }
60 
61           if (lastError != null &&
62                   (errorName != null || (error != null && !lastError.equals(error)))) {
63               System.out.println(consecutiveErrors + " times " + lastError);
64               lastError = null;
65               consecutiveErrors = 0;
66           }
67 
68           if (errorName != null) {
69               System.out.println(i + " = " + errorName);
70           } else {
71               lastError = error;
72               consecutiveErrors++;
73           }
74       }
75       if (consecutiveErrors > 0) {
76           System.out.println(consecutiveErrors + " times " + lastError);
77       }
78   }
79 
checkLivePhase()80   private static native boolean checkLivePhase();
setVerboseFlag(int flag, boolean value)81   private static native void setVerboseFlag(int flag, boolean value);
checkUnattached()82   private static native boolean checkUnattached();
getErrorName(int error)83   private static native String getErrorName(int error);
84 }
85