Path: blob/master/test/hotspot/gtest/runtime/test_stackoverflow.cpp
41144 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "runtime/os.hpp"26#include "runtime/globals.hpp"27#include "runtime/stackOverflow.hpp"28#include "utilities/align.hpp"29#include "utilities/globalDefinitions.hpp"30#include "utilities/ostream.hpp"31#include "unittest.hpp"323334TEST_VM(StackOverflow, basics) {35StackOverflow so;3637// Make up a stack range. No need to allocate anything. Size has to be large enough38// to fit sum of all zones into them.39address base = (address) 0x40000000;40const size_t size = os::vm_page_size() * 100;41address end = base - size;42so.initialize(base, end);4344// Walking down the "stack" check for consistency of the three "in_stack_xxx" functions45enum { normal_stack, reserved_or_yellow_zone, red_zone } where = normal_stack;46for (address p = base - 1; p >= end; p -= os::vm_page_size()) {47// tty->print_cr(PTR_FORMAT " %d %d %d", p2i(p),48// (int)so.in_stack_reserved_zone(p),49// (int)so.in_stack_yellow_reserved_zone(p),50// (int)so.in_stack_red_zone(p));51switch (where) {52case normal_stack:53ASSERT_FALSE(so.in_stack_red_zone(p));54if (so.in_stack_yellow_reserved_zone(p)) {55if (StackReservedPages > 0) {56ASSERT_TRUE(so.in_stack_reserved_zone(p));57} else {58ASSERT_FALSE(so.in_stack_reserved_zone(p));59}60where = reserved_or_yellow_zone;61} else {62ASSERT_FALSE(so.in_stack_reserved_zone((p)));63}64break;65case reserved_or_yellow_zone:66if (so.in_stack_red_zone(p)) {67ASSERT_FALSE(so.in_stack_yellow_reserved_zone(p));68where = red_zone;69} else {70ASSERT_TRUE(so.in_stack_yellow_reserved_zone(p));71}72break;73case red_zone:74ASSERT_TRUE(so.in_stack_red_zone(p));75ASSERT_FALSE(so.in_stack_yellow_reserved_zone(p));76ASSERT_FALSE(so.in_stack_reserved_zone((p)));77break;78}79}80ASSERT_EQ(where, red_zone);8182// Check bases.83ASSERT_FALSE(so.in_stack_red_zone(so.stack_red_zone_base()));84ASSERT_TRUE(so.in_stack_red_zone(so.stack_red_zone_base() - 1));85ASSERT_TRUE(so.in_stack_yellow_reserved_zone(so.stack_red_zone_base()));86ASSERT_FALSE(so.in_stack_reserved_zone(so.stack_reserved_zone_base()));87if (so.stack_reserved_zone_size() > 0) {88ASSERT_TRUE(so.in_stack_reserved_zone(so.stack_reserved_zone_base() - 1));89}90}919293