From 6defb4e5a2565f5568cf6c1346001abf99305d51 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Tue, 6 Mar 2012 08:33:16 -0800 Subject: [PATCH] 373195 --- .../context/CompilationAndWeavingContext.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/bridge/src/org/aspectj/bridge/context/CompilationAndWeavingContext.java b/bridge/src/org/aspectj/bridge/context/CompilationAndWeavingContext.java index f011572d9..28a414acd 100644 --- a/bridge/src/org/aspectj/bridge/context/CompilationAndWeavingContext.java +++ b/bridge/src/org/aspectj/bridge/context/CompilationAndWeavingContext.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2005 Contributors. + * Copyright (c) 2005-2012 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 @@ -8,23 +8,22 @@ * * Contributors: * Adrian Colyer Initial implementation + * Andy Clement various fixes + * Trask Stanalker #373195 * ******************************************************************/ package org.aspectj.bridge.context; import java.lang.ref.WeakReference; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Stack; /** - * @author colyer This class is responsible for tracking progress through the various phases of compilation and weaving. When an - * exception occurs (or a message is issued, if desired), you can ask this class for a "stack trace" that gives information - * about what the compiler was doing at the time. The trace will say something like: - * - * when matching pointcut xyz when matching shadow sss when weaving type ABC when weaving shadow mungers - * - * Since we can't use ThreadLocal (have to work on 1.3), we use a map from Thread -> ContextStack. + * This class is responsible for tracking progress through the various phases of compilation and weaving. + * When an exception occurs (or a message is issued, if desired), you can ask this class for a + * "stack trace" that gives information about what the compiler was doing at the time. + * The trace will say something like: + * "when matching pointcut xyz when matching shadow sss when weaving type ABC when weaving shadow mungers" */ public class CompilationAndWeavingContext { @@ -88,8 +87,7 @@ public class CompilationAndWeavingContext { "type munging for @AspectJ aspectOf" }; // context stacks, one per thread - private static Map> contextMap = Collections - .synchronizedMap(new HashMap>()); + private static ThreadLocal> contextMap = new ThreadLocal>(); // single thread mode stack private static Stack contextStack = new Stack(); @@ -109,12 +107,12 @@ public class CompilationAndWeavingContext { public static void reset() { if (!multiThreaded) { - contextMap.clear(); + contextMap.remove(); contextStack.clear(); formatterMap.clear(); nextTokenId = 1; } else { - contextMap.remove(Thread.currentThread()); + contextMap.remove(); // TODO what about formatterMap? // TODO what about nextTokenId? } @@ -160,9 +158,9 @@ public class CompilationAndWeavingContext { * Exit a phase, all stack entries from the one with the given token down will be removed. */ public static void leavingPhase(ContextToken aToken) { - Stack contextStack = getContextStack(); + Stack contextStack = getContextStack(); while (!contextStack.isEmpty()) { - ContextStackEntry entry = (ContextStackEntry) contextStack.pop(); + ContextStackEntry entry = contextStack.pop(); if (entry.contextToken == aToken) { break; } @@ -176,17 +174,17 @@ public class CompilationAndWeavingContext { if (!multiThreaded) { return; } - contextMap.remove(Thread.currentThread()); + contextMap.remove(); } private static Stack getContextStack() { if (!multiThreaded) { return contextStack; } else { - Stack contextStack = contextMap.get(Thread.currentThread()); + Stack contextStack = contextMap.get(); if (contextStack == null) { contextStack = new Stack(); - contextMap.put(Thread.currentThread(), contextStack); + contextMap.set(contextStack); } return contextStack; } -- 2.39.5