author | egahlin |
Mon, 08 Jul 2019 23:08:05 +0200 | |
branch | JEP-349-branch |
changeset 57460 | bcbc53560c77 |
parent 57360 | 5d043a159d5c |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
57360 | 2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 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.consumer; |
|
27 |
||
28 |
import jdk.jfr.internal.Type; |
|
29 |
||
30 |
/** |
|
31 |
* Abstract factory for creating specialized types |
|
32 |
*/ |
|
33 |
abstract class ObjectFactory<T> { |
|
34 |
||
35 |
final static String TYPE_PREFIX_VERSION_1 = "com.oracle.jfr.types."; |
|
36 |
final static String TYPE_PREFIX_VERSION_2 = Type.TYPES_PREFIX; |
|
37 |
final static String STACK_FRAME_VERSION_1 = TYPE_PREFIX_VERSION_1 + "StackFrame"; |
|
38 |
final static String STACK_FRAME_VERSION_2 = TYPE_PREFIX_VERSION_2 + "StackFrame"; |
|
39 |
||
40 |
public static ObjectFactory<?> create(Type type, TimeConverter timeConverter) { |
|
41 |
switch (type.getName()) { |
|
42 |
case "java.lang.Thread": |
|
43 |
return RecordedThread.createFactory(type, timeConverter); |
|
44 |
case TYPE_PREFIX_VERSION_1 + "StackFrame": |
|
45 |
case TYPE_PREFIX_VERSION_2 + "StackFrame": |
|
46 |
return RecordedFrame.createFactory(type, timeConverter); |
|
47 |
case TYPE_PREFIX_VERSION_1 + "Method": |
|
48 |
case TYPE_PREFIX_VERSION_2 + "Method": |
|
49 |
return RecordedMethod.createFactory(type, timeConverter); |
|
50 |
case TYPE_PREFIX_VERSION_1 + "ThreadGroup": |
|
51 |
case TYPE_PREFIX_VERSION_2 + "ThreadGroup": |
|
52 |
return RecordedThreadGroup.createFactory(type, timeConverter); |
|
53 |
case TYPE_PREFIX_VERSION_1 + "StackTrace": |
|
54 |
case TYPE_PREFIX_VERSION_2 + "StackTrace": |
|
55 |
return RecordedStackTrace.createFactory(type, timeConverter); |
|
56 |
case TYPE_PREFIX_VERSION_1 + "ClassLoader": |
|
57 |
case TYPE_PREFIX_VERSION_2 + "ClassLoader": |
|
58 |
return RecordedClassLoader.createFactory(type, timeConverter); |
|
59 |
case "java.lang.Class": |
|
60 |
return RecordedClass.createFactory(type, timeConverter); |
|
61 |
} |
|
62 |
return null; |
|
63 |
} |
|
64 |
||
57460
bcbc53560c77
Reduce allocation rate by minimizing number of fields in RecordedEvent
egahlin
parents:
57360
diff
changeset
|
65 |
private final ObjectContext objectContext; |
50113 | 66 |
|
57460
bcbc53560c77
Reduce allocation rate by minimizing number of fields in RecordedEvent
egahlin
parents:
57360
diff
changeset
|
67 |
ObjectFactory(Type type, TimeConverter timeConverter) { |
bcbc53560c77
Reduce allocation rate by minimizing number of fields in RecordedEvent
egahlin
parents:
57360
diff
changeset
|
68 |
this.objectContext = new ObjectContext(null, type.getFields(), timeConverter); |
50113 | 69 |
} |
70 |
||
71 |
T createObject(long id, Object value) { |
|
72 |
if (value == null) { |
|
73 |
return null; |
|
74 |
} |
|
75 |
if (value instanceof Object[]) { |
|
57460
bcbc53560c77
Reduce allocation rate by minimizing number of fields in RecordedEvent
egahlin
parents:
57360
diff
changeset
|
76 |
return createTyped(objectContext, id, (Object[]) value); |
50113 | 77 |
} |
57360 | 78 |
throw new InternalError("Object factory must have struct type. Type was " + value.getClass().getName()); |
50113 | 79 |
} |
80 |
||
57460
bcbc53560c77
Reduce allocation rate by minimizing number of fields in RecordedEvent
egahlin
parents:
57360
diff
changeset
|
81 |
abstract T createTyped(ObjectContext objectContextm, long id, Object[] values); |
50113 | 82 |
} |