Navigation Menu

Skip to content

Commit

Permalink
8227745: Enable Escape Analysis for Better Performance in the Presenc…
Browse files Browse the repository at this point in the history
…e of JVMTI Agents

8233915: JVMTI FollowReferences: Java Heap Leak not found because of C2 Scalar Replacement

Reviewed-by: mdoerr, goetz, sspitsyn, kvn
  • Loading branch information
reinrich committed Oct 20, 2020
1 parent f167a71 commit 40f847e
Show file tree
Hide file tree
Showing 53 changed files with 5,744 additions and 218 deletions.
8 changes: 6 additions & 2 deletions src/hotspot/share/c1/c1_IR.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, 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
Expand Down Expand Up @@ -244,7 +244,11 @@ class IRScopeDebugInfo: public CompilationResourceObj {
bool reexecute = topmost ? should_reexecute() : false;
bool return_oop = false; // This flag will be ignored since it used only for C2 with escape analysis.
bool rethrow_exception = false;
recorder->describe_scope(pc_offset, methodHandle(), scope()->method(), bci(), reexecute, rethrow_exception, is_method_handle_invoke, return_oop, locvals, expvals, monvals);
bool has_ea_local_in_scope = false;
bool arg_escape = false;
recorder->describe_scope(pc_offset, methodHandle(), scope()->method(), bci(),
reexecute, rethrow_exception, is_method_handle_invoke, return_oop,
has_ea_local_in_scope, arg_escape, locvals, expvals, monvals);
}
};

Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/ci/ciEnv.cpp
Expand Up @@ -242,6 +242,7 @@ bool ciEnv::cache_jvmti_state() {
_jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions();
_jvmti_can_pop_frame = JvmtiExport::can_pop_frame();
_jvmti_can_get_owned_monitor_info = JvmtiExport::can_get_owned_monitor_info();
_jvmti_can_walk_any_space = JvmtiExport::can_walk_any_space();
return _task != NULL && _task->method()->is_old();
}

Expand Down Expand Up @@ -271,6 +272,10 @@ bool ciEnv::jvmti_state_changed() const {
JvmtiExport::can_get_owned_monitor_info()) {
return true;
}
if (!_jvmti_can_walk_any_space &&
JvmtiExport::can_walk_any_space()) {
return true;
}

return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/ci/ciEnv.hpp
Expand Up @@ -74,6 +74,7 @@ class ciEnv : StackObj {
bool _jvmti_can_post_on_exceptions;
bool _jvmti_can_pop_frame;
bool _jvmti_can_get_owned_monitor_info; // includes can_get_owned_monitor_stack_depth_info
bool _jvmti_can_walk_any_space;

// Cache DTrace flags
bool _dtrace_extended_probes;
Expand Down Expand Up @@ -349,6 +350,7 @@ class ciEnv : StackObj {
bool jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; }
bool jvmti_can_post_on_exceptions() const { return _jvmti_can_post_on_exceptions; }
bool jvmti_can_get_owned_monitor_info() const { return _jvmti_can_get_owned_monitor_info; }
bool jvmti_can_walk_any_space() const { return _jvmti_can_walk_any_space; }

// Cache DTrace flags
void cache_dtrace_flags();
Expand Down
10 changes: 3 additions & 7 deletions src/hotspot/share/code/compiledMethod.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, 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
Expand Down Expand Up @@ -293,17 +293,13 @@ void CompiledMethod::verify_oop_relocations() {
ScopeDesc* CompiledMethod::scope_desc_at(address pc) {
PcDesc* pd = pc_desc_at(pc);
guarantee(pd != NULL, "scope must be present");
return new ScopeDesc(this, pd->scope_decode_offset(),
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
pd->return_oop());
return new ScopeDesc(this, pd);
}

ScopeDesc* CompiledMethod::scope_desc_near(address pc) {
PcDesc* pd = pc_desc_near(pc);
guarantee(pd != NULL, "scope must be present");
return new ScopeDesc(this, pd->scope_decode_offset(),
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
pd->return_oop());
return new ScopeDesc(this, pd);
}

address CompiledMethod::oops_reloc_begin() const {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/code/debugInfoRec.cpp
Expand Up @@ -288,6 +288,8 @@ void DebugInformationRecorder::describe_scope(int pc_offset,
bool rethrow_exception,
bool is_method_handle_invoke,
bool return_oop,
bool has_ea_local_in_scope,
bool arg_escape,
DebugToken* locals,
DebugToken* expressions,
DebugToken* monitors) {
Expand All @@ -304,6 +306,8 @@ void DebugInformationRecorder::describe_scope(int pc_offset,
last_pd->set_rethrow_exception(rethrow_exception);
last_pd->set_is_method_handle_invoke(is_method_handle_invoke);
last_pd->set_return_oop(return_oop);
last_pd->set_has_ea_local_in_scope(has_ea_local_in_scope);
last_pd->set_arg_escape(arg_escape);

// serialize sender stream offest
stream()->write_int(sender_stream_offset);
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/code/debugInfoRec.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2020, 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
Expand Down Expand Up @@ -105,6 +105,8 @@ class DebugInformationRecorder: public ResourceObj {
bool rethrow_exception = false,
bool is_method_handle_invoke = false,
bool return_oop = false,
bool has_ea_local_in_scope = false,
bool arg_escape = false,
DebugToken* locals = NULL,
DebugToken* expressions = NULL,
DebugToken* monitors = NULL);
Expand Down
8 changes: 2 additions & 6 deletions src/hotspot/share/code/nmethod.cpp
Expand Up @@ -2419,9 +2419,7 @@ void nmethod::verify_interrupt_point(address call_site) {

PcDesc* pd = pc_desc_at(nativeCall_at(call_site)->return_address());
assert(pd != NULL, "PcDesc must exist");
for (ScopeDesc* sd = new ScopeDesc(this, pd->scope_decode_offset(),
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
pd->return_oop());
for (ScopeDesc* sd = new ScopeDesc(this, pd);
!sd->is_top(); sd = sd->sender()) {
sd->verify();
}
Expand Down Expand Up @@ -3056,9 +3054,7 @@ const char* nmethod::reloc_string_for(u_char* begin, u_char* end) {
ScopeDesc* nmethod::scope_desc_in(address begin, address end) {
PcDesc* p = pc_desc_near(begin+1);
if (p != NULL && p->real_pc(this) <= end) {
return new ScopeDesc(this, p->scope_decode_offset(),
p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(),
p->return_oop());
return new ScopeDesc(this, p);
}
return NULL;
}
Expand Down
16 changes: 14 additions & 2 deletions src/hotspot/share/code/pcDesc.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
Expand Down Expand Up @@ -42,7 +42,9 @@ class PcDesc {
PCDESC_reexecute = 1 << 0,
PCDESC_is_method_handle_invoke = 1 << 1,
PCDESC_return_oop = 1 << 2,
PCDESC_rethrow_exception = 1 << 3
PCDESC_rethrow_exception = 1 << 3,
PCDESC_has_ea_local_in_scope = 1 << 4,
PCDESC_arg_escape = 1 << 5
};

int _flags;
Expand Down Expand Up @@ -89,6 +91,16 @@ class PcDesc {
bool return_oop() const { return (_flags & PCDESC_return_oop) != 0; }
void set_return_oop(bool z) { set_flag(PCDESC_return_oop, z); }

// Indicates if there are objects in scope that, based on escape analysis, are local to the
// compiled method or local to the current thread, i.e. NoEscape or ArgEscape
bool has_ea_local_in_scope() const { return (_flags & PCDESC_has_ea_local_in_scope) != 0; }
void set_has_ea_local_in_scope(bool z) { set_flag(PCDESC_has_ea_local_in_scope, z); }

// Indicates if this pc descriptor is at a call site where objects that do not escape the
// current thread are passed as arguments.
bool arg_escape() const { return (_flags & PCDESC_arg_escape) != 0; }
void set_arg_escape(bool z) { set_flag(PCDESC_arg_escape, z); }

// Returns the real pc
address real_pc(const CompiledMethod* code) const;

Expand Down
25 changes: 10 additions & 15 deletions src/hotspot/share/code/scopeDesc.cpp
Expand Up @@ -31,23 +31,16 @@
#include "oops/oop.inline.hpp"
#include "runtime/handles.inline.hpp"

ScopeDesc::ScopeDesc(const CompiledMethod* code, int decode_offset, int obj_decode_offset, bool reexecute, bool rethrow_exception, bool return_oop) {
ScopeDesc::ScopeDesc(const CompiledMethod* code, PcDesc* pd, bool ignore_objects) {
int obj_decode_offset = ignore_objects ? DebugInformationRecorder::serialized_null : pd->obj_decode_offset();
_code = code;
_decode_offset = decode_offset;
_decode_offset = pd->scope_decode_offset();
_objects = decode_object_values(obj_decode_offset);
_reexecute = reexecute;
_rethrow_exception = rethrow_exception;
_return_oop = return_oop;
decode_body();
}

ScopeDesc::ScopeDesc(const CompiledMethod* code, int decode_offset, bool reexecute, bool rethrow_exception, bool return_oop) {
_code = code;
_decode_offset = decode_offset;
_objects = decode_object_values(DebugInformationRecorder::serialized_null);
_reexecute = reexecute;
_rethrow_exception = rethrow_exception;
_return_oop = return_oop;
_reexecute = pd->should_reexecute();
_rethrow_exception = pd->rethrow_exception();
_return_oop = pd->return_oop();
_has_ea_local_in_scope = ignore_objects ? false : pd->has_ea_local_in_scope();
_arg_escape = ignore_objects ? false : pd->arg_escape();
decode_body();
}

Expand All @@ -59,6 +52,8 @@ void ScopeDesc::initialize(const ScopeDesc* parent, int decode_offset) {
_reexecute = false; //reexecute only applies to the first scope
_rethrow_exception = false;
_return_oop = false;
_has_ea_local_in_scope = parent->has_ea_local_in_scope();
_arg_escape = false;
decode_body();
}

Expand Down
16 changes: 9 additions & 7 deletions src/hotspot/share/code/scopeDesc.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
Expand Down Expand Up @@ -60,12 +60,7 @@ class SimpleScopeDesc : public StackObj {
class ScopeDesc : public ResourceObj {
public:
// Constructor
ScopeDesc(const CompiledMethod* code, int decode_offset, int obj_decode_offset, bool reexecute, bool rethrow_exception, bool return_oop);

// Calls above, giving default value of "serialized_null" to the
// "obj_decode_offset" argument. (We don't use a default argument to
// avoid a .hpp-.hpp dependency.)
ScopeDesc(const CompiledMethod* code, int decode_offset, bool reexecute, bool rethrow_exception, bool return_oop);
ScopeDesc(const CompiledMethod* code, PcDesc* pd, bool ignore_objects = false);

// Direct access to scope
ScopeDesc* at_offset(int decode_offset) { return new ScopeDesc(this, decode_offset); }
Expand All @@ -76,6 +71,10 @@ class ScopeDesc : public ResourceObj {
bool should_reexecute() const { return _reexecute; }
bool rethrow_exception() const { return _rethrow_exception; }
bool return_oop() const { return _return_oop; }
// Returns true if one or more NoEscape or ArgEscape objects exist in
// any of the scopes at compiled pc.
bool has_ea_local_in_scope() const { return _has_ea_local_in_scope; }
bool arg_escape() const { return _arg_escape; }

GrowableArray<ScopeValue*>* locals();
GrowableArray<ScopeValue*>* expressions();
Expand Down Expand Up @@ -105,6 +104,9 @@ class ScopeDesc : public ResourceObj {
bool _reexecute;
bool _rethrow_exception;
bool _return_oop;
bool _has_ea_local_in_scope; // One or more NoEscape or ArgEscape objects exist in
// any of the scopes at compiled pc.
bool _arg_escape; // Compiled Java call in youngest scope passes ArgEscape

// Decoding offsets
int _decode_offset;
Expand Down

1 comment on commit 40f847e

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 40f847e Oct 20, 2020

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.