Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define suppressEA option and implement regular expression matching based on a location in IL #6872

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corp. and others
* Copyright (c) 2000, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1097,6 +1097,7 @@ TR::OptionTable OMR::Options::_jitOptions[] = {
{"suffixLogs", "O\tadd the date/time/pid suffix to the file name of the logs", SET_OPTION_BIT(TR_EnablePIDExtension), "F", NOT_IN_SUBSET},
{"suffixLogsFormat=", "O\tadd the suffix in specified format to the file name of the logs", TR::Options::setString, offsetof(OMR::Options, _suffixLogsFormat), 0, "P%s", NOT_IN_SUBSET},
{"supportSwitchToInterpeter", "C\tGenerate code to allow each method to switch to the interpreter", SET_OPTION_BIT(TR_SupportSwitchToInterpreter), "P"},
{"suppressEA=", "O{regex}\tSuppress stack allocations by Escape Analysis at locations that match the specified regex", TR::Options::setRegex, offsetof(OMR::Options, _suppressEA), 0, "P"},
{"suspendCompThreadsEarly", "M\tSuspend compilation threads when QWeight drops under a threshold", SET_OPTION_BIT(TR_SuspendEarly), "F", NOT_IN_SUBSET },
{"terseRegisterPressureTrace","L\tinclude only summary info about register pressure tracing when traceGRA is enabled", SET_OPTION_BIT(TR_TerseRegisterPressureTrace), "P" },
{"test390LitPoolBufferSize=", "L\tInsert 8byte elements into Lit Pool to force testing of large lit pool sizes",
Expand Down
4 changes: 3 additions & 1 deletion compiler/control/OMROptions.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corp. and others
* Copyright (c) 2000, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1716,6 +1716,7 @@ class OMR_EXTENSIBLE Options
TR::SimpleRegex * getPackedTestRegex() {return _packedTest;}
TR::SimpleRegex * getClassesWithFoldableFinalFields(){return _classesWithFolableFinalFields;}
TR::SimpleRegex * getDisabledIdiomPatterns() {return _disabledIdiomPatterns;}
TR::SimpleRegex * getSuppressEARegex() {return _suppressEA;}

char* getInduceOSR() {return _induceOSR;}
int32_t getBigCalleeThreshold() const {return _bigCalleeThreshold;}
Expand Down Expand Up @@ -2355,6 +2356,7 @@ class OMR_EXTENSIBLE Options
TR::SimpleRegex * _memUsage;
TR::SimpleRegex * _classesWithFolableFinalFields;
TR::SimpleRegex * _disabledIdiomPatterns;
TR::SimpleRegex * _suppressEA;
uintptr_t _gcCardSize;
uintptr_t _heapBase;
uintptr_t _heapTop;
Expand Down
54 changes: 53 additions & 1 deletion compiler/infra/SimpleRegex.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corp. and others
* Copyright (c) 2000, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -30,6 +30,7 @@
#include "env/StackMemoryRegion.hpp"
#include "env/VerboseLog.hpp"
#include "il/DataTypes.hpp"
#include "infra/String.hpp"
#include "ras/Debug.hpp"
#include "ras/IgnoreLocale.hpp"

Expand Down Expand Up @@ -486,6 +487,57 @@ bool SimpleRegex::match(
return result;
}

bool SimpleRegex::match(
TR::SimpleRegex *regex,
TR_ByteCodeInfo& bcinfo,
bool isCaseSensitive)
{
TR::Compilation *comp = TR::comp();
TR::StackMemoryRegion stackMemoryRegion(*comp->trMemory());
TR::StringBuf buf(stackMemoryRegion);

// Append the signature of the outermost method
buf.appendf("#%s", comp->signature());
size_t outermostSigEnd = buf.len();

if (bcinfo.getCallerIndex() > -1)
{
int inlineDepth = 0;
int16_t callerIndex = bcinfo.getCallerIndex();
TR_Stack<int16_t> callSiteStack(comp->trMemory(), 8, false, stackAlloc);

// Populate a stack of inlined method invocations, pushing from
// the innermost to the outermost inlined method invocation
do
{
callSiteStack.push(callerIndex);
callerIndex = comp->getInlinedCallSite(callerIndex)._byteCodeInfo.getCallerIndex();
}
while (callerIndex > -1);

// Run through the stack of inlined method invocations from the
// outermost inlined method invocation to the innermost, appending the
// bytecode offset of the caller and the method signature of the callee
do
{
callerIndex = callSiteStack.pop();
buf.appendf("@%d#%s", comp->getInlinedCallSite(callerIndex)._byteCodeInfo.getByteCodeIndex(),
comp->getInlinedResolvedMethod(callerIndex)->signature(comp->trMemory()));
}
while (!callSiteStack.isEmpty());
}

// Append the bytecode offset of the actual location we're interested in
buf.appendf("@%d", bcinfo.getByteCodeIndex());

// The outermost method signature is optional - attempt to match the regular
// expression both with and without that signature
bool result = regex->match(buf.text(), isCaseSensitive, true)
|| regex->match(buf.text()+outermostSigEnd, isCaseSensitive, true);

return result;
}


bool SimpleRegex::matchIgnoringLocale(
TR::SimpleRegex *regex,
Expand Down
34 changes: 33 additions & 1 deletion compiler/infra/SimpleRegex.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
* Copyright (c) 2000, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -59,6 +59,38 @@ class SimpleRegex
static bool match(TR::SimpleRegex *regex, const char *, bool isCaseSensitive=true);
static bool match(TR::SimpleRegex *regex, int, bool isCaseSensitive=true);
static bool match(TR::SimpleRegex *regex, TR_ResolvedMethod *, bool isCaseSensitive=true);

/**
* \brief Check whether a location identified by the specified \ref TR_ByteCodeInfo
* matches the specified regular expression
*
* The location described by the \c bcInfo argument is expanded into a string of the
* form
*
* [<tt>\#</tt> <em>outer-method-sig</em>] <tt>\@</tt> <em>bc-offset</em> { <tt>\#</tt> <em>callee-method-sig</em> <tt>\@</tt> <em>bc-offset</em> }*
*
* where each <i>callee-method-sig</i> is the signature of an inlined method invocation,
* and each <i>bc-offset</i> is a bytecode offset within the particular method. The outermost method
* signature is optional.
*
* For example, if the outermost method <code>Outer.out()V</code> has an inlined reference to
* <code>Middle.mid()Z</code> at bytecode offset 13, and that in turn has an inlined
* reference to <code>Inner.in()I</code> at bytecode offset 17, then bytecode offset 19 of
* that innermost inlined reference would have the following two forms:
*
* <ul>
* <li><tt>#Outer.out()V@13#Middle.mid()Z@17#Inner.in()I@19</tt>
* <li><tt>@13#Middle.mid()Z@17#Inner.in()I@19</tt>
* </ul>
*
* If either form of the location matches the regular expression, the match is successful.
*
* \param[in] regex The regular expression against which to match
* \param[in] bcInfo A location in the IL
* \param[in] isCaseSensitive Optional. Specifies whether the case of letters is significant in matching. Default is \c true.
* \return \c true if the location matches the specified regular expression; \c false otherwise
*/
static bool match(TR::SimpleRegex *regex, TR_ByteCodeInfo &bcInfo, bool isCaseSensitive=true);
static bool matchIgnoringLocale(TR::SimpleRegex *regex, const char *, bool isCaseSensitive=true);

void print(bool negate);
Expand Down