Path: blob/master/test/hotspot/gtest/runtime/test_signatureStream.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*/2223#include "precompiled.hpp"24#include "classfile/symbolTable.hpp"25#include "memory/resourceArea.hpp"26#include "runtime/interfaceSupport.inline.hpp"27#include "runtime/signature.hpp"28#include "threadHelper.inline.hpp"29#include "unittest.hpp"3031TEST_VM(SignatureStream, check_refcount) {3233JavaThread* THREAD = JavaThread::current();34// the thread should be in vm to use locks35ThreadInVMfromNative ThreadInVMfromNative(THREAD);36// SignatureStream::as_symbol will allocate on the resource area37ResourceMark rm(THREAD);3839Symbol* foo = SymbolTable::new_symbol("Foo");40int r1 = foo->refcount();4142{43// Trivial test: non-method signature of a non-permanent symbol44Symbol* methodSig = SymbolTable::new_symbol("LFoo;");45SignatureStream ss(methodSig, false);46Symbol* sym = ss.as_symbol();47ASSERT_EQ(sym, foo) << "found symbol should be Foo: " << sym->as_C_string();48// This should mean the SS looks up and increments refcount to Foo49ASSERT_EQ(foo->refcount(), r1 + 1) << "refcount should be incremented";5051ASSERT_TRUE(!ss.is_done())52<< "stream parsing should not be marked as done until"53<<" ss.next() called after the last symbol";5455ss.next();56ASSERT_TRUE(ss.is_done()) << "stream parsing should be marked as done";57}5859ASSERT_EQ(foo->refcount(), r1) << "refcount should have decremented";6061{62// Ensure refcount is properly decremented when first symbol is non-permanent and second isn't6364Symbol* integer = SymbolTable::new_symbol("java/lang/Integer");65ASSERT_TRUE(integer->is_permanent()) << "java/lang/Integer must be permanent";6667Symbol* methodSig = SymbolTable::new_symbol("(LFoo;)Ljava/lang/Integer;");68SignatureStream ss(methodSig);69Symbol* sym = ss.as_symbol();70ASSERT_EQ(sym, foo) << "found symbol should be Foo: " << sym->as_C_string();71// This should mean the SS looks up and increments refcount to Foo72ASSERT_EQ(foo->refcount(), r1 + 1) << "refcount should be incremented";7374ss.next();75sym = ss.as_symbol();76ASSERT_EQ(sym, integer) << "found symbol should be java/lang/Integer";7778ASSERT_TRUE(!ss.is_done())79<< "stream parsing should not be marked as done until"80<<" ss.next() called after the last symbol";8182ss.next();83ASSERT_TRUE(ss.is_done()) << "stream parsing should be marked as done";84}8586ASSERT_EQ(foo->refcount(), r1) << "refcount should have decremented";8788}899091