Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/hashcode/HashCodeSimpleTest/HashCodeSimpleTest.java
40948 views
/*1* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key stress26*27* @summary converted from VM Testbase gc/hashcode/HashCodeSimpleTest.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]29* VM Testbase readme:30* DESCRIPTION31* Hash code regressiontests.32*33* COMMENTS34* This test was ported from JRockit test suite.35*36* @library /vmTestbase37* /test/lib38* @run main/othervm -XX:-UseGCOverheadLimit gc.hashcode.HashCodeSimpleTest.HashCodeSimpleTest39*/4041package gc.hashcode.HashCodeSimpleTest;4243import nsk.share.TestFailure;44import nsk.share.gc.GC;45import nsk.share.gc.ThreadedGCTest;4647/**48* Hash code regressiontests.49*/50public class HashCodeSimpleTest extends ThreadedGCTest {5152@Override53protected Runnable createRunnable(int i) {54555657/**58* Test verifies that VM provided hashcodes are constant over invocations.59* @return success if the test passes60* failure if some hashvalue has changed61*/62return new Runnable() {63long counter = 0;646566@Override67public void run() {6869Object object = new Object();70int hashCode0 = object.hashCode();7172for (int i = 0; i < 100; i++) {73int hashCode = object.hashCode();7475if (hashCode != hashCode0) {76throw new TestFailure("Repeated hash code queries broken: "77+ hashCode0 + "!=" + hashCode);78}79}80if (counter++ % 1000000 == 0) {81log.info(counter / 1000000 + " million hashcodes verified");82}838485}86};87}8889public static void main(String args[]) {90GC.runTest(new HashCodeSimpleTest(), args);91}92}939495