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 java.lang.reflect.Field;
026:
027: import ch.ethz.jvmai.JVMAIRuntimeException;
028: import ch.ethz.jvmai.FieldJoinPoint;
029:
030: /**
031: * Concrete implementation of a CodeJoinPoint for the Jikes RVM.
032: *
033: * @author Angela Nicoara
034: * @author Johann Gyger
035: * @version $Revision$
036: */
037: public class HotSwapFieldJoinPointImpl extends HotSwapJoinPointImpl
038: implements FieldJoinPoint {
039:
040: /**
041: * Field identifier to which this join point belongs.
042: */
043: public int fieldId;
044:
045: /**
046: * Field to which this join point belongs.
047: */
048: public Field field;
049:
050: /**
051: * Owner of `field'.
052: */
053: public Object owner;
054:
055: /**
056: * Field value for `owner';
057: */
058: public Object value;
059:
060: /**
061: * Constructs an uninitialized instance.
062: * To use it {@link #init} must be called
063: * after construction.
064: */
065: HotSwapFieldJoinPointImpl() {
066: super ();
067: }
068:
069: /**
070: * Constructs an initialized instance.
071: * @param tag AOP tag associated with this join point.
072: * @param fieldId unique numerical identifier for the target field.
073: * @param owner Object owning the field.
074: */
075: HotSwapFieldJoinPointImpl(Object tag, int fieldId, Object owner) {
076: super (tag, 0);
077: this .fieldId = fieldId;
078: this .owner = owner;
079: }
080:
081: /**
082: * Initializes this instance.
083: * @param tag AOP tag associated with this join point.
084: * @param fieldId unique numerical identifier for the target field.
085: * @param owner Object owning the field.
086: */
087: public void init(Object tag, int fieldId, Object owner) {
088: init(tag);
089: this .fieldId = fieldId;
090: field = null;
091: this .owner = owner;
092: value = null;
093: }
094:
095: /**
096: * The target of a field join point differs from the target of a code join
097: * point: It is actually the owner of the field.
098: */
099: public Object getTarget() {
100: return owner;
101: }
102:
103: public Field getField() {
104: if (field == null)
105: field = HotSwapFieldWeaver.idToField(fieldId);
106: return field;
107: }
108:
109: public Object getValue() {
110: if (value == null) {
111: Field f = getField();
112: // Make the field accessible if it's private or protected.
113: // There's no reset after access, because repeated
114: // accessses to this field are very likely.
115: if (!f.isAccessible())
116: ;
117: f.setAccessible(true);
118: try {
119: value = f.get(owner);
120: }
121: // If this handler is reached, something went wrong at
122: // the f.isAccessible() or f.setAccessible() call above.
123: catch (IllegalAccessException e) {
124: throw new JVMAIRuntimeException(
125: "Illigal field access: this should never happen");
126: }
127: }
128: return value;
129: }
130:
131: public String getKind() {
132: return FieldJoinPoint.KIND;
133: }
134:
135: public int getMask() {
136: return MASK_CODE_JP | MASK_FIELD_JP;
137: }
138:
139: /**
140: * @deprecated use getField().getDeclaringClass() instead
141: */
142: public Class getTargetClass() {
143: return getField().getDeclaringClass();
144: }
145:
146: }
147:
148: //======================================================================
149: //
150: //$Log$
151: //
|