|
1 /* |
|
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package jdk.jfr.internal; |
|
27 |
|
28 import jdk.internal.org.objectweb.asm.commons.Method; |
|
29 import jdk.jfr.internal.EventInstrumentation.FieldInfo; |
|
30 |
|
31 public enum EventWriterMethod { |
|
32 |
|
33 BEGIN_EVENT("(" + jdk.internal.org.objectweb.asm.Type.getType(PlatformEventType.class).getDescriptor() + ")Z", "???", "beginEvent"), |
|
34 END_EVENT("()Z", "???", "endEvent"), |
|
35 PUT_BYTE("(B)V", "byte", "putByte"), |
|
36 PUT_SHORT("(S)V", "short", "putShort"), |
|
37 PUT_INT("(I)V", "int", "putInt"), |
|
38 PUT_LONG("(J)V", "long", "putLong"), |
|
39 PUT_FLOAT("(F)V", "float", "putFloat"), |
|
40 PUT_DOUBLE("(D)V", "double", "putDouble"), |
|
41 PUT_CHAR("(C)V", "char", "putChar"), |
|
42 PUT_BOOLEAN("(Z)V", "boolean", "putBoolean"), |
|
43 PUT_THREAD("(Ljava/lang/Thread;)V", Type.THREAD.getName(), "putThread"), |
|
44 PUT_CLASS("(Ljava/lang/Class;)V", Type.CLASS.getName(), "putClass"), |
|
45 PUT_STRING("(Ljava/lang/String;Ljdk/jfr/internal/StringPool;)V", Type.STRING.getName(), "putString"), |
|
46 PUT_EVENT_THREAD("()V", Type.THREAD.getName(), "putEventThread"), |
|
47 PUT_STACK_TRACE("()V", Type.TYPES_PREFIX + "StackTrace", "putStackTrace"); |
|
48 |
|
49 private final Method asmMethod; |
|
50 private final String typeDescriptor; |
|
51 |
|
52 EventWriterMethod(String paramSignature, String typeName, String methodName) { |
|
53 this.typeDescriptor = ASMToolkit.getDescriptor(typeName); |
|
54 this.asmMethod = new Method(methodName, paramSignature); |
|
55 } |
|
56 |
|
57 public Method asASM() { |
|
58 return asmMethod; |
|
59 } |
|
60 |
|
61 /** |
|
62 * Return method in {@link EventWriter} class to use when writing event of |
|
63 * a certain type. |
|
64 * |
|
65 * @param v field info |
|
66 * |
|
67 * @return the method |
|
68 */ |
|
69 public static EventWriterMethod lookupMethod(FieldInfo v) { |
|
70 // event thread |
|
71 if (v.fieldName.equals(EventInstrumentation.FIELD_EVENT_THREAD)) { |
|
72 return EventWriterMethod.PUT_EVENT_THREAD; |
|
73 } |
|
74 for (EventWriterMethod m : EventWriterMethod.values()) { |
|
75 if (v.fieldDescriptor.equals(m.typeDescriptor)) { |
|
76 return m; |
|
77 } |
|
78 } |
|
79 throw new Error("Unknown type " + v.fieldDescriptor); |
|
80 } |
|
81 } |