forked from btraceio/btrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTraceUtils.java
More file actions
6972 lines (6330 loc) · 243 KB
/
BTraceUtils.java
File metadata and controls
6972 lines (6330 loc) · 243 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the Classpath exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.btrace;
import com.sun.btrace.aggregation.Aggregation;
import com.sun.btrace.aggregation.AggregationFunction;
import com.sun.btrace.aggregation.AggregationKey;
import com.sun.btrace.annotations.OnMethod;
import com.sun.btrace.annotations.ProbeClassName;
import com.sun.btrace.annotations.ProbeMethodName;
import com.sun.btrace.annotations.Self;
import sun.reflect.Reflection;
import java.io.Serializable;
import java.lang.management.MemoryUsage;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/**
* This class is an all-in-one wrapper for BTrace DSL methods
* @author A. Sundararajan
* @author Jaroslav Bachorik
*/
public class BTraceUtils {
static {
BTraceRuntime.initUnsafe();
}
// standard stack depth decrement for Reflection.getCallerClass() calls
private static final int STACK_DEC = 2;
// do not allow object creation!
private BTraceUtils() {}
// Thread and stack access
/**
* Tests whether this thread has been interrupted. The <i>interrupted
* status</i> of the thread is unaffected by this method.
*
* <p>A thread interruption ignored because a thread was not alive
* at the time of the interrupt will be reflected by this method
* returning false.
*
* @return <code>true</code> if this thread has been interrupted;
* <code>false</code> otherwise.
*/
public static boolean isInteruppted() {
return Threads.isInteruppted();
}
/**
* Prints the java stack trace of the current thread.
*/
public static void jstack() {
Threads.jstack(2, -1);
}
/**
* Prints the java stack trace of the current thread. But,
* atmost given number of frames.
*
* @param numFrames number of frames to be printed. When this is
* negative all frames are printed.
*/
public static void jstack(int numFrames) {
Threads.jstack(2, numFrames);
}
/**
* Prints Java stack traces of all the Java threads.
*/
public static void jstackAll() {
Threads.jstackAll(2, -1);
}
/**
* Prints Java stack traces of all the Java threads. But,
* atmost given number of frames.
*
* @param numFrames number of frames to be printed. When this is
* negative all frames are printed.
*/
public static void jstackAll(int numFrames) {
Threads.jstackAll(2, numFrames);
}
/**
* Returns the stack trace of current thread as a String.
*
* @return the stack trace as a String.
*/
public static String jstackStr() {
return Threads.jstackStr(2, -1);
}
/**
* Returns the stack trace of the current thread as a String
* but includes atmost the given number of frames.
*
* @param numFrames number of frames to be included. When this is
* negative all frames are included.
* @return the stack trace as a String.
*/
public static String jstackStr(int numFrames) {
return Threads.jstackStr(2, numFrames);
}
/**
* Returns the stack traces of all Java threads as a String.
*
* @return the stack traces as a String.
*/
public static String jstackAllStr() {
return Threads.jstackAllStr();
}
/**
* Returns atmost given number of frames in stack traces
* of all threads as a String.
*
* @param numFrames number of frames to be included. When this is
* negative all frames are included.
* @return the stack traces as a String.
*/
public static String jstackAllStr(int numFrames) {
return Threads.jstackAllStr(numFrames);
}
/**
* Prints the stack trace of the given exception object.
*
* @param exception throwable for which stack trace is printed.
*/
public static void jstack(Throwable exception) {
Threads.jstack(exception);
}
/**
* Prints the stack trace of the given exception object. But,
* prints atmost given number of frames.
*
* @param exception throwable for which stack trace is printed.
* @param numFrames maximum number of frames to be printed.
*/
public static void jstack(Throwable exception, int numFrames) {
Threads.jstack(exception, numFrames);
}
/**
* Returns the stack trace of given exception object as a String.
*
* @param exception the throwable for which stack trace is returned.
*/
public static String jstackStr(Throwable exception) {
return Threads.jstackStr(exception);
}
/**
* Returns stack trace of given exception object as a String.
*
* @param exception throwable for which stack trace is returned.
* @param numFrames maximum number of frames to be returned.
*/
public static String jstackStr(Throwable exception, int numFrames) {
return Threads.jstackStr(exception, numFrames);
}
/**
* Returns a reference to the currently executing thread object.
*
* @return the currently executing thread.
*/
public static Thread currentThread() {
return Threads.currentThread();
}
/**
* Returns the identifier of the given Thread. The thread ID is a positive
* <tt>long</tt> number generated when the given thread was created.
* The thread ID is unique and remains unchanged during its lifetime.
* When a thread is terminated, the thread ID may be reused.
*/
public static long threadId(Thread thread) {
return Threads.threadId(thread);
}
/**
* Returns the state of the given thread.
* This method is designed for use in monitoring of the system state,
* not for synchronization control.
*/
public static Thread.State threadState(Thread thread) {
return Threads.threadState(thread);
}
/**
* Returns <tt>true</tt> if and only if the current thread holds the
* monitor lock on the specified object.
*
* <p>This method is designed to allow a program to assert that
* the current thread already holds a specified lock:
* <pre>
* assert Thread.holdsLock(obj);
* </pre>
*
* @param obj the object on which to test lock ownership
* @throws NullPointerException if obj is <tt>null</tt>
* @return <tt>true</tt> if the current thread holds the monitor lock on
* the specified object.
*/
public static boolean holdsLock(Object obj) {
return Threads.holdsLock(obj);
}
/**
* Prints the Java level deadlocks detected (if any).
*/
public static void deadlocks() {
Threads.deadlocks();
}
/**
* Prints deadlocks detected (if any). Optionally prints
* stack trace of the deadlocked threads.
*
* @param stackTrace boolean flag to specify whether to
* print stack traces of deadlocked threads or not.
*/
public static void deadlocks(boolean stackTrace) {
Threads.deadlocks(stackTrace);
}
/**
* Returns the name of the given thread.
*
* @param thread thread whose name is returned
*/
public static String name(Thread thread) {
return Threads.name(thread);
}
// class loader access
/**
* Returns the class loader for the given class. Some implementations may use
* null to represent the bootstrap class loader. This method will return
* null in such implementations if this class was loaded by the bootstrap
* class loader.
*
* @param clazz the Class for which the class loader is returned
*/
public static ClassLoader loader(Class clazz) {
return clazz.getClassLoader();
}
/**
* Returns the parent class loader of the given loader. Some implementations may
* use <tt>null</tt> to represent the bootstrap class loader. This method
* will return <tt>null</tt> in such implementations if this class loader's
* parent is the bootstrap class loader.
*
* @param loader the loader for which the parent loader is returned
* @return The parent <tt>ClassLoader</tt>
*/
public static ClassLoader parentLoader(ClassLoader loader) {
return loader.getParent();
}
// java.lang.Object methods
/**
* Returns a string representation of the object. In general, the
* <code>toString</code> method returns a string that
* "textually represents" this object. The result should
* be a concise but informative representation that is easy for a
* person to read. For bootstrap classes, returns the result of
* calling Object.toString() override. For non-bootstrap classes,
* default toString() value [className@hashCode] is returned.
*
* @param obj the object whose string representation is returned
* @return a string representation of the given object.
*/
public static String str(Object obj) {
return Strings.str(obj);
}
/**
* Returns identity string of the form class-name@identity-hash
*
* @param obj object for which identity string is returned
* @return identity string
*/
public static String identityStr(Object obj) {
int hashCode = java.lang.System.identityHashCode(obj);
return obj.getClass().getName() + "@" + Integer.toHexString(hashCode);
}
/**
* Returns a hash code value for the object. This method is supported
* for the benefit of hashtables such as those provided by
* <code>java.util.Hashtable</code>. For bootstrap classes, returns the
* result of calling Object.hashCode() override. For non-bootstrap classes,
* the identity hash code is returned.
*
* @param obj the Object whose hash code is returned.
* @return a hash code value for the given object.
*/
public static int hash(Object obj) {
if (obj.getClass().getClassLoader() == null) {
return obj.hashCode();
} else {
return java.lang.System.identityHashCode(obj);
}
}
/**
* Returns the same hash code for the given object as
* would be returned by the default method hashCode(),
* whether or not the given object's class overrides
* hashCode(). The hash code for the null reference is zero.
*
* @param obj object for which the hashCode is to be calculated
* @return the hashCode
*/
public static int identityHashCode(Object obj) {
return java.lang.System.identityHashCode(obj);
}
/**
* Indicates whether two given objects are "equal to" one another.
* For bootstrap classes, returns the result of calling Object.equals()
* override. For non-bootstrap classes, the reference identity comparison
* is done.
*
* @param obj1 first object to compare equality
* @param obj2 second object to compare equality
* @return <code>true</code> if the given objects are equal;
* <code>false</code> otherwise.
*/
public static boolean compare(Object obj1, Object obj2) {
return BTraceRuntime.compare(obj1, obj2);
}
// reflection
/**
* Returns the runtime class of the given Object.
*
* @param obj the Object whose Class is returned
* @return the Class object of given object
*/
public static Class classOf(Object obj) {
return Reflective.classOf(obj);
}
/**
* Checks whether the provided object is an instance of the named class.
* <cite>Note: this method can be rather CPU intensive, use with caution</cite>
* @param obj the object to check
* @param className the class name; as a special case {@code void} can be provided
* to check whether the instance is a void value wrapper - {@linkplain AnyType#VOID}
* @return {@code true} if the object can be assigned to an instance of 'className' type
*
* @since 1.3.5
*/
public static boolean instanceOf(Object obj, String className) {
return BTraceRuntime.instanceOf(obj, className);
}
/**
* Returns the Class object representing the class or interface
* that declares the field represented by the given Field object.
* @param field whose declaring Class is returned
*/
public static Class declaringClass(Field field) {
return Reflective.declaringClass(field);
}
/**
* Returns the name of the given Class object.
*/
public static String name(Class clazz) {
return Reflective.name(clazz);
}
/**
* Returns the name of the Field object.
*
* @param field Field for which name is returned
* @return name of the given field
*/
public static String name(Field field) {
return Reflective.name(field);
}
/**
* Returns the type of the Field object.
*
* @param field Field for which type is returned
* @return type of the given field
*/
public static Class type(Field field) {
return Reflective.type(field);
}
/**
* Returns the access flags of the given Class.
*/
public static int accessFlags(Class clazz) {
return Reflective.accessFlags(clazz);
}
/**
* Returns the access flags of the given Field.
*/
public static int accessFlags(Field field) {
return Reflective.accessFlags(field);
}
/**
* Returns the current context class loader
*/
public static ClassLoader contextClassLoader() {
return Reflective.contextClassLoader();
}
// get Class of the given name
/**
* Returns Class object for given class name.
*/
public static Class classForName(String name) {
return Reflective.classForName(name);
}
/**
* Returns the Class for the given class name
* using the given class loader.
*/
public static Class classForName(String name, ClassLoader cl) {
return Reflective.classForName(name, cl);
}
/**
* Determines if the class or interface represented by the first
* <code>Class</code> object is either the same as, or is a superclass or
* superinterface of, the class or interface represented by the second
* <code>Class</code> parameter. It returns <code>true</code> if so;
* otherwise it returns <code>false</code>.
*/
public static boolean isAssignableFrom(Class<?> a, Class<?> b) {
return Reflective.isAssignableFrom(a, b);
}
/**
* Determines if the specified <code>Object</code> is assignment-compatible
* with the object represented by the specified <code>Class</code>. This method is
* the dynamic equivalent of the Java language <code>instanceof</code>
* operator. The method returns <code>true</code> if the specified
* <code>Object</code> argument is non-null and can be cast to the
* reference type represented by this <code>Class</code> object without
* raising a <code>ClassCastException.</code> It returns <code>false</code>
* otherwise.
*
* @param clazz the class that is checked.
* @param obj the object to check.
* @return true if <code>obj</code> is an instance of the given class.
*/
public static boolean isInstance(Class clazz, Object obj) {
return Reflective.isInstance(clazz, obj);
}
/**
* Returns the <code>Class</code> representing the superclass of the entity
* (class, interface, primitive type or void) represented by the given
* <code>Class</code>. If the given <code>Class</code> represents either the
* <code>Object</code> class, an interface, a primitive type, or void, then
* null is returned. If the given object represents an array class then the
* <code>Class</code> object representing the <code>Object</code> class is
* returned.
*
* @param clazz the Class whose super class is returned.
* @return the superclass of the class represented by the given object.
*/
public static Class getSuperclass(Class clazz) {
return Reflective.getSuperclass(clazz);
}
/**
* Determines if the specified <code>Class</code> object represents an
* interface type.
*
* @param clazz the Class object to check.
* @return <code>true</code> if the Class represents an interface;
* <code>false</code> otherwise.
*/
public static boolean isInterface(Class clazz) {
return Reflective.isInterface(clazz);
}
/**
* Determines if the given <code>Class</code> object represents an array class.
*
* @param clazz Class object to check.
* @return <code>true</code> if the given object represents an array class;
* <code>false</code> otherwise.
*/
public static boolean isArray(Class clazz) {
return Reflective.isArray(clazz);
}
/**
* Returns whether the given Class represent primitive type or not.
*/
public static boolean isPrimitive(Class clazz) {
return Reflective.isPrimitive(clazz);
}
/**
* returns component type of an array Class.
*/
public static Class getComponentType(Class clazz) {
return Reflective.getComponentType(clazz);
}
// Accessing fields by reflection
/**
* Returns a <code>Field</code> object that reflects the specified declared
* field of the class or interface represented by the given <code>Class</code>
* object. The <code>name</code> parameter is a <code>String</code> that
* specifies the simple name of the desired field. Returns <code>null</code> on not finding
* field if throwException parameter is <code>false</code>. Else throws a <code>RuntimeException</code>
* when field is not found.
*
* @param clazz Class whose field is returned
* @param name the name of the field
* @param throwException whether to throw exception on failing to find field or not
* @return the <code>Field</code> object for the specified field in this
* class
*/
public static Field field(Class clazz, String name, boolean throwException) {
return Reflective.field(clazz, name, throwException);
}
/**
* Returns a <code>Field</code> object that reflects the specified declared
* field of the class or interface represented by the given <code>Class</code>
* object. The <code>name</code> parameter is a <code>String</code> that
* specifies the simple name of the desired field. Throws a <code>RuntimeException</code>
* when field is not found.
*
* @param clazz Class whose field is returned
* @param name the name of the field
* @return the <code>Field</code> object for the specified field in this
* class
*/
public static Field field(Class clazz, String name) {
return Reflective.field(clazz, name);
}
/**
* Returns a <code>Field</code> object that reflects the specified declared
* field of the class or interface represented by the given <code>Class</code>
* object. The <code>name</code> parameter is a <code>String</code> that
* specifies the simple name of the desired field. Returns <code>null</code> on not finding
* field if throwException parameter is <code>false</code>. Else throws a <code>RuntimeException</code>
* when field is not found.
*
* @param clazz Class whose field is returned
* @param name the name of the field
* @param throwException whether to throw exception on failing to find field or not
* @return the <code>Field</code> object for the specified field in this
* class
*/
public static Field field(String clazz, String name, boolean throwException) {
ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
return Reflective.field(classForName(clazz, callerLoader), name, throwException);
}
/**
* Returns a <code>Field</code> object that reflects the specified declared
* field of the class or interface represented by the given <code>Class</code>
* object. The <code>name</code> parameter is a <code>String</code> that
* specifies the simple name of the desired field. Throws a <code>RuntimeException</code>
* when field is not found.
*
* @param clazz Class whose field is returned
* @param name the name of the field
* @return the <code>Field</code> object for the specified field in this
* class
*/
public static Field field(String clazz, String name) {
ClassLoader callerLoader = Reflection.getCallerClass(STACK_DEC).getClassLoader();
return Reflective.field(classForName(clazz, callerLoader), name);
}
// field value get methods
/**
* Gets the value of a static <code>byte</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>byte</code> field
*/
public static byte getByte(Field field) {
return Reflective.getByte(field);
}
/**
* Gets the value of an instance <code>byte</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>byte</code> value
* from
* @return the value of the <code>byte</code> field
*/
public static byte getByte(Field field, Object obj) {
return Reflective.getByte(field, obj);
}
/**
* Gets the value of a static <code>short</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>short</code> field
*/
public static short getShort(Field field) {
return Reflective.getShort(field);
}
/**
* Gets the value of an instance <code>short</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>short</code> value
* from
* @return the value of the <code>short</code> field
*/
public static short getShort(Field field, Object obj) {
return Reflective.getShort(field, obj);
}
/**
* Gets the value of a static <code>int</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>int</code> field
*/
public static int getInt(Field field) {
return Reflective.getInt(field);
}
/**
* Gets the value of an instance <code>int</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>int</code> value
* from
* @return the value of the <code>int</code> field
*/
public static int getInt(Field field, Object obj) {
return Reflective.getInt(field, obj);
}
/**
* Gets the value of a static <code>long</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>long</code> field
*/
public static long getLong(Field field) {
return Reflective.getLong(field);
}
/**
* Gets the value of an instance <code>long</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>long</code> value
* from
* @return the value of the <code>long</code> field
*/
public static long getLong(Field field, Object obj) {
return Reflective.getLong(field, obj);
}
/**
* Gets the value of a static <code>float</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>float</code> field
*/
public static float getFloat(Field field) {
return Reflective.getFloat(field);
}
/**
* Gets the value of an instance <code>float</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>float</code> value
* from
* @return the value of the <code>float</code> field
*/
public static float getFloat(Field field, Object obj) {
return Reflective.getFloat(field, obj);
}
/**
* Gets the value of a static <code>double</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>double</code> field
*/
public static double getDouble(Field field) {
return Reflective.getDouble(field);
}
/**
* Gets the value of an instance <code>double</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>double</code> value
* from
* @return the value of the <code>double</code> field
*/
public static double getDouble(Field field, Object obj) {
return Reflective.getDouble(field, obj);
}
/**
* Gets the value of a static <code>boolean</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>boolean</code> field
*/
public static boolean getBoolean(Field field) {
return Reflective.getBoolean(field);
}
/**
* Gets the value of an instance <code>boolean</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>boolean</code> value
* from
* @return the value of the <code>boolean</code> field
*/
public static boolean getBoolean(Field field, Object obj) {
return Reflective.getBoolean(field, obj);
}
/**
* Gets the value of a static <code>char</code> field.
*
* @param field Field object whose value is returned.
* @return the value of the <code>char</code> field
*/
public static char getChar(Field field) {
return Reflective.getChar(field);
}
/**
* Gets the value of an instance <code>char</code> field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the <code>char</code> value
* from
* @return the value of the <code>char</code> field
*/
public static char getChar(Field field, Object obj) {
return Reflective.getChar(field, obj);
}
/**
* Gets the value of a static reference field.
*
* @param field Field object whose value is returned.
* @return the value of the reference field
*/
public static Object get(Field field) {
return Reflective.get(field);
}
/**
* Gets the value of an instance reference field.
*
* @param field Field object whose value is returned.
* @param obj the object to extract the reference value
* from
* @return the value of the reference field
*/
public static Object get(Field field, Object obj) {
return Reflective.get(field, obj);
}
// weak, soft references
/**
* Creates and returns a weak reference to the given object.
*
* @param obj object for which a weak reference is created.
* @return a weak reference to the given object.
*/
public static WeakReference weakRef(Object obj) {
return References.weakRef(obj);
}
/**
* Creates and returns a soft reference to the given object.
*
* @param obj object for which a soft reference is created.
* @return a soft reference to the given object.
*/
public static SoftReference softRef(Object obj) {
return References.softRef(obj);
}
/**
* Returns the given reference object's referent. If the reference object has
* been cleared, either by the program or by the garbage collector, then
* this method returns <code>null</code>.
*
* @param ref reference object whose referent is returned.
* @return The object to which the reference refers, or
* <code>null</code> if the reference object has been cleared.
*/
public static Object deref(Reference ref) {
return References.deref(ref);
}
// probe point access
/**
* Returns the Class object of the currently
* probed (or traced) class.
* @deprecated Since 1.1. Use {@linkplain ProbeClassName} and {@linkplain Self} annotations instead
*/
@Deprecated
public static Class probeClass() {
return Reflection.getCallerClass(STACK_DEC);
}
/**
* Returns the currently probed method's name.
* @deprecated Since 1.1. Use {@linkplain ProbeMethodName} annotation instead
*/
@Deprecated
public static String probeMethod() {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
if (stack.length >= 4) {
return stack[3].getMethodName();
} else {
return null;
}
}
/**
* Returns the currently probed source line number (if available).
*/
public static int probeLine() {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
if (stack.length >= 4) {
return stack[3].getLineNumber();
} else {
return -1;
}
}
// printing values
/**
* Prints the given Map.
*
* @param map Map that is printed.
*/
public static void printMap(Map map) {
BTraceRuntime.printMap(map);
}
/**
* Prints the given Map.
*
* @param name - the name of the map
* @param data - the map data
*/
public static void printStringMap(String name, Map<String,String> data) {
BTraceRuntime.printStringMap(name, data);
}
/**
* Prints the given Map.
*
* @param name - the name of the map
* @param data - the map data
*/
public static void printNumberMap(String name, Map<String, ? extends Number> data) {
BTraceRuntime.printNumberMap(name, data);
}
/**
* Prints a number.
*
* @param name - name of the number data
* @param value - value of the numerical data
*/
public static void printNumber(String name, Number value) {
BTraceRuntime.printNumber(name, value);
}
/**
* Prints the elements of the given array as comma
* separated line bounded by '[' and ']'.
*/
public static void printArray(Object[] array) {
StringBuilder buf = new StringBuilder();
buf.append('[');
for (Object obj : array) {
buf.append(Strings.str(obj));
buf.append(", ");
}
buf.append(']');
println(buf.toString());
}
/**
* Prints the elements of the given array as comma
* separated line bounded by '[' and ']'.
* @since 1.3.11
*/
public static void printArray(int[] array) {
println(Arrays.toString(array));
}
/**
* Prints the elements of the given array as comma
* separated line bounded by '[' and ']'.
* @since 1.3.11
*/
public static void printArray(long[] array) {
println(Arrays.toString(array));
}
/**
* Prints the elements of the given array as comma
* separated line bounded by '[' and ']'.
* @since 1.3.11
*/
public static void printArray(float[] array) {
println(Arrays.toString(array));
}
/**
* Prints the elements of the given array as comma
* separated line bounded by '[' and ']'.
* @since 1.3.11
*/
public static void printArray(double[] array) {
println(Arrays.toString(array));
}
/**
* Prints the elements of the given array as comma
* separated line bounded by '[' and ']'.