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 Andrei Popovici. Portions
017: // created by Andrei Popovici are Copyright (C) 2002 Andrei Popovici.
018: // All Rights Reserved.
019: //
020: // Contributor(s):
021: // $Id: ControlFlow.java,v 1.2 2004/05/12 09:41:54 anicoara Exp $
022: // =====================================================================
023: //
024: // (history at end)
025: //
026:
027: package ch.ethz.inf.iks.jvmai.jvmdi;
028:
029: // used packages
030: import java.util.*;
031:
032: /**
033: * Class ControlFlow encapsulates <em>thread local</em> information needed
034: * by the jvmai. Each thread will be associated via the ThreadLocalVariable
035: * AspectInterfaceImpl.cflows with an instance of <code>ControlFlow</code>.
036: * <p>
037: * With this, the need for <creating> joinpoints when they are needed
038: * is elimiated (hence no garbage collection artificially incurred by
039: * this JVMAI implementation.
040: * <p>
041: * The control flow contains AT LEAST a pointer to a join-point object
042: * of each kind. The thread-local join-points must be instantiated
043: * such that they all point to a <code>JoinPointContext</code> object
044: * which, again, belongs to this controlflow.
045: *
046: * @version $Revision: 1.2 $
047: * @author Andrei Popovici
048: */
049: public class ControlFlow {
050:
051: private SortedMap aopMap;
052: private JoinPointContext currentContext;
053: private MethodExecutionJoinPointImpl executionJoinPoint;
054: private FieldAccessJoinPointImpl getJoinPoint;
055: private FieldModificationJoinPointImpl setJoinPoint;
056: private ExceptionJoinPointImpl throwJoinPoint;
057: private ExceptionCatchJoinPointImpl catchJoinPoint;
058:
059: /** Create a standard control flow */
060: public ControlFlow() {
061: aopMap = new TreeMap();
062: currentContext = new JoinPointContext();
063: executionJoinPoint = new MethodExecutionJoinPointImpl(this ,
064: currentContext);
065: getJoinPoint = new FieldAccessJoinPointImpl(this ,
066: currentContext);
067: setJoinPoint = new FieldModificationJoinPointImpl(this ,
068: currentContext);
069: throwJoinPoint = new ExceptionJoinPointImpl(this ,
070: currentContext);
071: catchJoinPoint = new ExceptionCatchJoinPointImpl(this ,
072: currentContext);
073: }
074:
075: protected Collection getAopTags(CodeJoinPointImpl jp) {
076: SortedMap headMap = aopMap.headMap(valueOf(jp.context.depth));
077: return headMap.values();
078: }
079:
080: protected void pushJoinPoint(CodeJoinPointImpl cjp) {
081: aopMap.put(valueOf(currentContext.depth), cjp.getAopTag());
082: }
083:
084: protected void popJoinPoint(int depth) {
085:
086: Integer intKey = valueOf(depth);
087:
088: Integer lastKey = (Integer) aopMap.lastKey();
089:
090: if (lastKey.equals(intKey))
091: aopMap.remove(lastKey);
092: else {
093: SortedMap tail = aopMap.tailMap(intKey);
094: Iterator i = tail.keySet().iterator();
095: while (i.hasNext()) {
096: aopMap.remove(i.next());
097: }
098: }
099: }
100:
101: private static Integer[] first100Integers;
102:
103: private Integer valueOf(int x) {
104: if (first100Integers == null) {
105: first100Integers = new Integer[100];
106: for (int i = 0; i < 100; i++)
107: first100Integers[i] = new Integer(i);
108: }
109:
110: if (x < 100)
111: return first100Integers[x];
112: else
113: return new Integer(x);
114: }
115:
116: }
117:
118: //======================================================================
119: //
120: // $Log: ControlFlow.java,v $
121: // Revision 1.2 2004/05/12 09:41:54 anicoara
122: // Remove the README.RVM file
123: //
124: // Revision 1.1.1.1 2003/07/02 15:30:50 apopovic
125: // Imported from ETH Zurich
126: //
127: // Revision 1.5 2003/07/02 12:42:45 anicoara
128: // Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
129: //
130: // Revision 1.4 2003/05/06 15:51:13 popovici
131: // Mozilla-ification
132: //
133: // Revision 1.3 2003/05/05 17:46:23 popovici
134: // Refactorization step (runes->prose) cleanup
135: //
136: // Revision 1.2 2003/03/04 16:09:32 popovici
137: // Documentation improvements
138: //
139: // Revision 1.1 2003/03/04 11:26:22 popovici
140: // Important refactorization step (march):
141: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
142: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
143: // structures
144: //
|