test/serviceability/sa/LingeredAppWithRecComputation.java

Mon, 23 Sep 2019 20:26:18 +0200

author
sgehwolf
date
Mon, 23 Sep 2019 20:26:18 +0200
changeset 9919
e8a0af9fc1cb
permissions
-rw-r--r--

8196969: JTreg Failure: serviceability/sa/ClhsdbJstack.java causes NPE
Summary: Account for serialized null scopes in NMethod
Reviewed-by: aph, never, andrew

     1 /*
     2  * Copyright (c) 2019, Red Hat Inc. 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  */
    24 import jdk.test.lib.apps.LingeredApp;
    26 public class LingeredAppWithRecComputation extends LingeredApp {
    28     public static final String THREAD_NAME = "LingeredAppWithRecComputation.factorial()";
    30     private long factorial(int n) {
    31         if (n <= 1) {
    32                 return 1;
    33         }
    34         if (n == 2) {
    35                 return 2;
    36         }
    37         return n * factorial(n - 1);
    38     }
    40     public void testLoop() {
    41         long result = 0;
    42         long[] lastNResults = new long[20];
    43         int i = 0;
    44         int j = 0;
    45         while (true) {
    46             result = factorial(i);
    47             lastNResults[j] = result;
    48             if (i % 12 == 0) {
    49                     i = -1; // reset i
    50             }
    51             if (j % 19 == 0) {
    52                     j = -1; // reset j
    53             }
    54             i++; j++;
    55         }
    56     }
    58     public static void main(String args[]) {
    59         LingeredAppWithRecComputation app = new LingeredAppWithRecComputation();
    60         Thread factorial = new Thread(() -> {
    61             app.testLoop();
    62         });
    63         factorial.setName(THREAD_NAME);
    64         factorial.start();
    65         LingeredApp.main(args);
    66     }
    67  }

mercurial