/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/*
* @test
* @bug 7004029
* @summary Ensure Scope impl can cope with hash collisions
*/
public class HashCollisionTest {
new HashCollisionTest().run();
}
// set up basic environment for test
// determine hashMask for an empty scope
sHashMask.setAccessible(true);
// 1. determine the Name.hashCode of "Entry", and therefore the index of
// Entry in an empty scope. i.e. name.hashCode() & Scope.hashMask
// 2. create names of the form *$Entry until we find a name with a
// hashcode which yields the same index as Entry in an empty scope.
// Since Name.hashCode is a function of position (and not content) it
// should work to create successively longer names until one with the
// desired characteristics is found.
int i = 0;
do {
+ " after " + i + " tries");
} else {
}
/*
* Now we can set up the scenario.
*/
// 3. Create a nested class named Entry
// 4. Create a package containing a nested class using the name from 2
p.members_field = new Scope(p);
// we'll need this later when we "rename" cn
// 5. Create a star-import scope
log ("createStarImportScope");
// if StarImportScope exists, use it, otherwise, for testing legacy code,
// fall back on ImportScope
try {
} catch (ClassNotFoundException e) {
}
// 6. Insert the contents of the package from 4.
} else {
// The following lines are taken from MemberEnter.importAll,
// before the use of StarImportScope.importAll.
}
}
// 7. Insert the class from 3.
/*
* Set the trap.
*/
// 8. Rename the nested class to Entry. so that there is a bogus entry in the star-import scope
// 9. Lookup Entry
}
/*
* Check for a (probable) hash collision in an empty scope.
*/
}
/**
* Create a class symbol, init the members scope, and add it to owner's scope.
*/
return sym;
}
/**
* Dump the contents of a scope to System.err.
*/
}
/**
* Dump the contents of a scope to a stream.
*/
sTable.setAccessible(true);
if (i > 0)
}
}
/**
* Create a string showing the contents of an entry, using the table
* to help identify cross-references to other entries in the table.
* @param e the entry to be shown
* @param table the table containing the other entries
*/
if (e == null)
return "null";
return "sent"; // sentinel
if (ref) {
if (index != -1)
}
: "")
+ ")";
}
return i;
}
return -1;
}
/**
* Write a message to stderr.
*/
}
int scopeHashMask;
}