test/hotspot/jtreg/runtime/NMT/MallocStressTest.java
changeset 55052 05a408cbd945
parent 52898 f3d5dcb6924b
equal deleted inserted replaced
55051:fb9758536458 55052:05a408cbd945
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    75 
    75 
    76         // Grab my own PID
    76         // Grab my own PID
    77         String pid = Long.toString(ProcessTools.getProcessId());
    77         String pid = Long.toString(ProcessTools.getProcessId());
    78         ProcessBuilder pb = new ProcessBuilder();
    78         ProcessBuilder pb = new ProcessBuilder();
    79 
    79 
    80         AllocThread[]   alloc_threads = new AllocThread[256];
    80         AllocThread[]   alloc_threads = new AllocThread[40];
    81         ReleaseThread[] release_threads = new ReleaseThread[64];
    81         ReleaseThread[] release_threads = new ReleaseThread[10];
    82 
    82 
    83         int index;
    83         int index;
    84         // Create many allocation threads
    84         // Create many allocation threads
    85         for (index = 0; index < alloc_threads.length; index ++) {
    85         for (index = 0; index < alloc_threads.length; index ++) {
    86             alloc_threads[index] = new AllocThread();
    86             alloc_threads[index] = new AllocThread();
    89         // Fewer release threads
    89         // Fewer release threads
    90         for (index = 0; index < release_threads.length; index ++) {
    90         for (index = 0; index < release_threads.length; index ++) {
    91             release_threads[index] = new ReleaseThread();
    91             release_threads[index] = new ReleaseThread();
    92         }
    92         }
    93 
    93 
    94         if (is_64_bit_system()) {
       
    95             sleep_wait(2*60*1000);
       
    96         } else {
       
    97             sleep_wait(60*1000);
       
    98         }
       
    99         // pause the stress test
    94         // pause the stress test
   100         phase = TestPhase.pause;
    95         phase = TestPhase.pause;
   101         while (pause_count.intValue() <  alloc_threads.length + release_threads.length) {
    96         while (pause_count.intValue() <  alloc_threads.length + release_threads.length) {
   102             sleep_wait(10);
    97             sleep_wait(10);
   103         }
    98         }
   170         }
   165         }
   171 
   166 
   172         // AllocThread only runs "Alloc" phase
   167         // AllocThread only runs "Alloc" phase
   173         public void run() {
   168         public void run() {
   174             Random random = new Random();
   169             Random random = new Random();
   175             while (MallocStressTest.phase == TestPhase.alloc) {
   170             // MallocStressTest.phase == TestPhase.alloc
       
   171             for (int loops = 0; loops < 100; loops++) {
   176                 int r = random.nextInt(Integer.MAX_VALUE);
   172                 int r = random.nextInt(Integer.MAX_VALUE);
   177                 // Only malloc small amount to avoid OOM
   173                 // Only malloc small amount to avoid OOM
   178                 int size = r % 32;
   174                 int size = r % 32;
   179                 if (is_64_bit_system()) {
   175                 if (is_64_bit_system()) {
   180                     r = r % 32 * K;
   176                     r = r % 32 * K;