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: // The Initial Developer of the Original Code is Angela Nicoara. Portions
017: // created by Angela Nicoara are Copyright (C) 2002 Angela Nicoara.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id$
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.prose.jvmai.jikesrvm.advice_weaver;
028:
029: import java.lang.reflect.Field;
030:
031: import ch.ethz.jvmai.FieldJoinPoint;
032:
033: import com.ibm.JikesRVM.classloader.*;
034:
035: /**
036: * Concrete implementation of a CodeJoinPoint for the Jikes RVM.
037: *
038: * @version $Revision$
039: * @author Johann Gyger
040: * @author Angela Nicoara
041: */
042: public class FieldJoinPointImpl extends CodeJoinPointImpl implements
043: FieldJoinPoint {
044:
045: /**
046: * Field identifier to which this join point belongs.
047: */
048: public int fieldId;
049:
050: /**
051: * Field to which this join point belongs.
052: */
053: public Field field;
054:
055: /**
056: * Owner of `field'.
057: */
058: public Object owner;
059:
060: /**
061: * Field value for `owner';
062: */
063: public Object value;
064:
065: public void init(int id, Object tag, Object this 0, Object[] args,
066: int fieldId, Object owner) {
067: init(id, tag, this 0, args);
068: this .fieldId = fieldId;
069: field = null;
070: this .owner = owner;
071: value = null;
072: }
073:
074: /**
075: * The target of a field join point differs from the target of a code join
076: * point: It is actually the owner of the field. See
077: * {@link com.ibm.JikesRVM.VM_JVMAI#getFieldTarget()}for more information.
078: */
079: public Object getTarget() {
080: return owner;
081: }
082:
083: public Field getField() {
084: if (field == null) {
085: VM_Field f = VM_FieldReference.getMemberRef(fieldId)
086: .asFieldReference().resolve();
087: return java.lang.reflect.JikesRVMSupport.createField(f);
088: }
089:
090: return field;
091: }
092:
093: public Object getValue() {
094: if (value == null) {
095: VM_Field f = VM_FieldReference.getMemberRef(fieldId)
096: .asFieldReference().resolve();
097: VM_TypeReference type = f.getType();
098: if (type.isReferenceType()) {
099: value = f.getObjectValueUnchecked(owner);
100: } else if (type.isCharType()) {
101: value = new Character(f.getCharValueUnchecked(owner));
102: } else if (type.isDoubleType()) {
103: value = new Double(f.getDoubleValueUnchecked(owner));
104: } else if (type.isFloatType()) {
105: value = new Float(f.getFloatValueUnchecked(owner));
106: } else if (type.isLongType()) {
107: value = new Long(f.getLongValueUnchecked(owner));
108: } else if (type.isIntType()) {
109: value = new Integer(f.getIntValueUnchecked(owner));
110: } else if (type.isShortType()) {
111: value = new Short(f.getShortValueUnchecked(owner));
112: } else if (type.isByteType()) {
113: value = new Byte(f.getByteValueUnchecked(owner));
114: } else if (type.isBooleanType()) {
115: value = new Boolean(f.getBooleanValueUnchecked(owner));
116: } else {
117: throw new InternalError(
118: "Huh? Field of unknown primitive type " + type);
119: }
120: }
121:
122: return value;
123: }
124:
125: }
126:
127: //======================================================================
128: //
129: // $Log$
130: //
|