Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanghuang-Huawei committed Mar 19, 2021
1 parent a82410c commit 3934fd9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
55 changes: 27 additions & 28 deletions src/hotspot/share/opto/callGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,16 @@ class LateInlineCallGenerator : public DirectCallGenerator {
private:
jlong _unique_id; // unique id for log compilation
bool _is_pure_call; // a hint that the call doesn't have important side effects to care about
bool _is_boxing_call;

protected:
CallGenerator* _inline_cg;
virtual bool do_late_inline_check(Compile* C, JVMState* jvms) { return true; }
virtual CallGenerator* inline_cg() const { return _inline_cg; }
virtual bool is_pure_call() const { return _is_pure_call; }
virtual bool is_boxing_call() const { return _is_boxing_call; }

public:
LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg, bool is_pure_call = false, bool is_boxing_call = false) :
DirectCallGenerator(method, true), _unique_id(0),
_is_pure_call(is_pure_call),
_is_boxing_call(is_boxing_call),
_inline_cg(inline_cg) {}
LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg, bool is_pure_call = false) :
DirectCallGenerator(method, true), _unique_id(0), _is_pure_call(is_pure_call), _inline_cg(inline_cg) {}

virtual bool is_late_inline() const { return true; }

Expand Down Expand Up @@ -453,22 +448,17 @@ class LateInlineVirtualCallGenerator : public VirtualCallGenerator {
CallGenerator* _inline_cg;
ciMethod* _callee;
bool _is_pure_call;
bool _is_boxing_call;
float _prof_factor;

protected:
virtual bool do_late_inline_check(Compile* C, JVMState* jvms);
virtual CallGenerator* inline_cg() const { return _inline_cg; }
virtual bool is_pure_call() const { return _is_pure_call; }
virtual bool is_boxing_call() const { return _is_boxing_call; }

public:
LateInlineVirtualCallGenerator(ciMethod* method, int vtable_index, float prof_factor)
: VirtualCallGenerator(method, vtable_index, true /*separate_io_projs*/),
_unique_id(0), _inline_cg(NULL), _callee(NULL),
_is_pure_call(false),
_is_boxing_call(false),
_prof_factor(prof_factor) {}
_unique_id(0), _inline_cg(NULL), _callee(NULL), _is_pure_call(false), _prof_factor(prof_factor) {}

virtual bool is_late_inline() const { return true; }

Expand Down Expand Up @@ -564,19 +554,22 @@ void LateInlineVirtualCallGenerator::do_late_inline() {
CallGenerator::do_late_inline_helper();
}

// replace box node to scalar node only in case it is directly referenced by debug info
static void replace_box_to_scalar(CallNode* call, Node* resproj) {
assert(call->as_CallStaticJava()->is_boxing_method(), "sanity");
static bool has_non_debug_usages(Node* n) {
for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
Node* m = n->fast_out(i);
if (!m->is_SafePoint()
|| (m->is_Call() && m->as_Call()->has_non_debug_use(n))) {
return true;
}
}
return false;
}

static void scalarize_debug_usages(CallNode* call, Node* resproj) {
Unique_Node_List safepoints;
for (DUIterator_Fast imax, i = resproj->fast_outs(imax); i < imax; i++) {
Node* m = resproj->fast_out(i);
if (m->is_SafePoint()
&& (!m->is_Call() || !m->as_Call()->has_non_debug_use(resproj))) {
safepoints.push(m);
} else {
return;
}
safepoints.push(m);
}

#ifndef PRODUCT
Expand Down Expand Up @@ -666,19 +659,23 @@ void CallGenerator::do_late_inline_helper() {
C->remove_macro_node(call);
}

bool call_can_eliminate = false;
bool result_not_used = false;

if (is_pure_call()) {
if (is_boxing_call() && callprojs.resproj != nullptr) {
replace_box_to_scalar(call, callprojs.resproj);
if (is_boxing_late_inline() && callprojs.resproj != nullptr) {
// replace box node to scalar node only in case it is directly referenced by debug info
assert(call->as_CallStaticJava()->is_boxing_method(), "sanity");
if (!has_non_debug_usages(callprojs.resproj)) {
scalarize_debug_usages(call, callprojs.resproj);
}
}

// The call is marked as pure (no important side effects), but result isn't used.
// It's safe to remove the call.
call_can_eliminate = (callprojs.resproj == NULL || callprojs.resproj->outcnt() == 0);
result_not_used = (callprojs.resproj == NULL || callprojs.resproj->outcnt() == 0);
}

if (call_can_eliminate) {
if (result_not_used) {
GraphKit kit(call->jvms());
kit.replace_call(call, C->top(), true);
} else {
Expand Down Expand Up @@ -800,7 +797,7 @@ class LateInlineBoxingCallGenerator : public LateInlineCallGenerator {

public:
LateInlineBoxingCallGenerator(ciMethod* method, CallGenerator* inline_cg) :
LateInlineCallGenerator(method, inline_cg, /*is_pure=*/true, /*is_boxing*/true) {}
LateInlineCallGenerator(method, inline_cg, /*is_pure=*/true) {}

virtual JVMState* generate(JVMState* jvms) {
Compile *C = Compile::current();
Expand All @@ -813,6 +810,8 @@ class LateInlineBoxingCallGenerator : public LateInlineCallGenerator {
return new_jvms;
}

virtual bool is_boxing_late_inline() const { return true; }

virtual CallGenerator* with_call_node(CallNode* call) {
LateInlineBoxingCallGenerator* cg = new LateInlineBoxingCallGenerator(method(), _inline_cg);
cg->set_call_node(call->as_CallStaticJava());
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/opto/callGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class CallGenerator : public ResourceObj {
void do_late_inline_helper();

virtual bool do_late_inline_check(Compile* C, JVMState* jvms) { ShouldNotReachHere(); return false; }
virtual CallGenerator* inline_cg() const { ShouldNotReachHere(); return NULL; }
virtual bool is_pure_call() const { ShouldNotReachHere(); return false; }
virtual bool is_boxing_call() const { ShouldNotReachHere(); return false; }
virtual CallGenerator* inline_cg() const { ShouldNotReachHere(); return NULL; }
virtual bool is_pure_call() const { ShouldNotReachHere(); return false; }

public:
// Accessors
Expand Down Expand Up @@ -75,6 +74,7 @@ class CallGenerator : public ResourceObj {
virtual bool is_late_inline() const { return false; }
// same but for method handle calls
virtual bool is_mh_late_inline() const { return false; }
virtual bool is_boxing_late_inline() const { return false; }
virtual bool is_string_late_inline() const { return false; }
virtual bool is_virtual_late_inline() const { return false; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Huawei and/or its affiliates. All rights reserved.
* Copyright (c) 2021, Huawei Technologies Co., Ltd. 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Huawei and/or its affiliates. All rights reserved.
* Copyright (c) 2021, Huawei Technologies Co., Ltd. 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

0 comments on commit 3934fd9

Please sign in to comment.