jdk

Форк
0
/
Stack004.java 
84 строки · 3.0 Кб
1
/*
2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
/*
25
 * @test
26
 * @key stress
27
 *
28
 * @summary converted from VM testbase nsk/stress/stack/stack004.
29
 * VM testbase keywords: [stress, stack, nonconcurrent]
30
 * VM testbase readme:
31
 * DESCRIPTION
32
 *     This test provokes multiple stack overflows in the same thread
33
 *     by invoking final static recursive method for the given fixed
34
 *     depth of recursion (though, for a large depth).
35
 *     This test makes measures a number of recursive invocations
36
 *     before 1st StackOverflowError, and then tries to reproduce
37
 *     such StackOverflowError 100 times -- each time by trying to
38
 *     invoke the same recursive method for the given fixed depth
39
 *     of invocations (which is 200 times that depth just measured).
40
 *     The test is deemed passed, if VM have not crashed.
41
 * COMMENTS
42
 *     This test crashes all HS versions (2.0, 1.3, 1.4) on all
43
 *     platforms (Win32, Solaris, Linux) in all execution modes
44
 *     (-Xint, -Xmixed, -Xcomp) in 100% of executions in which
45
 *     I had tryied it.
46
 *     See the bug:
47
 *     4366625 (P4/S4) multiple stack overflow causes HS crash
48
 *
49
 * @requires vm.opt.DeoptimizeALot != true
50
 * @run main/othervm/timeout=900 Stack004
51
 */
52

53
public class Stack004 {
54
    public static void main(String[] args) {
55
        Stack004 test = new Stack004();
56
        test.doRun();
57
    }
58

59
    public void doRun() {
60
        int depth;
61
        for (depth = 100; ; depth += 100) {
62
            try {
63
                recurse(depth);
64
            } catch (StackOverflowError | OutOfMemoryError err) {
65
                break;
66
            }
67
        }
68
        System.out.println("Max. depth: " + depth);
69
        for (int i = 0; i < 100; i++) {
70
            try {
71
                recurse(200 * depth);
72
                System.out.println("?");
73
            } catch (StackOverflowError | OutOfMemoryError err) {
74
                // OK.
75
            }
76
        }
77
    }
78

79
    final static void recurse(int depth) {
80
        if (depth > 0) {
81
            recurse(depth - 1);
82
        }
83
    }
84
}
85

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.