RFR: 8260198: TypeInstPtr::dump2() emits multiple lines if Verbose is set [v4]

Evgeny Astigeevich github.com+42899633+eastig at openjdk.java.net
Wed Feb 17 19:25:40 UTC 2021


On Wed, 17 Feb 2021 19:16:59 GMT, Evgeny Astigeevich <github.com+42899633+eastig at openjdk.org> wrote:

>> src/hotspot/share/opto/type.cpp line 4049:
>> 
>>> 4047:       ss.print(" ");
>>> 4048:       const_oop()->print_oop(&ss);
>>> 4049:       ss.tr_delete('\n');
>> 
>> `tr_delete` is expensive. Also deleting something in a stream does not fit into a concept of streams.
>> I see that the content of `ss` is traversed many times.
>> What about this code:
>> for (const char *str = ss.base(); *str; ) {
>>   size_t i = 0;
>>   while (str[i] && str[i] != '\n' ) {
>>        ++i;
>>   }
>>   st->print_raw(str, i);
>>   str += i;
>>   while (*str == '\n') {
>>     ++str;
>>   }
>> }
>
> Another option:
> class filterStringStream: public stringStream {
> private:
>   char ch;
> public:
>   filterStringStream(char ch_to_filter, size_t initial_bufsize = 256) : stringStream(initial_bufsize), ch(ch_to_filter) {}
> 
>   virtual void write(const char* c, size_t len) override {
>     const char* e = c + len;
>     while (c != e) {
>       size_t i = 0;
>       while ((c+i) != e && c[i] != ch ) {
>         ++i;
>       }
>       stringStream::write(c, i);
>       c += i;
>       while (c != e && *ch == ch) {
>         ++c;
>       }
>     }     
>   }
> };
> 
> Your code will be:
> filterStringStream ss('\n');
> ss.print(" ");
> const_oop->print_oop(&ss);
> st->print_raw(ss.base(), ss,size());

> `tr_delete` is expensive. Also deleting something in a stream does not fit into a concept of streams.
> I see that the content of `ss` is traversed many times.
> What about this code:
> 
> ```
> for (const char *str = ss.base(); *str; ) {
>   size_t i = 0;
>   while (str[i] && str[i] != '\n' ) {
>        ++i;
>   }
>   st->print_raw(str, i);
>   str += i;
>   while (*str == '\n') {
>     ++str;
>   }
> }
> ```

You can put this code in a function like `print_filtering_ch(char, const stringStream&, outputStream*)`

-------------

PR: https://git.openjdk.java.net/jdk/pull/2178


More information about the hotspot-dev mailing list