Wed, 21 Sep 2011 21:56:53 -0700
7092965: javac should not close processorClassLoader before end of compilation
Reviewed-by: darcy
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.comp; |
duke@1 | 27 | |
jjg@119 | 28 | import java.util.AbstractQueue; |
jjg@119 | 29 | import com.sun.tools.javac.util.Context; |
jjg@119 | 30 | import java.util.HashMap; |
jjg@119 | 31 | import java.util.Iterator; |
jjg@119 | 32 | import java.util.LinkedList; |
jjg@119 | 33 | import java.util.Map; |
jjg@119 | 34 | import java.util.Queue; |
jjg@119 | 35 | import javax.tools.JavaFileObject; |
duke@1 | 36 | |
duke@1 | 37 | /** A queue of all as yet unattributed classes. |
duke@1 | 38 | * |
jjg@581 | 39 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 40 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 41 | * This code and its internal interfaces are subject to change or |
duke@1 | 42 | * deletion without notice.</b> |
duke@1 | 43 | */ |
jjg@119 | 44 | public class Todo extends AbstractQueue<Env<AttrContext>> { |
duke@1 | 45 | /** The context key for the todo list. */ |
duke@1 | 46 | protected static final Context.Key<Todo> todoKey = |
duke@1 | 47 | new Context.Key<Todo>(); |
duke@1 | 48 | |
duke@1 | 49 | /** Get the Todo instance for this context. */ |
duke@1 | 50 | public static Todo instance(Context context) { |
duke@1 | 51 | Todo instance = context.get(todoKey); |
duke@1 | 52 | if (instance == null) |
duke@1 | 53 | instance = new Todo(context); |
duke@1 | 54 | return instance; |
duke@1 | 55 | } |
duke@1 | 56 | |
duke@1 | 57 | /** Create a new todo list. */ |
duke@1 | 58 | protected Todo(Context context) { |
duke@1 | 59 | context.put(todoKey, this); |
duke@1 | 60 | } |
jjg@119 | 61 | |
jjg@119 | 62 | public void append(Env<AttrContext> env) { |
jjg@119 | 63 | add(env); |
jjg@119 | 64 | } |
jjg@119 | 65 | |
jjg@119 | 66 | @Override |
jjg@119 | 67 | public Iterator<Env<AttrContext>> iterator() { |
jjg@119 | 68 | return contents.iterator(); |
jjg@119 | 69 | } |
jjg@119 | 70 | |
jjg@119 | 71 | @Override |
jjg@119 | 72 | public int size() { |
jjg@119 | 73 | return contents.size(); |
jjg@119 | 74 | } |
jjg@119 | 75 | |
jjg@119 | 76 | public boolean offer(Env<AttrContext> e) { |
jjg@119 | 77 | if (contents.add(e)) { |
jjg@119 | 78 | if (contentsByFile != null) |
jjg@119 | 79 | addByFile(e); |
jjg@119 | 80 | return true; |
jjg@119 | 81 | } else { |
jjg@119 | 82 | return false; |
jjg@119 | 83 | } |
jjg@119 | 84 | } |
jjg@119 | 85 | |
jjg@119 | 86 | public Env<AttrContext> poll() { |
jjg@119 | 87 | if (size() == 0) |
jjg@119 | 88 | return null; |
jjg@119 | 89 | Env<AttrContext> env = contents.remove(0); |
jjg@119 | 90 | if (contentsByFile != null) |
jjg@119 | 91 | removeByFile(env); |
jjg@119 | 92 | return env; |
jjg@119 | 93 | } |
jjg@119 | 94 | |
jjg@119 | 95 | public Env<AttrContext> peek() { |
jjg@119 | 96 | return (size() == 0 ? null : contents.get(0)); |
jjg@119 | 97 | } |
jjg@119 | 98 | |
jjg@119 | 99 | public Queue<Queue<Env<AttrContext>>> groupByFile() { |
jjg@119 | 100 | if (contentsByFile == null) { |
jjg@119 | 101 | contentsByFile = new LinkedList<Queue<Env<AttrContext>>>(); |
jjg@119 | 102 | for (Env<AttrContext> env: contents) { |
jjg@119 | 103 | addByFile(env); |
jjg@119 | 104 | } |
jjg@119 | 105 | } |
jjg@119 | 106 | return contentsByFile; |
jjg@119 | 107 | } |
jjg@119 | 108 | |
jjg@119 | 109 | private void addByFile(Env<AttrContext> env) { |
jjg@119 | 110 | JavaFileObject file = env.toplevel.sourcefile; |
jjg@119 | 111 | if (fileMap == null) |
jjg@119 | 112 | fileMap = new HashMap<JavaFileObject, FileQueue>(); |
jjg@119 | 113 | FileQueue fq = fileMap.get(file); |
jjg@119 | 114 | if (fq == null) { |
jjg@119 | 115 | fq = new FileQueue(); |
jjg@119 | 116 | fileMap.put(file, fq); |
jjg@119 | 117 | contentsByFile.add(fq); |
jjg@119 | 118 | } |
jjg@119 | 119 | fq.fileContents.add(env); |
jjg@119 | 120 | } |
jjg@119 | 121 | |
jjg@119 | 122 | private void removeByFile(Env<AttrContext> env) { |
jjg@119 | 123 | JavaFileObject file = env.toplevel.sourcefile; |
jjg@119 | 124 | FileQueue fq = fileMap.get(file); |
jjg@119 | 125 | if (fq == null) |
jjg@119 | 126 | return; |
jjg@119 | 127 | if (fq.fileContents.remove(env)) { |
jjg@119 | 128 | if (fq.isEmpty()) { |
jjg@119 | 129 | fileMap.remove(file); |
jjg@119 | 130 | contentsByFile.remove(fq); |
jjg@119 | 131 | } |
jjg@119 | 132 | } |
jjg@119 | 133 | } |
jjg@119 | 134 | |
jjg@119 | 135 | LinkedList<Env<AttrContext>> contents = new LinkedList<Env<AttrContext>>(); |
jjg@119 | 136 | LinkedList<Queue<Env<AttrContext>>> contentsByFile; |
jjg@119 | 137 | Map<JavaFileObject, FileQueue> fileMap; |
jjg@119 | 138 | |
jjg@119 | 139 | class FileQueue extends AbstractQueue<Env<AttrContext>> { |
jjg@119 | 140 | @Override |
jjg@119 | 141 | public Iterator<Env<AttrContext>> iterator() { |
jjg@119 | 142 | return fileContents.iterator(); |
jjg@119 | 143 | } |
jjg@119 | 144 | |
jjg@119 | 145 | @Override |
jjg@119 | 146 | public int size() { |
jjg@119 | 147 | return fileContents.size(); |
jjg@119 | 148 | } |
jjg@119 | 149 | |
jjg@119 | 150 | public boolean offer(Env<AttrContext> e) { |
jjg@119 | 151 | if (fileContents.offer(e)) { |
jjg@119 | 152 | contents.add(e); |
jjg@119 | 153 | return true; |
jjg@119 | 154 | } |
jjg@119 | 155 | return false; |
jjg@119 | 156 | } |
jjg@119 | 157 | |
jjg@119 | 158 | public Env<AttrContext> poll() { |
jjg@119 | 159 | if (fileContents.size() == 0) |
jjg@119 | 160 | return null; |
jjg@119 | 161 | Env<AttrContext> env = fileContents.remove(0); |
jjg@119 | 162 | contents.remove(env); |
jjg@119 | 163 | return env; |
jjg@119 | 164 | } |
jjg@119 | 165 | |
jjg@119 | 166 | public Env<AttrContext> peek() { |
jjg@119 | 167 | return (fileContents.size() == 0 ? null : fileContents.get(0)); |
jjg@119 | 168 | } |
jjg@119 | 169 | |
jjg@119 | 170 | LinkedList<Env<AttrContext>> fileContents = new LinkedList<Env<AttrContext>>(); |
jjg@119 | 171 | } |
duke@1 | 172 | } |