Skip to content

Improve handling of java/lang/System entry points in CG generation #241

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

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
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
8 changes: 6 additions & 2 deletions OPAL/br/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ org.opalj {
{declaringClass = "java/lang/ClassLoader", name = "checkPackageAccess", descriptor = "(Ljava/lang/Class;Ljava/security/ProtectionDomain;)V"},
{declaringClass = "java/lang/ClassLoader", name = "addClass", descriptor = "(Ljava/lang/Class;)V"},
{declaringClass = "java/lang/ClassLoader", name = "findNative", descriptor = "(Ljava/lang/ClassLoader;Ljava/lang/String;)J"},
{declaringClass = "java/security/PrivilegedActionException", name = "<init>", descriptor = "(Ljava/lang/Exception;)V"}
{declaringClass = "java/security/PrivilegedActionException", name = "<init>", descriptor = "(Ljava/lang/Exception;)V"},
{declaringClass = "java/lang/System", name = "initPhase1", descriptor = "()V"},
{declaringClass = "java/lang/System", name = "initPhase2", descriptor = "(ZZ)I"}
{declaringClass = "java/lang/System", name = "initPhase3", descriptor = "()V"}
]
# additional entry points can be specified by adding a respective tuple that must consist of
# a class name and a method name and can be refined by also defining a method descriptor.
Expand All @@ -97,7 +100,8 @@ org.opalj {
#analysis = "org.opalj.br.analyses.cg.LibraryInstantiatedTypesFinder"

instantiatedTypes = [

"java/lang/ClassLoader",
"java/lang/Thread"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,6 @@ trait ConfigurationEntryPointsFinder extends EntryPointFinder {
)
}

if (methods.exists(_.body.isEmpty)) {
OPALLogger.warn(
"project configuration",
s"$typeName has an empty method $name); " +
"entry point ignored"
)
methods = methods.filter(_.body.isDefined)
}

entryPoints = entryPoints ++ methods

case None if !isSubtype =>
Expand Down
75 changes: 75 additions & 0 deletions OPAL/tac/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,81 @@ org.opalj {
// java.lang.System //
// //
//////////////////////////////////////////////////////////////////////////////////////////
{
cf = "java/lang/System",
name = "initPhase1",
desc = "()V",
pointsTo = [
{
lhs = {
cf = "java/lang/System",
name = "initPhase1",
desc = "()V"
},
rhs = {
cf = "java/lang/System",
name = "initPhase1",
desc = "()V"
instantiatedType = "Ljava/io/BufferedInputStream;"
}
}
],
methodInvocations = [
{
cf = "java/lang/System",
name = "setIn0",
desc = "(Ljava/io/InputStream;)V"
},
{
cf = "java/lang/System",
name = "setOut0",
desc = "(Ljava/io/PrintStream;)V"
},
{
cf = "java/lang/System",
name = "setErr0",
desc = "(Ljava/io/PrintStream;)V"
},
{
cf = "java/lang/System",
name = "newPrintStream",
desc = "(Ljava/io/OutputStream;Ljava/lang/String;)Ljava/io/PrintStream;"
}
]
},
{
cf = "java/lang/System",
name = "newPrintStream",
desc = "(Ljava/io/OutputStream;Ljava/lang/String;)Ljava/io/PrintStream;",
pointsTo = [
{
lhs = {
cf = "java/lang/System",
name = "newPrintStream",
desc = "(Ljava/io/OutputStream;Ljava/lang/String;)Ljava/io/PrintStream;"
},
rhs = {
cf = "java/lang/System",
name = "newPrintStream",
desc = "(Ljava/io/OutputStream;Ljava/lang/String;)Ljava/io/PrintStream;",
instantiatedType = "Ljava/io/PrintStream;"
}
},
{
lhs = {
cf = "java/lang/System",
name = "newPrintStream",
desc = "(Ljava/io/OutputStream;Ljava/lang/String;)Ljava/io/PrintStream;"
},
rhs = {
cf = "java/lang/System",
name = "newPrintStream",
desc = "(Ljava/io/OutputStream;Ljava/lang/String;)Ljava/io/PrintStream;",
instantiatedType = "Ljava/io/BufferedOutputStream;"
}
}
]
},
{
// assigns its parameter to the field System.in
cf = "java/lang/System", name = "setIn0", desc = "(Ljava/io/InputStream;)V",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.opalj.br.analyses.cg.InitialInstantiatedTypesKey
import org.opalj.br.fpcf.FPCFAnalysisScheduler
import org.opalj.br.fpcf.properties.SimpleContextsKey
import org.opalj.tac.fpcf.analyses.cg.PropagationBasedTypeIterator
import org.opalj.tac.fpcf.analyses.cg.rta.ConfiguredNativeMethodsInstantiatedTypesAnalysisScheduler
import org.opalj.tac.fpcf.analyses.cg.xta.ArrayInstantiationsAnalysisScheduler
import org.opalj.tac.fpcf.analyses.cg.xta.ConfiguredNativeMethodsInstantiatedTypesAnalysisScheduler
import org.opalj.tac.fpcf.analyses.cg.xta.CTASetEntitySelector
import org.opalj.tac.fpcf.analyses.cg.xta.FTASetEntitySelector
import org.opalj.tac.fpcf.analyses.cg.xta.InstantiatedTypesAnalysisScheduler
Expand Down Expand Up @@ -61,7 +61,7 @@ trait PropagationBasedCallGraphKey extends CallGraphKey {
new InstantiatedTypesAnalysisScheduler(theTypeSetEntitySelector),
new ArrayInstantiationsAnalysisScheduler(theTypeSetEntitySelector),
new TypePropagationAnalysisScheduler(theTypeSetEntitySelector),
ConfiguredNativeMethodsInstantiatedTypesAnalysisScheduler,
new ConfiguredNativeMethodsInstantiatedTypesAnalysisScheduler(theTypeSetEntitySelector),
TriggeredFieldAccessInformationAnalysis,
ReflectionRelatedFieldAccessesAnalysisScheduler
) ::: (if (isLibrary) List(LibraryInstantiatedTypesBasedEntryPointsAnalysis) else Nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ class ConfiguredNativeMethodsCallGraphAnalysis private[analyses] (
// we only allow defined methods
if (!dm.hasSingleDefinedMethod) return NoResult

val method = dm.definedMethod

if (!method.isNative || !nativeMethodData.contains(dm)) {
if (!nativeMethodData.contains(dm)) {
return NoResult;
}

Expand Down
Loading