langtools/test/tools/javac/scope/HashCollisionTest.java
author jlahoda
Wed, 03 Dec 2014 13:46:12 +0100
changeset 27857 7e913a535736
parent 27224 228abfa87080
child 30730 d3ce7619db2c
permissions -rw-r--r--
7101822: Compiling depends on order of imports 7177813: Static import to local nested class fails Summary: MemberEnter overhaul - TypeEnter is split out of MemberEnter; the TypeEnter consists of several Phases which ensure actions are done in the correct order. Reviewed-by: mcimadamore, jfranck, aeremeev Contributed-by: jan.lahoda@oracle.com, maurizio.cimadamore@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     1
/*
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     4
 *
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     8
 *
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    13
 * accompanied this code).
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    14
 *
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    18
 *
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    21
 * questions.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    22
 */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    23
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    24
/*
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    25
 * @test
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    26
 * @bug 7004029
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    27
 * @summary Ensure Scope impl can cope with hash collisions
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    28
 * @library /tools/javac/lib
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    29
 * @build DPrinter HashCollisionTest
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    30
 * @run main HashCollisionTest
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    31
 */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    32
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    33
import java.lang.reflect.*;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    34
import java.io.*;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    35
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    36
import com.sun.source.util.Trees;
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    37
import com.sun.tools.javac.api.JavacTrees;
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    38
import com.sun.tools.javac.util.*;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    39
import com.sun.tools.javac.code.*;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    40
import com.sun.tools.javac.code.Scope.*;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    41
import com.sun.tools.javac.code.Symbol.*;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    42
import com.sun.tools.javac.file.JavacFileManager;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    43
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25443
diff changeset
    44
import static com.sun.tools.javac.code.Kinds.Kind.*;
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25443
diff changeset
    45
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    46
public class HashCollisionTest {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    47
    public static void main(String... args) throws Exception {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    48
        new HashCollisionTest().run();
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    49
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    50
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    51
    void run() throws Exception {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    52
        // set up basic environment for test
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    53
        Context context = new Context();
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    54
        JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    55
        names = Names.instance(context);       // Name.Table impls tied to an instance of Names
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    56
        symtab = Symtab.instance(context);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    57
        trees = JavacTrees.instance(context);
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents: 27224
diff changeset
    58
        types = Types.instance(context);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    59
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    60
        // determine hashMask for an empty scope
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    61
        Scope emptyScope = WriteableScope.create(symtab.unnamedPackage); // any owner will do
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    62
        Field field = emptyScope.getClass().getDeclaredField("hashMask");
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    63
        field.setAccessible(true);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
    64
        scopeHashMask = field.getInt(emptyScope);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    65
        log("scopeHashMask: " + scopeHashMask);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    66
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    67
        // 1. determine the Name.hashCode of "Entry", and therefore the index of
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    68
        // Entry in an empty scope.  i.e. name.hashCode() & Scope.hashMask
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    69
        Name entry = names.fromString("Entry");
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    70
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    71
        // 2. create names of the form *$Entry until we find a name with a
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    72
        // hashcode which yields the same index as Entry in an empty scope.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    73
        // Since Name.hashCode is a function of position (and not content) it
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    74
        // should work to create successively longer names until one with the
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    75
        // desired characteristics is found.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    76
        Name outerName;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    77
        Name innerName;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    78
        StringBuilder sb = new StringBuilder("C");
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    79
        int i = 0;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    80
        do {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    81
            sb.append(Integer.toString(i % 10));
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    82
            innerName = names.fromString(sb + "$Entry");
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    83
        } while (!clash(entry, innerName) && (++i) < MAX_TRIES);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    84
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    85
        if (clash(entry, innerName)) {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    86
            log("Detected expected hash collision for " + entry + " and " + innerName
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    87
                    + " after " + i + " tries");
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    88
        } else {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    89
            throw new Exception("No potential collision found after " + i + " tries");
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    90
        }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    91
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    92
        outerName = names.fromString(sb.toString());
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    93
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    94
        /*
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    95
         * Now we can set up the scenario.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    96
         */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    97
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    98
        // 3. Create a nested class named Entry
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
    99
        ClassSymbol cc = createClass(names.fromString("C"), symtab.unnamedPackage);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   100
        ClassSymbol ce = createClass(entry, cc);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   101
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   102
        // 4. Create a package containing a nested class using the name from 2
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   103
        PackageSymbol p = new PackageSymbol(names.fromString("p"), symtab.rootPackage);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   104
        p.members_field = WriteableScope.create(p);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   105
        ClassSymbol inner = createClass(innerName, p);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   106
        // we'll need this later when we "rename" cn
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   107
        ClassSymbol outer = createClass(outerName, p);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   108
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   109
        // 5. Create a star-import scope
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   110
        log ("createStarImportScope");
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   111
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   112
        PackageSymbol pkg = new PackageSymbol(names.fromString("pkg"), symtab.rootPackage);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   113
        StarImportScope starImportScope = new StarImportScope(pkg);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   114
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   115
        dump("initial", starImportScope);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   116
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   117
        // 6. Insert the contents of the package from 4.
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   118
        Scope fromScope = p.members();
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   119
        ImportFilter typeFilter = new ImportFilter() {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   120
            @Override
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   121
            public boolean accepts(Scope origin, Symbol sym) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25443
diff changeset
   122
                return sym.kind == TYP;
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   123
            }
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   124
        };
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents: 27224
diff changeset
   125
        starImportScope.importAll(types, fromScope, typeFilter, false);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   126
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   127
        dump("imported p", starImportScope);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   128
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   129
        // 7. Insert the class from 3.
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents: 27224
diff changeset
   130
        starImportScope.importAll(types, cc.members_field, typeFilter, false);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   131
        dump("imported ce", starImportScope);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   132
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   133
        /*
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   134
         * Set the trap.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   135
         */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   136
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   137
        // 8. Rename the nested class to Entry. so that there is a bogus entry in the star-import scope
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   138
        p.members_field.remove(inner);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   139
        inner.name = entry;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   140
        inner.owner = outer;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   141
        outer.members_field.enter(inner);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   142
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   143
        // 9. Lookup Entry
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   144
        Symbol found = starImportScope.findFirst(entry);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   145
        if (found != ce)
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   146
            throw new Exception("correct symbol not found: " + entry + "; found=" + found);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   147
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   148
        dump("final", starImportScope);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   149
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   150
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   151
    /*
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   152
     * Check for a (probable) hash collision in an empty scope.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   153
     */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   154
    boolean clash(Name n1, Name n2) {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   155
        log(n1 + " hc:" + n1.hashCode() + " v:" + (n1.hashCode() & scopeHashMask) + ", " +
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   156
                n2 + " hc:" + n2.hashCode() + " v:" + (n2.hashCode() & scopeHashMask));
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   157
        return (n1.hashCode() & scopeHashMask) == (n2.hashCode() & scopeHashMask);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   158
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   159
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   160
    /**
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   161
     * Create a class symbol, init the members scope, and add it to owner's scope.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   162
     */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   163
    ClassSymbol createClass(Name name, Symbol owner) {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   164
        ClassSymbol sym = new ClassSymbol(0, name, owner);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   165
        sym.members_field = WriteableScope.create(sym);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   166
        if (owner != symtab.unnamedPackage)
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   167
            owner.members().enter(sym);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   168
        return sym;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   169
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   170
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   171
    /**
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   172
     * Dump the contents of a scope to System.err.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   173
     */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   174
    void dump(String label, Scope s) throws Exception {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   175
        PrintWriter pw = new PrintWriter(System.err);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   176
        new DPrinter(pw, trees).printScope(label, s);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   177
        pw.flush();
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   178
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   179
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   180
    Object readField(Object scope, String fieldName) throws Exception {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   181
        Field field = scope.getClass().getDeclaredField(fieldName);
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   182
        field.setAccessible(true);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   183
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   184
        return field.get(scope);
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   185
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   186
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   187
    /**
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   188
     * Write a message to stderr.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   189
     */
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   190
    void log(String msg) {
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   191
        System.err.println(msg);
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   192
    }
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   193
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   194
    int MAX_TRIES = 100; // max tries to find a hash clash before giving up.
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   195
    int scopeHashMask;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   196
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   197
    Names names;
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   198
    Symtab symtab;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 9087
diff changeset
   199
    Trees trees;
27857
7e913a535736 7101822: Compiling depends on order of imports
jlahoda
parents: 27224
diff changeset
   200
    Types types;
7615
8bc078486f2b 7004029: intermittent failures compiling pack200
jjg
parents:
diff changeset
   201
}