01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.bytecode.hook.impl;
05:
06: import com.tc.object.bytecode.Manageable;
07:
08: /**
09: * Helper utility methods
10: */
11: public class Util {
12:
13: private Util() {
14: //
15: }
16:
17: /**
18: * System.exit() without an exception
19: */
20: public static void exit() {
21: exit(null);
22: }
23:
24: /**
25: * Dump an exception and System.exit().
26: * @param t Exception
27: */
28: public static void exit(Throwable t) {
29: if (t != null) {
30: t.printStackTrace(System.err);
31: System.err.flush();
32: }
33:
34: try {
35: Thread.sleep(500);
36: } catch (InterruptedException e) {
37: // ignore
38: }
39:
40: System.exit(1);
41: }
42:
43: /**
44: * This method nulls the TCObject reference in the cloned object if the clone() method had done a shallow copy. This
45: * is called from the instrumented code.
46: * @param original Original object
47: * @param clone Clone of original
48: * @return Clone, modified
49: */
50: public static Object fixTCObjectReferenceOfClonedObject(
51: Object original, Object clone) {
52: if (clone instanceof Manageable
53: && original instanceof Manageable) {
54: Manageable mClone = (Manageable) clone;
55: Manageable mOriginal = (Manageable) original;
56: if (mClone.__tc_managed() != null
57: && clone != original
58: && mClone.__tc_managed() == mOriginal
59: .__tc_managed()) {
60: // A shallow copy is returned. We don't want the clone to have the same TCObject
61: mClone.__tc_managed(null);
62: }
63: }
64: return clone;
65: }
66:
67: }
|