001: //
002: //This file is part of the prose package.
003: //
004: //The contents of this file are subject to the Mozilla Public License
005: //Version 1.1 (the "License"); you may not use this file except in
006: //compliance with the License. You may obtain a copy of the License at
007: //http://www.mozilla.org/MPL/
008: //
009: //Software distributed under the License is distributed on an "AS IS" basis,
010: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: //for the specific language governing rights and limitations under the
012: //License.
013: //
014: //The Original Code is prose.
015: //
016: //Contributor(s):
017: //$Id$
018: //=====================================================================
019: //
020: //(history at end)
021: //
022:
023: package ch.ethz.inf.iks.jvmai.jvmdi;
024:
025: import ch.ethz.jvmai.ConstructorJoinPoint;
026: import java.lang.reflect.Constructor;
027: import java.lang.reflect.Method;
028:
029: /**
030: * HotSwapConstructorJoinPointImpl class.
031: *
032: * @version $Revision$
033: * @author Angela Nicoara
034: * @author Gerald Linhofer
035: */
036: public class HotSwapConstructorJoinPointImpl extends
037: HotSwapMethodEntryJoinPointImpl implements ConstructorJoinPoint {
038:
039: private Constructor constructor;
040:
041: HotSwapConstructorJoinPointImpl() {
042: super ();
043: }
044:
045: HotSwapConstructorJoinPointImpl(Object this 0, int methodId,
046: Object aopTag) {
047: super (methodId, aopTag);
048: target = this 0;
049: }
050:
051: protected void init(Object this 0, int methodId, Object aopTag) {
052: super .init(methodId, aopTag);
053: target = this 0;
054: }
055:
056: public Constructor getConstructor() {
057: if (null == constructor) {
058: constructor = (Constructor) HotSwapClassWeaver
059: .idToMethod(methodId);
060: }
061: return constructor;
062: }
063:
064: public Method getMethod() {
065: return null;
066: }
067:
068: /**
069: * Returns the object on that this join point is executed or the class for
070: * static methods.
071: *
072: * @return Object
073: * @throws IlligalIdException can not find the stack frame of the 'target'.
074: */
075: public Object getThis() {
076: if (null == target)
077: // the first parameter passed to a member method is the 'this' pointer.
078: target = doGetLocalVar(0, ARG_TYPE_OBJECT, Thread
079: .currentThread(), height);
080: return target;
081: }
082:
083: /**
084: * Returns the arguments with that the target method was called.
085: *
086: * @return arguments the method was called with, primitive types
087: * are enclosed in there java types.
088: * @throws IlligalIdException can not find the stack frame of the 'target'.
089: */
090: public Object[] getArgs() {
091: if (gotArgs)
092: return args;
093: if (!argTypesInitialized)
094: initArgTypes();
095:
096: // dont try to get the values, if argument type is 'void'
097: if (0 == args.length)
098: return args;
099:
100: // get argument values
101: doGetLocalVars(2, argTypeCodes, args, Thread.currentThread(),
102: height);
103:
104: gotArgs = true;
105: return args;
106: }
107:
108: /**
109: * Modifies an argument of the target method.
110: *
111: * @param pos position of the parameter (not the slot!)
112: * @param value new value of the argument
113: *
114: * @throws ch.ethz.jvmai.InvalidIdException can not find
115: * the stack frame of the caller in current thread.
116: */
117: public void setArg(int pos, Object value) {
118: if (!argTypesInitialized)
119: initArgTypes();
120: if (argTypeCodes.length < pos)
121: throw new RuntimeException("Invalide argument position");
122: //System.out.println("setArg(" + pos + "," + value + ")");
123: // calculate slot
124: int slot = pos + 2; // first Arg is 'this' second is the caller (SDK 1.5)
125: for (int i = 0; i < pos; i++)
126: slot += (ARG_TYPE_LONG > argTypeCodes[i]) ? 0 : 1;
127: // set argument
128: doSetLocalVar(slot, argTypeCodes[pos], value, Thread
129: .currentThread(), height);
130: args[pos] = value;
131: //System.out.println("setArg() terminated");
132: }
133:
134: /**
135: * Internal method: initializes some member fields, required to get or
136: * set arguments.
137: */
138: protected void initArgTypes() {
139: // Get parameter types
140: argTypes = getConstructor().getParameterTypes();
141: int argLength = argTypes.length;
142:
143: // Allocate or get arrays for the arguments
144: // and there type codes.
145: if (argTypeCodes.length != argLength)
146: if (5 > argLength) {
147: // use a preallocated array
148: args = preAllocatedArgs[argLength];
149: argTypeCodes = preAllocatedCodes[argLength];
150: } else {
151: // allocate a new array
152: args = new Object[argLength];
153: argTypeCodes = new int[argLength];
154: }
155: // fill argTypeCodes (get encoding for all argument types)
156: for (int i = 0; i < argLength; i++) {
157: argTypeCodes[i] = encodeArgType(argTypes[i]);
158: }
159: argTypesInitialized = true;
160: }
161: }
162:
163: //======================================================================
164: //
165: // $Log$
166: //
|