jdk

Форк
0
/
Stack001.java 
77 строк · 2.9 Кб
1
/*
2
 * Copyright (c) 2000, 2024, 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/stack001.
29
 * VM testbase keywords: [stress, quick, stack, nonconcurrent]
30
 * VM testbase readme:
31
 * DESCRIPTION
32
 *     Provoke StackOverflowError by infinite recursion in Java method,
33
 *     intercept the exception try to make one more invocation.
34
 * COMMENTS
35
 *     Kestrel for Solaris_JDK_1.3-b10 crashes while trying to execute
36
 *     this test with Client HS VM.
37
 *     See lots of bugs concerning similar failures:
38
 *     Evaluated:
39
 *     4217960 [native stack overflow bug] reflection test causes crash
40
 *     Accepted:
41
 *     4285716 native stack overflow causes crash on Solaris
42
 *     4281578 Second stack overflow crashes HotSpot VM
43
 *     Closed (duplicate):
44
 *     4027933     Native stack overflows not detected or handled correctly
45
 *     4134353     (hpi) sysThreadCheckStack is a no-op on win32
46
 *     4185411     Various crashes when using recursive reflection.
47
 *     4167055     infinite recursion in FindClass
48
 *     4222359     Infinite recursion crashes jvm
49
 *     Closed (will not fix):
50
 *     4231968 StackOverflowError in a native method causes Segmentation Fault
51
 *     4254634     println() while catching StackOverflowError causes hotspot VM crash
52
 *     4302288 the second stack overflow causes Classic VM to exit on win32
53
 *
54
 * @requires vm.opt.DeoptimizeALot != true
55
 * @run main/othervm/timeout=900 Stack001
56
 */
57

58
public class Stack001 {
59
    public static void main(String[] args) {
60
        Stack001 test = new Stack001();
61
        test.recurse(0);
62
        System.out.println("Maximal depth: " + test.maxdepth);
63
    }
64

65
    private int maxdepth;
66

67
    private void recurse(int depth) {
68
        maxdepth = depth;
69
        try {
70
            recurse(depth + 1);
71
        } catch (StackOverflowError | OutOfMemoryError e) {
72
            if (maxdepth == depth) {
73
                recurse(depth + 1);
74
            }
75
        }
76
    }
77
}
78

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

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

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

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