Skip to content
Permalink
Browse files
8259316: [REDO] C1/C2 compiler support for blackholes
Reviewed-by: vlivanov, kvn, iignatyev
  • Loading branch information
shipilev committed May 5, 2021
1 parent f07bb2f commit 6018336fc5e93675482b92df76594712c238adda
Showing with 1,167 additions and 6 deletions.
  1. +2 −0 src/hotspot/share/c1/c1_Compiler.cpp
  2. +1 −1 src/hotspot/share/c1/c1_GraphBuilder.cpp
  3. +13 −0 src/hotspot/share/c1/c1_LIRGenerator.cpp
  4. +2 −1 src/hotspot/share/c1/c1_LIRGenerator.hpp
  5. +3 −0 src/hotspot/share/ci/ciMethod.cpp
  6. +10 −0 src/hotspot/share/ci/ciMethod.hpp
  7. +5 −0 src/hotspot/share/classfile/classFileParser.cpp
  8. +1 −0 src/hotspot/share/classfile/vmIntrinsics.cpp
  9. +3 −0 src/hotspot/share/classfile/vmIntrinsics.hpp
  10. +1 −0 src/hotspot/share/classfile/vmSymbols.hpp
  11. +37 −1 src/hotspot/share/compiler/compilerOracle.cpp
  12. +5 −1 src/hotspot/share/compiler/compilerOracle.hpp
  13. +2 −0 src/hotspot/share/jvmci/jvmciEnv.cpp
  14. +2 −0 src/hotspot/share/opto/c2compiler.cpp
  15. +1 −0 src/hotspot/share/opto/classes.hpp
  16. +2 −0 src/hotspot/share/opto/compile.cpp
  17. +24 −1 src/hotspot/share/opto/library_call.cpp
  18. +2 −0 src/hotspot/share/opto/library_call.hpp
  19. +23 −0 src/hotspot/share/opto/memnode.cpp
  20. +21 −1 src/hotspot/share/opto/memnode.hpp
  21. +1 −0 src/hotspot/share/opto/node.hpp
  22. +7 −0 src/hotspot/share/opto/regmask.cpp
  23. +1 −0 src/hotspot/share/opto/regmask.hpp
  24. +1 −0 src/hotspot/share/runtime/vmStructs.cpp
  25. +1 −0 test/hotspot/jtreg/TEST.groups
  26. +120 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeExistingIntrinsicWarningTest.java
  27. +128 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeExperimentalUnlockTest.java
  28. +298 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeIntrinsicTest.java
  29. +119 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeNonEmptyWarningTest.java
  30. +120 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeNonStaticWarningTest.java
  31. +121 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeNonVoidWarningTest.java
  32. +90 −0 test/hotspot/jtreg/compiler/blackhole/BlackholeTarget.java
@@ -229,6 +229,8 @@ bool Compiler::is_intrinsic_supported(const methodHandle& method) {
break;
case vmIntrinsics::_getObjectSize:
break;
case vmIntrinsics::_blackhole:
break;
default:
return false; // Intrinsics not on the previous list are not available.
}
@@ -3419,7 +3419,7 @@ bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, bool ignore_r

// handle intrinsics
if (callee->intrinsic_id() != vmIntrinsics::_none &&
(CheckIntrinsics ? callee->intrinsic_candidate() : true)) {
callee->check_intrinsic_candidate()) {
if (try_inline_intrinsics(callee, ignore_return)) {
print_inlining(callee, "intrinsic");
if (callee->has_reserved_stack_access()) {
@@ -3202,6 +3202,10 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
do_vectorizedMismatch(x);
break;

case vmIntrinsics::_blackhole:
do_blackhole(x);
break;

default: ShouldNotReachHere(); break;
}
}
@@ -3621,6 +3625,15 @@ void LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) {
}
}

void LIRGenerator::do_blackhole(Intrinsic *x) {
assert(!x->has_receiver(), "Should have been checked before: only static methods here");
for (int c = 0; c < x->number_of_arguments(); c++) {
// Load the argument
LIRItem vitem(x->argument_at(c), this);
vitem.load_item();
// ...and leave it unused.
}
}

LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) {
LIRItemList args(1);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@@ -265,6 +265,7 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
void do_update_CRC32(Intrinsic* x);
void do_update_CRC32C(Intrinsic* x);
void do_vectorizedMismatch(Intrinsic* x);
void do_blackhole(Intrinsic* x);

public:
LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
@@ -154,6 +154,8 @@ ciMethod::ciMethod(const methodHandle& h_m, ciInstanceKlass* holder) :
ciReplay::initialize(this);
}
#endif

CompilerOracle::tag_blackhole_if_possible(h_m);
}


@@ -1214,6 +1216,7 @@ bool ciMethod::is_getter () const { FETCH_FLAG_FROM_VM(is_getter);
bool ciMethod::is_setter () const { FETCH_FLAG_FROM_VM(is_setter); }
bool ciMethod::is_accessor () const { FETCH_FLAG_FROM_VM(is_accessor); }
bool ciMethod::is_initializer () const { FETCH_FLAG_FROM_VM(is_initializer); }
bool ciMethod::is_empty () const { FETCH_FLAG_FROM_VM(is_empty_method); }

bool ciMethod::is_boxing_method() const {
if (intrinsic_id() != vmIntrinsics::_none && holder()->is_box_klass()) {
@@ -204,6 +204,15 @@ class ciMethod : public ciMetadata {
bool intrinsic_candidate() const { return get_Method()->intrinsic_candidate(); }
bool is_static_initializer() const { return get_Method()->is_static_initializer(); }

bool check_intrinsic_candidate() const {
if (intrinsic_id() == vmIntrinsics::_blackhole) {
// This is the intrinsic without an associated method, so no intrinsic_candidate
// flag is set. The intrinsic is still correct.
return true;
}
return (CheckIntrinsics ? intrinsic_candidate() : true);
}

int highest_osr_comp_level();

Bytecodes::Code java_code_at_bci(int bci) {
@@ -346,6 +355,7 @@ class ciMethod : public ciMetadata {
bool is_setter () const;
bool is_accessor () const;
bool is_initializer () const;
bool is_empty () const;
bool can_be_statically_bound() const { return _can_be_statically_bound; }
bool has_reserved_stack_access() const { return _has_reserved_stack_access; }
bool is_boxing_method() const;
@@ -5304,6 +5304,11 @@ static void check_methods_for_intrinsics(const InstanceKlass* ik,
// is defined for it.
continue;
}
if (vmIntrinsics::_blackhole == id) {
// The _blackhole intrinsic is a special marker. No explicit method
// is defined for it.
continue;
}

if (vmIntrinsics::class_for(id) == klass_id) {
// Check if the current class contains a method with the same
@@ -153,6 +153,7 @@ bool vmIntrinsics::should_be_pinned(vmIntrinsics::ID id) {
#endif
case vmIntrinsics::_currentTimeMillis:
case vmIntrinsics::_nanoTime:
case vmIntrinsics::_blackhole:
return true;
default:
return false;
@@ -534,6 +534,9 @@ class methodHandle;
do_name( getObjectSize_name, "getObjectSize0") \
do_alias( getObjectSize_signature, long_object_long_signature) \
\
/* special marker for blackholed methods: */ \
do_intrinsic(_blackhole, java_lang_Object, blackhole_name, star_name, F_S) \
\
/* unsafe memory references (there are a lot of them...) */ \
do_signature(getReference_signature, "(Ljava/lang/Object;J)Ljava/lang/Object;") \
do_signature(putReference_signature, "(Ljava/lang/Object;JLjava/lang/Object;)V") \
@@ -283,6 +283,7 @@
template(signature_name, "signature") \
template(slot_name, "slot") \
template(trusted_final_name, "trustedFinal") \
template(blackhole_name, "<blackhole>") /*fake name*/ \
\
/* Support for annotations (JDK 1.5 and above) */ \
\
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -306,6 +306,11 @@ static void register_command(TypedMethodOptionMatcher* matcher,
}
assert(CompilerOracle::option_matches_type(option, value), "Value must match option type");

if (option == CompileCommand::Blackhole && !UnlockExperimentalVMOptions) {
warning("Blackhole compile option is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions");
return;
}

matcher->init(option, option_list);
matcher->set_value<T>(value);
option_list = matcher;
@@ -417,6 +422,37 @@ bool CompilerOracle::should_break_at(const methodHandle& method) {
return check_predicate(CompileCommand::Break, method);
}

void CompilerOracle::tag_blackhole_if_possible(const methodHandle& method) {
if (!check_predicate(CompileCommand::Blackhole, method)) {
return;
}
guarantee(UnlockExperimentalVMOptions, "Checked during initial parsing");
if (method->result_type() != T_VOID) {
warning("Blackhole compile option only works for methods with void type: %s",
method->name_and_sig_as_C_string());
return;
}
if (!method->is_empty_method()) {
warning("Blackhole compile option only works for empty methods: %s",
method->name_and_sig_as_C_string());
return;
}
if (!method->is_static()) {
warning("Blackhole compile option only works for static methods: %s",
method->name_and_sig_as_C_string());
return;
}
if (method->intrinsic_id() == vmIntrinsics::_blackhole) {
return;
}
if (method->intrinsic_id() != vmIntrinsics::_none) {
warning("Blackhole compile option only works for methods that do not have intrinsic set: %s, %s",
method->name_and_sig_as_C_string(), vmIntrinsics::name_at(method->intrinsic_id()));
return;
}
method->set_intrinsic_id(vmIntrinsics::_blackhole);
}

static enum CompileCommand match_option_name(const char* line, int* bytes_read, char* errorbuf, int bufsize) {
assert(ARRAY_SIZE(option_names) == static_cast<int>(CompileCommand::Count), "option_names size mismatch");

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -51,6 +51,7 @@ class methodHandle;
option(Print, "print", Bool) \
option(Inline, "inline", Bool) \
option(DontInline, "dontinline", Bool) \
option(Blackhole, "blackhole", Bool) \
option(CompileOnly, "compileonly", Bool)\
option(Exclude, "exclude", Bool) \
option(Break, "break", Bool) \
@@ -144,6 +145,9 @@ class CompilerOracle : AllStatic {
// Tells whether there are any methods to print for print_method_statistics()
static bool should_print_methods();

// Tags the method as blackhole candidate, if possible.
static void tag_blackhole_if_possible(const methodHandle& method);

// A wrapper for checking bool options
static bool has_option(const methodHandle& method, enum CompileCommand option);

@@ -28,6 +28,7 @@
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "code/codeCache.hpp"
#include "compiler/compilerOracle.hpp"
#include "compiler/compileTask.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
@@ -991,6 +992,7 @@ JVMCIObject JVMCIEnv::get_jvmci_method(const methodHandle& method, JVMCI_TRAPS)
jmetadata handle = _runtime->allocate_handle(method);
jboolean exception = false;
if (is_hotspot()) {
CompilerOracle::tag_blackhole_if_possible(method);
JavaValue result(T_OBJECT);
JavaCallArguments args;
args.push_long((jlong) handle);
@@ -677,6 +677,8 @@ bool C2Compiler::is_intrinsic_supported(const methodHandle& method, bool is_virt
case vmIntrinsics::_VectorInsert:
case vmIntrinsics::_VectorExtract:
return EnableVectorSupport;
case vmIntrinsics::_blackhole:
break;

default:
return false;
@@ -44,6 +44,7 @@ macro(ArrayCopy)
macro(AryEq)
macro(AtanD)
macro(Binary)
macro(Blackhole)
macro(Bool)
macro(BoxLock)
macro(ReverseBytesI)
@@ -3519,6 +3519,8 @@ void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& f
}
break;
}
case Op_Blackhole:
break;
case Op_RangeCheck: {
RangeCheckNode* rc = n->as_RangeCheck();
Node* iff = new IfNode(rc->in(0), rc->in(1), rc->_prob, rc->_fcnt);
@@ -111,7 +111,7 @@ JVMState* LibraryIntrinsic::generate(JVMState* jvms) {
Node* ctrl = kit.control();
#endif
// Try to inline the intrinsic.
if ((CheckIntrinsics ? callee->intrinsic_candidate() : true) &&
if (callee->check_intrinsic_candidate() &&
kit.try_to_inline(_last_predicate)) {
const char *inline_msg = is_virtual() ? "(intrinsic, virtual)"
: "(intrinsic)";
@@ -669,6 +669,9 @@ bool LibraryCallKit::try_to_inline(int predicate) {
case vmIntrinsics::_getObjectSize:
return inline_getObjectSize();

case vmIntrinsics::_blackhole:
return inline_blackhole();

default:
// If you get here, it may be that someone has added a new intrinsic
// to the list in vmIntrinsics.hpp without implementing it here.
@@ -6911,3 +6914,23 @@ bool LibraryCallKit::inline_getObjectSize() {

return true;
}

//------------------------------- inline_blackhole --------------------------------------
//
// Make sure all arguments to this node are alive.
// This matches methods that were requested to be blackholed through compile commands.
//
bool LibraryCallKit::inline_blackhole() {
assert(callee()->is_static(), "Should have been checked before: only static methods here");
assert(callee()->is_empty(), "Should have been checked before: only empty methods here");
assert(callee()->holder()->is_loaded(), "Should have been checked before: only methods for loaded classes here");

// Bind call arguments as blackhole arguments to keep them alive
Node* bh = insert_mem_bar(Op_Blackhole);
uint nargs = callee()->arg_size();
for (uint i = 0; i < nargs; i++) {
bh->add_req(argument(i));
}

return true;
}
@@ -344,5 +344,7 @@ class LibraryCallKit : public GraphKit {
}

bool inline_getObjectSize();

bool inline_blackhole();
};

@@ -34,6 +34,7 @@
#include "opto/addnode.hpp"
#include "opto/arraycopynode.hpp"
#include "opto/cfgnode.hpp"
#include "opto/regalloc.hpp"
#include "opto/compile.hpp"
#include "opto/connode.hpp"
#include "opto/convertnode.hpp"
@@ -3305,6 +3306,7 @@ MemBarNode* MemBarNode::make(Compile* C, int opcode, int atp, Node* pn) {
case Op_OnSpinWait: return new OnSpinWaitNode(C, atp, pn);
case Op_Initialize: return new InitializeNode(C, atp, pn);
case Op_MemBarStoreStore: return new MemBarStoreStoreNode(C, atp, pn);
case Op_Blackhole: return new BlackholeNode(C, atp, pn);
default: ShouldNotReachHere(); return NULL;
}
}
@@ -3539,6 +3541,27 @@ MemBarNode* MemBarNode::leading_membar() const {
return mb;
}

#ifndef PRODUCT
void BlackholeNode::format(PhaseRegAlloc* ra, outputStream* st) const {
st->print("blackhole ");
bool first = true;
for (uint i = 0; i < req(); i++) {
Node* n = in(i);
if (n != NULL && OptoReg::is_valid(ra->get_reg_first(n))) {
if (first) {
first = false;
} else {
st->print(", ");
}
char buf[128];
ra->dump_register(n, buf);
st->print("%s", buf);
}
}
st->cr();
}
#endif

//===========================InitializeNode====================================
// SUMMARY:
// This node acts as a memory barrier on raw memory, after some raw stores.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@@ -1337,6 +1337,26 @@ class OnSpinWaitNode: public MemBarNode {
virtual int Opcode() const;
};

//------------------------------BlackholeNode----------------------------
// Blackhole all arguments. This node would survive through the compiler
// the effects on its arguments, and would be finally matched to nothing.
class BlackholeNode : public MemBarNode {
public:
BlackholeNode(Compile* C, int alias_idx, Node* precedent)
: MemBarNode(C, alias_idx, precedent) {}
virtual int Opcode() const;
virtual uint ideal_reg() const { return 0; } // not matched in the AD file
const RegMask &in_RegMask(uint idx) const {
// Fake the incoming arguments mask for blackholes: accept all registers
// and all stack slots. This would avoid any redundant register moves
// for blackhole inputs.
return RegMask::All;
}
#ifndef PRODUCT
virtual void format(PhaseRegAlloc* ra, outputStream* st) const;
#endif
};

// Isolation of object setup after an AllocateNode and before next safepoint.
// (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.)
class InitializeNode: public MemBarNode {
@@ -44,6 +44,7 @@ class AllocateNode;
class ArrayCopyNode;
class BaseCountedLoopNode;
class BaseCountedLoopEndNode;
class BlackholeNode;
class Block;
class BoolNode;
class BoxLockNode;

0 comments on commit 6018336

Please sign in to comment.