Skip to content

Commit

Permalink
Merge pull request #12764 from jdmpapin/combine-fold-final-fields-in
Browse files Browse the repository at this point in the history
Combine the two definitions of foldFinalFieldsIn()
  • Loading branch information
0xdaryl committed May 28, 2021
2 parents d41853f + 4199650 commit 2fba124
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
35 changes: 3 additions & 32 deletions runtime/compiler/env/VMJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4011,37 +4011,6 @@ bool TR_J9VMBase::isFinalFieldPointingAtJ9Class(TR::SymbolReference *symRef, TR:

// }}} (end of predicates)

static bool foldFinalFieldsIn(const char *className, int32_t classNameLength, TR::Compilation *comp)
{
TR::SimpleRegex *classRegex = comp->getOptions()->getClassesWithFoldableFinalFields();
if (classRegex)
return TR::SimpleRegex::match(classRegex, className);
else if (classNameLength >= 17 && !strncmp(className, "java/lang/invoke/", 17))
return true; // We can ONLY do this opt to fields that are never victimized by setAccessible
else if (classNameLength >= 30 && !strncmp(className, "java/lang/String$UnsafeHelpers", 30))
return true;
else if (classNameLength >= 17 && !strncmp(className, "com/ibm/oti/vm/VM", 17))
return true;
else if (classNameLength >= 22 && !strncmp(className, "com/ibm/jit/JITHelpers", 22))
return true;
else if (classNameLength >= 23 && !strncmp(className, "java/lang/J9VMInternals", 23))
return true;
else if (classNameLength >= 34 && !strncmp(className, "java/util/concurrent/atomic/Atomic", 34))
return true;
else if (classNameLength >= 17 && !strncmp(className, "java/util/EnumMap", 17))
return true;
else if (classNameLength >= 38 && !strncmp(className, "java/util/concurrent/ThreadLocalRandom", 38))
return true;
else if (classNameLength == 16 && !strncmp(className, "java/lang/String", 16))
return true;
else if (classNameLength >= 20 && !strncmp(className, "jdk/incubator/vector", 20))
return true;
else if (classNameLength >= 22 && !strncmp(className, "jdk/internal/vm/vector", 22))
return true;
else
return false;
}

bool
TR_J9VMBase::canDereferenceAtCompileTimeWithFieldSymbol(TR::Symbol * fieldSymbol, int32_t cpIndex, TR_ResolvedMethod *owningMethod)
{
Expand Down Expand Up @@ -4084,7 +4053,9 @@ TR_J9VMBase::canDereferenceAtCompileTimeWithFieldSymbol(TR::Symbol * fieldSymbol
name = getClassNameChars((TR_OpaqueClassBlock*)fieldClass, len);
}

return foldFinalFieldsIn(name, len, comp);
bool isStatic = false;
TR_OpaqueClassBlock *clazz = NULL; // only used for static fields
return TR::TransformUtil::foldFinalFieldsIn(clazz, name, len, isStatic, comp);
}
}
return false;
Expand Down
11 changes: 10 additions & 1 deletion runtime/compiler/optimizer/J9TransformUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,14 @@ bool J9::TransformUtil::foldFinalFieldsIn(TR_OpaqueClassBlock *clazz, const char
{
TR::SimpleRegex *classRegex = comp->getOptions()->getClassesWithFoldableFinalFields();
if (classRegex)
return TR::SimpleRegex::match(classRegex, className);
{
// TR::SimpleRegex::match needs a NUL-terminated string
size_t size = classNameLength + 1;
char *name = (char*)comp->trMemory()->allocateMemory(size, stackAlloc);
strncpy(name, className, classNameLength);
name[size - 1] = '\0';
return TR::SimpleRegex::match(classRegex, name);
}
else if (classNameLength >= 17 && !strncmp(className, "java/lang/invoke/", 17))
return true; // We can ONLY do this opt to fields that are never victimized by setAccessible
else if (classNameLength >= 30 && !strncmp(className, "java/lang/String$UnsafeHelpers", 30))
Expand All @@ -441,6 +448,8 @@ bool J9::TransformUtil::foldFinalFieldsIn(TR_OpaqueClassBlock *clazz, const char
return true;
else if (classNameLength >= 17 && !strncmp(className, "java/util/EnumMap", 17))
return true;
else if (classNameLength >= 38 && !strncmp(className, "java/util/concurrent/ThreadLocalRandom", 38))
return true;
else if (classNameLength >= 18 && !strncmp(className, "java/nio/ByteOrder", 18))
return true;
else if (classNameLength >= 13 && !strncmp(className, "java/nio/Bits", 13))
Expand Down

0 comments on commit 2fba124

Please sign in to comment.