test/hotspot/jtreg/vmTestbase/nsk/stress/except/except007.java
author jcbeyler
Wed, 21 Nov 2018 09:38:27 -0800
changeset 52640 3a7d49718852
parent 50169 dd501973095c
permissions -rw-r--r--
8213721: [Graal] Tests vmTestbase/nsk/stress/except/except* may be encountering SEGV during out-of-memory conditions Summary: Add the exception handler only for the current thread Reviewed-by: dholmes, sspitsyn, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     1
/*
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     2
 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     4
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     8
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    13
 * accompanied this code).
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    14
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    18
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    21
 * questions.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    22
 */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    23
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    24
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    25
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    26
/*
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    27
 * @test
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    28
 * @key stress
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    29
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    30
 * @summary converted from VM testbase nsk/stress/except/except007.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    31
 * VM testbase keywords: [stress, diehard, slow, nonconcurrent, quick]
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    32
 * VM testbase readme:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    33
 * DESCRIPTION
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    34
 *     This checks if various exceptions are thrown (and caught) correctly
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    35
 *     when there apparently are no free space in the heap to allocate new
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    36
 *     Throwable instance.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    37
 *     The test tries to occupy all of memory available in the heap by allocating
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    38
 *     lots of new Object() instances. Instances of the type Object are the smallest
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    39
 *     objects, so they apparently should occupy most fine-grained fragments in the
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    40
 *     heap and leave no free space for new Throwable instance. After that, the test
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    41
 *     provokes various exceptions (e.g.: by executing integer division by 0 and so
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    42
 *     on), and checks if appropriate exceptions are thrown.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    43
 * COMMENTS
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    44
 *     The test needs a lot of memory to start up, so it should not run under older
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    45
 *     JDK 1.1.x release due to its poorer heap utilization. Also, some checks are
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    46
 *     skipped when testing classic VM, because OutOfMemoryError is correctly thrown
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    47
 *     instead of target exception.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    48
 *     When the test is being self-initiating (i.e.: eating heap), memory occupation
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    49
 *     is terminated if memory allocation slows down crucially. This is a workaround
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    50
 *     intended to avoid the HotSpot bug:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    51
 *         #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    52
 *     There is also a workaround involved to avoid the following bugs known
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    53
 *     for HotSpot and for classic VM:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    54
 *         #4239841 (P1/S5) 1.1: poor garbage collector performance  (HotSpot bug)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    55
 *         #4245060 (P4/S5) poor garbage collector performance       (Classic VM bug)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    56
 *     However, printing of the test's error messages, warnings, and of execution
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    57
 *     trace fails under JDK 1.2 for Win32 even so. If the test fails due to this
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    58
 *     problem, exit status 96 is returned instead of 97.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    59
 *     JDK 1.3 classic VM for Sparc may crash (core dump) due to the known bug:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    60
 *         #4245057 (P2/S3) VM crashes when heap is exhausted
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    61
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    62
 * @run main/othervm -Xms50M -Xmx200M nsk.stress.except.except007
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    63
 */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    64
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    65
package nsk.stress.except;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    66
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    67
import java.io.PrintStream;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    68
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    69
/**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    70
 * This checks if various exceptions are thrown (and caught) correctly
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    71
 * when there apparently are no free space in the heap to allocate new
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    72
 * <code>Throwable</code> instance.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    73
 * <p>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    74
 * <p>The test tries to occupy all of memory available in the heap by
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    75
 * allocating lots of new <code>Object()</code> instances. Instances of the
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    76
 * type <code>Object</code> are the smallest objects, so they apparently should
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    77
 * occupy most fine-grained fragments in the heap and leave no free space for
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    78
 * new <code>Throwable</code> instance. After that, the test provokes various
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    79
 * exceptions (e.g.: by executing integer division by 0 and so on), and checks
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    80
 * if appropriate exceptions are thrown.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    81
 * <p>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    82
 * <p>Note, that memory occupation is terminated if memory allocation slows
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    83
 * down crucially. This is a workaround intended to avoid the HotSpot bug:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    84
 * <br>&nbsp;&nbsp;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    85
 * #4248801 (P1/S5) slow memory allocation when heap is almost exhausted
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    86
 * <p>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    87
 * <p>There is also a workaround involved to avoid the following bugs known
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    88
 * for HotSpot and for classic VM:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    89
 * <br>&nbsp;&nbsp;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    90
 * #4239841 (P1/S5) 1.1: poor garbage collector performance
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    91
 * <br>&nbsp;&nbsp;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    92
 * #4245060 (P4/S5) poor garbage collector performance
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    93
 * <br>However, printing of the test's error messages, warnings, and of
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    94
 * execution trace may fail even so. If the test fails due to poor GC
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    95
 * performance, exit status 96 is returned instead of 97.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    96
 * <p>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    97
 * <p>Also note, that the test needs a lot of memory to start up, so it should
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    98
 * not run under older JDK 1.1.x release due to its poor heap utilization.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    99
 */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   100
public class except007 {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   101
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   102
     * Either allow or supress printing of execution trace.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   103
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   104
    private static boolean TRACE_ON = false;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   105
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   106
     * Either allow or supress printing of warning messages.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   107
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   108
    private static final boolean WARN_ON = true;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   109
    /*
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   110
     * Storage for a lot of tiny objects
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   111
     * "static volatile" keywords are for preventing heap optimization
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   112
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   113
    private static volatile Object pool[] = null;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   114
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   115
     * Temporary <code>log</code> for error messages, warnings and/or execution trace.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   116
     *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   117
     * @see #messages
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   118
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   119
    private static String log[] = new String[1000]; // up to 1000 messages
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   120
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   121
     * How many <code>messages</code> were submitted to the <code>log</code>.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   122
     *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   123
     * @see #log
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   124
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   125
    private static int messages = 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   126
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   127
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   128
     * Re-call to the method <code>run(out)</code> (ignore <code>args[]</code>),
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   129
     * and print the test summary - either test passed of failed.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   130
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   131
    public static int run(String args[], PrintStream out) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   132
        if (args.length > 0) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   133
            if (args[0].toLowerCase().startsWith("-v"))
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   134
                TRACE_ON = true;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   135
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   136
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   137
        int exitCode = run(out);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   138
        pool = null;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   139
        System.gc();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   140
        // Print the log[] and the test summary:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   141
        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   142
            for (int i = 0; i < messages; i++)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   143
                out.println(log[i]);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   144
            if (exitCode == 0) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   145
                if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   146
                    out.println("Test passed.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   147
            } else
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   148
                out.println("Test failed.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   149
        } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   150
            // Poor performance of garbage collector:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   151
            exitCode = 1;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   152
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   153
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   154
        return exitCode;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   155
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   156
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   157
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   158
     * Allocate as much <code>Object</code> instances as possible to bring JVM
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   159
     * into stress, and then check if exceptions are correctly thrown accordingly
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   160
     * to various situations like integer division by 0, etc.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   161
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   162
    private static int run(PrintStream out) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   163
        out.println("# While printing this message, JVM seems to initiate the output");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   164
        out.println("# stream, so that it will not need more memory to print later,");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   165
        out.println("# when the heap would fail to provide more memory.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   166
        out.println("# ");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   167
        out.println("# Note, that the test maintains especial static log[] field in");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   168
        out.println("# order to avoid printing when the heap seems exhausted.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   169
        out.println("# Nevertheless, printing could arise OutOfMemoryError even");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   170
        out.println("# after all the memory allocated by the test is released.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   171
        out.println("# ");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   172
        out.println("# That problem is caused by the known JDK/HotSpot bugs:");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   173
        out.println("#     4239841 (P1/S5) 1.1: poor garbage collector performance");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   174
        out.println("#     4245060 (P4/S5) poor garbage collector performance");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   175
        out.println("# ");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   176
        out.println("# This message is just intended to work-around that problem.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   177
        out.println("# If printing should fail even so, the test will try to return");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   178
        out.println("# the exit status 96 instead of 97 to indicate the problem.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   179
        out.println("# However, the test may fail or even crash on some platforms");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   180
        out.println("# suffering the bug 4239841 or 4245060.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   181
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   182
        // Prepare some items, which will be used by the test:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   183
        Thread rabbit = new Rabbit();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   184
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   185
        // Allocate repository for a lots of tiny objects:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   186
        for (int size = 1 << 30; size > 0 && pool == null; size >>= 1)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   187
            try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   188
                pool = new Object[size];
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   189
            } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   190
            }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   191
        if (pool == null)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   192
            throw new Error("HS bug: cannot allocate new Object[1]");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   193
        int poolSize = pool.length;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   194
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   195
        int index = 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   196
        pool[index++] = new Object();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   197
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   198
        // Sum up time spent, when it was hard to JVM to allocate next object
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   199
        // (i.e.: when JVM has spent more than 1 second to allocate new object):
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   200
        double totalDelay = 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   201
        long timeMark = System.currentTimeMillis();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   202
        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   203
            for (; index < poolSize; index++) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   204
                //-------------------------
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   205
                pool[index] = new Object();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   206
                long nextTimeMark = System.currentTimeMillis();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   207
                long elapsed = nextTimeMark - timeMark;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   208
                timeMark = nextTimeMark;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   209
                //----------------------
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   210
                if (elapsed > 1000) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   211
                    double seconds = elapsed / 1000.0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   212
                    if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   213
                        out.println(
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   214
                                "pool[" + index + "]=new Object(); // elapsed " + seconds + "s");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   215
                    totalDelay += seconds;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   216
                    if (totalDelay > 60) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   217
                        if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   218
                            out.println(
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   219
                                    "Memory allocation became slow; so, heap seems exhausted.");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   220
                        break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   221
                    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   222
                }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   223
            }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   224
        } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   225
            if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   226
                log[messages++] = "Heap seems exhausted - OutOfMemoryError thrown.";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   227
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   228
        if (index > poolSize - 1000) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   229
            if (WARN_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   230
                log[messages++] = "Warning: pool[] is full; so, checks would not be enough hard...";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   231
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   232
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   233
        // Sum up exit code:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   234
        int exitCode = 0; // apparently PASSED
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   235
        int skipped = 0;  // some checks may correctly suffer OutOfMemoryError
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   236
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   237
        // Check InterruptedException:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   238
        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   239
            synchronized (rabbit) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   240
                rabbit.start();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   241
                rabbit.wait();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   242
            }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   243
            rabbit.interrupt();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   244
            while (rabbit.isAlive())
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   245
                rabbit.join();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   246
            Throwable exception = ((Rabbit) rabbit).exception;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   247
            if (exception == null) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   248
                log[messages++] = "Failure: InterruptedException not thrown";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   249
                exitCode = 2;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   250
            } else {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   251
                if (exception instanceof InterruptedException) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   252
                    if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   253
                        log[messages++] =
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   254
                                "Success: InterruptedException thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   255
                } else if (exception instanceof OutOfMemoryError) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   256
                    if (WARN_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   257
                        log[messages++] = "Skipped: InterruptedException";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   258
                    skipped++;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   259
                } else {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   260
                    log[messages++] =
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   261
                            "Failure: InterruptedException: unexpected exception thrown";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   262
                    exitCode = 2;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   263
                }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   264
                pool[index++] = exception;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   265
            }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   266
        } catch (InterruptedException ie) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   267
            log[messages++] = "Failure: InterruptedException thrown unexpectedly";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   268
            exitCode = 2;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   269
        } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   270
            if (WARN_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   271
                log[messages++] = "Skipped: InterruptedException";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   272
            skipped++;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   273
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   274
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   275
        // Check NegativeArraySizeException:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   276
        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   277
            int negative = -1;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   278
            byte array[] = new byte[negative];
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   279
            log[messages++] = "Failure: NegativeArraySizeException not thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   280
            exitCode = 2;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   281
        } catch (NegativeArraySizeException ie) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   282
            if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   283
                log[messages++] = "Success: NegativeArraySizeException thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   284
            pool[index++] = ie;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   285
        } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   286
            if (WARN_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   287
                log[messages++] = "Skipped: NegativeArraySizeException";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   288
            skipped++;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   289
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   290
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   291
        // Check NullPointerException:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   292
        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   293
            Double none = null;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   294
            double oops = none.doubleValue();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   295
            log[messages++] = "Failure: NullPointerException not thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   296
            exitCode = 2;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   297
        } catch (NullPointerException npe) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   298
            if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   299
                log[messages++] = "Success: NullPointerException thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   300
            pool[index++] = npe;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   301
        } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   302
            if (WARN_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   303
                log[messages++] = "Skipped: NullPointerException";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   304
            skipped++;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   305
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   306
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   307
        // Check NumberFormatException:
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   308
        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   309
            double oops = Double.parseDouble("3.14159D00"); // FORTRAN-like
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   310
            log[messages++] = "Failure: NumberFormatException not thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   311
            exitCode = 2;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   312
        } catch (NumberFormatException nfe) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   313
            if (TRACE_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   314
                log[messages++] = "Success: NumberFormatException thrown as expected";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   315
        } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   316
            if (WARN_ON)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   317
                log[messages++] = "Skipped: NumberFormatException";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   318
            skipped++;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   319
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   320
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   321
        return exitCode;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   322
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   323
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   324
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   325
     * Will shoot a rabbit when it waits -- in order to provoke
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   326
     * InterruptedException.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   327
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   328
    private static class Rabbit extends Thread {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   329
        Throwable exception = null;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   330
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   331
        public void run() {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   332
            try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   333
                synchronized (this) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   334
                    this.notify();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   335
                    this.wait();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   336
                }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   337
            } catch (InterruptedException ie) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   338
                exception = ie;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   339
            } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   340
                exception = oome;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   341
            }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   342
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   343
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   344
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   345
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   346
    /**
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   347
     * Re-call to <code>run(args,out)</code>, and return JCK-like exit status.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   348
     * (The stream <code>out</code> is assigned to <code>System.out</code> here.)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   349
     *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   350
     * @see #run(String[], PrintStream)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   351
     */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   352
    public static void main(String args[]) {
52640
3a7d49718852 8213721: [Graal] Tests vmTestbase/nsk/stress/except/except* may be encountering SEGV during out-of-memory conditions
jcbeyler
parents: 50169
diff changeset
   353
        Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   354
            // Last try. If there is some exception outside the code, test should end correctly
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   355
            @Override
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   356
            public void uncaughtException(Thread t, Throwable e) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   357
                try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   358
                    pool = null;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   359
                    log = null;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   360
                    System.gc();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   361
                    if (e instanceof OutOfMemoryError) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   362
                        try {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   363
                            System.out.println("OOME : Test Skipped");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   364
                            System.exit(0);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   365
                        } catch (Throwable ignore) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   366
                        } // No code in the handler can provoke correct exceptions.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   367
                    } else {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   368
                        e.printStackTrace();
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   369
                        throw (RuntimeException) e;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   370
                    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   371
                } catch (OutOfMemoryError oome) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   372
                }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   373
            }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   374
        });
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   375
        int exitCode = run(args, System.out);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   376
        System.exit(exitCode + 95);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   377
        // JCK-like exit status.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   378
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   379
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   380
}