Skip to content
Permalink
Browse files
8260198: TypeInstPtr::dump2() emits multiple lines if Verbose is set
Reviewed-by: thartmann
  • Loading branch information
Xin Liu authored and TobiHartmann committed Feb 26, 2021
1 parent 0a4e710 commit 7603278164721bfbd4b70d316b62df5c9b334515
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
@@ -40,6 +40,7 @@
#include "opto/opcodes.hpp"
#include "opto/type.hpp"
#include "utilities/powerOfTwo.hpp"
#include "utilities/stringUtils.hpp"

// Portions of code courtesy of Clifford Click

@@ -4103,15 +4104,23 @@ int TypeInstPtr::hash(void) const {
//------------------------------dump2------------------------------------------
// Dump oop Type
#ifndef PRODUCT
void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
// Print the name of the klass.
klass()->print_name_on(st);

switch( _ptr ) {
case Constant:
// TO DO: Make CI print the hex address of the underlying oop.
if (WizardMode || Verbose) {
const_oop()->print_oop(st);
ResourceMark rm;
stringStream ss;

st->print(" ");
const_oop()->print_oop(&ss);
// 'const_oop->print_oop()' may emit newlines('\n') into ss.
// suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
char* buf = ss.as_string(/* c_heap= */false);
StringUtils::replace_no_expand(buf, "\n", "");
st->print_raw(buf);
}
case BotPTR:
if (!WizardMode && !Verbose) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
*/

#include "precompiled.hpp"
#include "memory/resourceArea.hpp"
#include "utilities/stringUtils.hpp"
#include "unittest.hpp"

@@ -31,3 +32,43 @@ TEST(StringUtils, similarity) {
const char* str2 = "the quick brown fox jumps over the lazy doh";
EXPECT_NEAR(0.95349, StringUtils::similarity(str1, strlen(str1), str2, strlen(str2)), 1e-5);
}

static size_t count_char(const char* s, size_t len, char ch) {
size_t cnt = 0;

for (size_t i = 0; i < len; ++i) {
if (s[i] == ch) {
cnt++;
}
}
return cnt;
}

static size_t count_char(const stringStream& ss, char ch) {
return count_char(ss.base(), ss.size(), ch);
}

static const char* const lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" \
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" \
"Lacinia at quis risus sed vulputate odio ut enim blandit.\n" \
"Amet risus nullam eget felis eget.\n" \
"Viverra orci sagittis eu volutpat odio facilisis mauris sit.\n" \
"Erat velit scelerisque in dictum non.\n";


TEST_VM(StringUtils, replace_no_expand) {
ResourceMark rm;
stringStream ss;

ss.print_raw(lorem);
size_t newlines = count_char(ss, '\n');
char* s2 = ss.as_string(false);
int deleted = StringUtils::replace_no_expand(s2, "\n", "");
ASSERT_EQ(newlines, (size_t)deleted);

newlines = count_char(s2, strlen(s2), '\n');
ASSERT_EQ(newlines, (size_t)0);

deleted = StringUtils::replace_no_expand(s2, "\n", "");
ASSERT_EQ(deleted, 0);
}

1 comment on commit 7603278

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 7603278 Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.