# HG changeset patch # User Christian Wimmer # Date 1328744201 28800 # Node ID ade4281b79c34e3c0f1bb26a9a11542f2fa534f0 # Parent cf13124efdd9e80a2da534a3971f09199dfdb442 Remove obsolete CompilationObserver diff -r cf13124efdd9 -r ade4281b79c3 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationEvent.java Wed Feb 08 15:35:21 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.max.graal.compiler.observer; - -import java.util.*; - -/** - * An event that occurred during compilation. Instances of this class provide information about the event and the state - * of the compilation when the event was raised. Depending on the state of the compiler and the compilation phase, - * different types of objects are provided in the {@link #debugObjects}. The observer should filter events that it is - * interested in by checking if an object of a specific type is provided by the event. - */ -public class CompilationEvent { - - /** - * Marker object for the {@link #debugObject} array: When this object is present, the event is the result of a compilation error. - */ - public static final Object ERROR = new Object() {}; - - public final String label; - private List debugObjects; - - protected CompilationEvent(String label, ArrayList debugObjects) { - this.label = label; - this.debugObjects = debugObjects; - } - - @SuppressWarnings("unchecked") - public T debugObject(Class type) { - for (ListIterator iter = debugObjects.listIterator(debugObjects.size()); iter.hasPrevious();) { - Object o = iter.previous(); - if (type.isInstance(o)) { - return (T) o; - } - } - return null; - } - - public boolean hasDebugObject(Object search) { - for (ListIterator iter = debugObjects.listIterator(debugObjects.size()); iter.hasPrevious();) { - Object o = iter.previous(); - if (o == search) { - return true; - } - } - return false; - } -} diff -r cf13124efdd9 -r ade4281b79c3 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationObserver.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/CompilationObserver.java Wed Feb 08 15:35:21 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.max.graal.compiler.observer; - - -/** - * Interface for classes that observe events of an {@link ObservableCompiler}. - */ -public interface CompilationObserver { - - /** - * Called when compilation of a method has started. This is always the first event raised for a particular - * method compilation. - * - * @param event Information associated with the event and current state of the compilation. - */ - void compilationStarted(CompilationEvent event); - - /** - * Called when an event has occurred, for example that a particular phase in the compilation has been entered. - * - * @param event Information associated with the event and current state of the compilation. - */ - void compilationEvent(CompilationEvent event); - - /** - * Called when compilation of a method has completed (successfully or not). This is always the last event raised for - * a particular method compilation. - * - * @param event Information associated with the event and current state of the compilation. - */ - void compilationFinished(CompilationEvent event); - -} diff -r cf13124efdd9 -r ade4281b79c3 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/ObservableContext.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/ObservableContext.java Wed Feb 08 15:35:21 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.max.graal.compiler.observer; - -import java.util.*; - -/** - * Base class for compilers that notify subscribed {@link CompilationObserver CompilationObservers} of - * {@link CompilationEvent CompilationEvents} that occur during their compilations. - */ -public class ObservableContext { - - private List observers; - - private ThreadLocal scopeName = new ThreadLocal() { - @Override - protected StringBuilder initialValue() { - return new StringBuilder(); - } - }; - - private ThreadLocal> debugObjects = new ThreadLocal>() { - @Override - protected ArrayList initialValue() { - return new ArrayList<>(); - } - }; - - /** - * @return {@code true} if one or more observers are subscribed to receive notifications from this compiler, - * {@code false} otherwise. - */ - public boolean isObserved() { - return observers != null; - } - - /** - * Add the specified observer to receive events from this compiler. - * - * @param observer The observer to add. - */ - public void addCompilationObserver(CompilationObserver observer) { - assert observer != null; - - if (observers == null) { - observers = new LinkedList<>(); - } - observers.add(observer); - } - - public void fireCompilationStarted(Object... additionalDebugObjects) { - if (isObserved()) { - addDebugObjects(null, additionalDebugObjects); - CompilationEvent event = new CompilationEvent("started", debugObjects.get()); - for (CompilationObserver observer : observers) { - observer.compilationStarted(event); - } - removeDebugObjects(null, additionalDebugObjects); - } - } - - public void fireCompilationEvent(String label, Object... additionalDebugObjects) { - if (isObserved()) { - addDebugObjects(null, additionalDebugObjects); - CompilationEvent event = new CompilationEvent(label, debugObjects.get()); - for (CompilationObserver observer : observers) { - observer.compilationEvent(event); - } - removeDebugObjects(null, additionalDebugObjects); - } - } - - public void fireCompilationFinished(Object... additionalDebugObjects) { - if (isObserved()) { - addDebugObjects(null, additionalDebugObjects); - CompilationEvent event = new CompilationEvent("finished", debugObjects.get()); - for (CompilationObserver observer : observers) { - observer.compilationFinished(event); - } - removeDebugObjects(null, additionalDebugObjects); - } - } - - /** - * Remove the specified observer so that it no longer receives events from this compiler. - * - * @param observer The observer to remove. - */ - public void removeCompilationObserver(CompilationObserver observer) { - if (observers != null) { - observers.remove(observer); - if (observers.size() == 0) { - observers = null; - } - } - } - - public void clear() { - if (observers != null) { - observers = null; - } - } - - public void addDebugObjects(String name, Object[] additionalDebugObjects) { - if (name != null) { - if (scopeName.get().length() > 0) { - scopeName.get().append('.'); - } - scopeName.get().append(name); - } - for (Object obj : additionalDebugObjects) { - debugObjects.get().add(obj); - } - } - - public void removeDebugObjects(String name, Object[] additionalDebugObjects) { - if (name != null) { - scopeName.get().setLength(Math.max(0, scopeName.get().length() - name.length())); - } - for (int i = 0; i < additionalDebugObjects.length; i++) { - debugObjects.get().remove(debugObjects.get().size() - 1); - } - } -} diff -r cf13124efdd9 -r ade4281b79c3 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/package-info.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/package-info.java Wed Feb 08 15:35:21 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * Classes and interfaces for observing compilations. - */ -package com.oracle.max.graal.compiler.observer;