test/hotspot/gtest/classfile/test_symbolTable.cpp
author coleenp
Fri, 16 Mar 2018 09:12:13 -0400
changeset 49449 ef5d5d343e2a
parent 47216 71c04702a3d5
child 51179 516acf6956a2
permissions -rw-r--r--
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files Summary: interfaceSupport.hpp is an inline file so moved to interfaceSupport.inline.hpp and stopped including it in .hpp files Reviewed-by: stefank, rehn, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41289
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     1
/*
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     4
 *
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     8
 *
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    14
 *
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    18
 *
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    21
 * questions.
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    22
 */
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    23
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    24
#include "precompiled.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
    25
#include "runtime/interfaceSupport.inline.hpp"
41289
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    26
#include "classfile/symbolTable.hpp"
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    27
#include "unittest.hpp"
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    28
41671
9e0c6db4918a 8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents: 41289
diff changeset
    29
TEST_VM(SymbolTable, temp_new_symbol) {
41289
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    30
  // Assert messages assume these symbols are unique, and the refcounts start at
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    31
  // one, but code does not rely on this.
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    32
  JavaThread* THREAD = JavaThread::current();
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    33
  // the thread should be in vm to use locks
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    34
  ThreadInVMfromNative ThreadInVMfromNative(THREAD);
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    35
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    36
  Symbol* abc = SymbolTable::new_symbol("abc", CATCH);
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    37
  int abccount = abc->refcount();
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    38
  TempNewSymbol ss = abc;
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    39
  ASSERT_EQ(ss->refcount(), abccount) << "only one abc";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    40
  ASSERT_EQ(ss->refcount(), abc->refcount()) << "should match TempNewSymbol";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    41
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    42
  Symbol* efg = SymbolTable::new_symbol("efg", CATCH);
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    43
  Symbol* hij = SymbolTable::new_symbol("hij", CATCH);
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    44
  int efgcount = efg->refcount();
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    45
  int hijcount = hij->refcount();
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    46
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    47
  TempNewSymbol s1 = efg;
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    48
  TempNewSymbol s2 = hij;
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    49
  ASSERT_EQ(s1->refcount(), efgcount) << "one efg";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    50
  ASSERT_EQ(s2->refcount(), hijcount) << "one hij";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    51
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    52
  // Assignment operator
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    53
  s1 = s2;
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    54
  ASSERT_EQ(hij->refcount(), hijcount + 1) << "should be two hij";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    55
  ASSERT_EQ(efg->refcount(), efgcount - 1) << "should be no efg";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    56
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    57
  s1 = ss; // s1 is abc
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    58
  ASSERT_EQ(s1->refcount(), abccount + 1) << "should be two abc (s1 and ss)";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    59
  ASSERT_EQ(hij->refcount(), hijcount) << "should only have one hij now (s2)";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    60
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    61
  s1 = s1; // self assignment
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    62
  ASSERT_EQ(s1->refcount(), abccount + 1) << "should still be two abc (s1 and ss)";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    63
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    64
  TempNewSymbol s3;
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    65
  Symbol* klm = SymbolTable::new_symbol("klm", CATCH);
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    66
  int klmcount = klm->refcount();
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    67
  s3 = klm; // assignment
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    68
  ASSERT_EQ(s3->refcount(), klmcount) << "only one klm now";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    69
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    70
  Symbol* xyz = SymbolTable::new_symbol("xyz", CATCH);
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    71
  int xyzcount = xyz->refcount();
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    72
  { // inner scope
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    73
    TempNewSymbol s_inner = xyz;
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    74
  }
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    75
  ASSERT_EQ(xyz->refcount(), xyzcount - 1)
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    76
          << "Should have been decremented by dtor in inner scope";
f307cc24f1e9 8165439: Convert Test_TempNewSymbol to GTest
kzhaldyb
parents:
diff changeset
    77
}