Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
829b8c6e
Commit
829b8c6e
authored
7 years ago
by
Florian Angerer
Browse files
Options
Downloads
Patches
Plain Diff
Synchronizing FD cache.
parent
2b05e288
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java
+32
-28
32 additions, 28 deletions
...me/src/com/oracle/truffle/r/runtime/env/REnvironment.java
with
32 additions
and
28 deletions
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/REnvironment.java
+
32
−
28
View file @
829b8c6e
...
...
@@ -24,6 +24,8 @@ package com.oracle.truffle.r.runtime.env;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.WeakHashMap
;
import
java.util.regex.Pattern
;
...
...
@@ -114,6 +116,8 @@ import com.oracle.truffle.r.runtime.env.frame.REnvTruffleFrameAccess;
public
abstract
class
REnvironment
extends
RAttributeStorage
{
public
static
final
class
ContextStateImpl
implements
RContext
.
ContextState
{
private
static
Map
<
RStringVector
,
WeakReference
<
FrameDescriptor
>>
frameDescriptorCache
;
private
final
MaterializedFrame
globalFrame
;
@CompilationFinal
private
Base
baseEnv
;
@CompilationFinal
private
REnvironment
namespaceRegistry
;
...
...
@@ -179,6 +183,33 @@ public abstract class REnvironment extends RAttributeStorage {
this
.
namespaceRegistry
=
newNamespaceRegistry
;
this
.
searchPath
=
newSearchPath
;
}
public
static
FrameDescriptor
getFrameDescriptorFromList
(
RList
list
)
{
CompilerAsserts
.
neverPartOfCompilation
();
// create lazily
if
(
frameDescriptorCache
==
null
)
{
frameDescriptorCache
=
Collections
.
synchronizedMap
(
new
WeakHashMap
<>());
}
RStringVector
names
=
list
.
getNames
();
WeakReference
<
FrameDescriptor
>
weakReference
=
frameDescriptorCache
.
get
(
names
);
FrameDescriptor
fd
=
weakReference
!=
null
?
weakReference
.
get
()
:
null
;
if
(
fd
==
null
)
{
// ensure that string vector is not modified anymore
names
.
makeSharedPermanent
();
fd
=
RRuntime
.
createFrameDescriptorWithMetaData
(
"<new-cachedfd-env>"
);
for
(
int
i
=
0
;
i
<
list
.
getLength
();
i
++)
{
FrameSlotKind
valueSlotKind
=
RRuntime
.
getSlotKind
(
list
.
getDataAt
(
i
));
FrameSlotChangeMonitor
.
findOrAddFrameSlot
(
fd
,
names
.
getDataAt
(
i
),
valueSlotKind
);
}
frameDescriptorCache
.
put
(
names
,
new
WeakReference
<>(
fd
));
}
return
fd
;
}
}
public
static
class
PutException
extends
RErrorException
{
...
...
@@ -670,7 +701,7 @@ public abstract class REnvironment extends RAttributeStorage {
REnvironment
result
;
RStringVector
names
=
list
.
getNames
();
if
(
list
.
getLength
()
>=
LARGE_LIST_THRESHOLD
)
{
FrameDescriptor
cachedFd
=
getFrameDescriptorFromList
(
list
);
FrameDescriptor
cachedFd
=
ContextStateImpl
.
getFrameDescriptorFromList
(
list
);
result
=
RDataFactory
.
createNewEnv
(
cachedFd
,
null
);
}
else
{
result
=
RDataFactory
.
createNewEnv
(
null
);
...
...
@@ -686,33 +717,6 @@ public abstract class REnvironment extends RAttributeStorage {
return
result
;
}
private
static
WeakHashMap
<
RStringVector
,
WeakReference
<
FrameDescriptor
>>
frameDescriptorCache
;
public
static
FrameDescriptor
getFrameDescriptorFromList
(
RList
list
)
{
// create lazily
if
(
frameDescriptorCache
==
null
)
{
frameDescriptorCache
=
new
WeakHashMap
<>();
}
RStringVector
names
=
list
.
getNames
();
WeakReference
<
FrameDescriptor
>
weakReference
=
frameDescriptorCache
.
get
(
names
);
FrameDescriptor
fd
=
weakReference
!=
null
?
weakReference
.
get
()
:
null
;
if
(
fd
==
null
)
{
// ensure that string vector is not modified anymore
names
.
makeSharedPermanent
();
fd
=
RRuntime
.
createFrameDescriptorWithMetaData
(
"<new-cachedfd-env>"
);
for
(
int
i
=
0
;
i
<
list
.
getLength
();
i
++)
{
FrameSlotKind
valueSlotKind
=
RRuntime
.
getSlotKind
(
list
.
getDataAt
(
i
));
FrameSlotChangeMonitor
.
findOrAddFrameSlot
(
fd
,
names
.
getDataAt
(
i
),
valueSlotKind
);
}
frameDescriptorCache
.
put
(
names
,
new
WeakReference
<>(
fd
));
}
return
fd
;
}
// END of static methods
public
static
final
String
NAMESPACE_KEY
=
".__NAMESPACE__."
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment