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.TCObject;
07: import com.tc.object.bytecode.ManagerUtil;
08:
09: public class JavaLangArrayHelpers {
10: public static final String CLASS = "com/tc/object/bytecode/hook/impl/JavaLangArrayHelpers";
11:
12: /**
13: * Optimization used by String.getChars(int, int, char[], int)
14: */
15: public static void charArrayCopy(char[] src, int srcPos,
16: char[] dest, int destPos, int length) {
17: TCObject tco = ManagerUtil.getObject(dest);
18: if (tco != null) {
19: ManagerUtil.charArrayCopy(src, srcPos, dest, destPos,
20: length, tco);
21: } else {
22: System.arraycopy(src, srcPos, dest, destPos, length);
23: }
24: }
25:
26: /**
27: * The entire implementation of String.getBytes() is replaced by a call to this method
28: */
29: public static void javaLangStringGetBytes(int srcBegin, int srcEnd,
30: byte dst[], int dstBegin, int count, int offset,
31: char[] value) {
32: if (srcBegin < 0) {
33: throw new StringIndexOutOfBoundsException(srcBegin);
34: }
35: if (srcEnd > count) {
36: throw new StringIndexOutOfBoundsException(srcEnd);
37: }
38: if (srcBegin > srcEnd) {
39: throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
40: }
41: int j = dstBegin;
42: int n = offset + srcEnd;
43: int i = offset + srcBegin;
44: char[] val = value;
45:
46: TCObject tco = ManagerUtil.getObject(dst);
47: if (tco != null) {
48: while (i < n) {
49: dst[j] = (byte) val[i++];
50: tco.byteFieldChanged(null, null, dst[j], j++);
51: }
52: } else {
53: while (i < n) {
54: dst[j++] = (byte) val[i++];
55: }
56: }
57: }
58:
59: /**
60: * Called by the 1.5 implementation of java/lang/AbstractStringBuilder.append(int|long)
61: */
62: public static void javaLangAbstractStringBuilderAppend(
63: char[] value, int appendLength, int bufferLength) {
64: TCObject tco = ManagerUtil.getObject(value);
65:
66: if (tco != null) {
67: int index = bufferLength - appendLength;
68:
69: while (index < bufferLength) {
70: tco.charFieldChanged(null, null, value[index], index++);
71: }
72: }
73: }
74:
75: }
|