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
28984710
Commit
28984710
authored
7 years ago
by
Florian Angerer
Browse files
Options
Downloads
Patches
Plain Diff
Refined assertion in 'NativeDataAccess' and introduced empty array marker
address.
parent
01198b9c
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/data/NativeDataAccess.java
+24
-10
24 additions, 10 deletions
...c/com/oracle/truffle/r/runtime/data/NativeDataAccess.java
with
24 additions
and
10 deletions
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/NativeDataAccess.java
+
24
−
10
View file @
28984710
...
@@ -96,6 +96,8 @@ public final class NativeDataAccess {
...
@@ -96,6 +96,8 @@ public final class NativeDataAccess {
private
static
final
boolean
TRACE_MIRROR_ALLOCATION_SITES
=
false
;
private
static
final
boolean
TRACE_MIRROR_ALLOCATION_SITES
=
false
;
private
static
final
long
EMPTY_DATA_ADDRESS
=
0xDEAD
L
;
public
static
boolean
isNativeMirror
(
Object
o
)
{
public
static
boolean
isNativeMirror
(
Object
o
)
{
return
o
instanceof
NativeMirror
;
return
o
instanceof
NativeMirror
;
}
}
...
@@ -132,9 +134,16 @@ public final class NativeDataAccess {
...
@@ -132,9 +134,16 @@ public final class NativeDataAccess {
@TruffleBoundary
@TruffleBoundary
void
allocateNative
(
Object
source
,
int
len
,
int
elementBase
,
int
elementSize
)
{
void
allocateNative
(
Object
source
,
int
len
,
int
elementBase
,
int
elementSize
)
{
assert
dataAddress
==
0
;
assert
dataAddress
==
0
;
dataAddress
=
UnsafeAdapter
.
UNSAFE
.
allocateMemory
(
len
*
elementSize
);
if
(
len
!=
0
)
{
UnsafeAdapter
.
UNSAFE
.
copyMemory
(
source
,
elementBase
,
null
,
dataAddress
,
len
*
elementSize
);
dataAddress
=
UnsafeAdapter
.
UNSAFE
.
allocateMemory
(
len
*
elementSize
);
UnsafeAdapter
.
UNSAFE
.
copyMemory
(
source
,
elementBase
,
null
,
dataAddress
,
len
*
elementSize
);
}
else
{
dataAddress
=
EMPTY_DATA_ADDRESS
;
}
this
.
length
=
len
;
this
.
length
=
len
;
// ensure that marker address is not used
assert
this
.
length
==
0
||
dataAddress
!=
EMPTY_DATA_ADDRESS
;
}
}
@TruffleBoundary
@TruffleBoundary
...
@@ -146,6 +155,9 @@ public final class NativeDataAccess {
...
@@ -146,6 +155,9 @@ public final class NativeDataAccess {
UnsafeAdapter
.
UNSAFE
.
putByte
(
dataAddress
+
bytes
.
length
,
(
byte
)
0
);
// C strings
UnsafeAdapter
.
UNSAFE
.
putByte
(
dataAddress
+
bytes
.
length
,
(
byte
)
0
);
// C strings
// terminator
// terminator
this
.
length
=
bytes
.
length
+
1
;
this
.
length
=
bytes
.
length
+
1
;
// ensure that marker address is not used
assert
this
.
length
==
0
||
dataAddress
!=
EMPTY_DATA_ADDRESS
;
}
}
@Override
@Override
...
@@ -153,7 +165,9 @@ public final class NativeDataAccess {
...
@@ -153,7 +165,9 @@ public final class NativeDataAccess {
super
.
finalize
();
super
.
finalize
();
nativeMirrors
.
remove
(
id
);
nativeMirrors
.
remove
(
id
);
// System.out.println(String.format("gc'ing %16x", id));
// System.out.println(String.format("gc'ing %16x", id));
if
(
dataAddress
!=
0
)
{
if
(
dataAddress
==
EMPTY_DATA_ADDRESS
)
{
assert
(
dataAddress
=
0xbadbad
)
!=
0
;
}
else
if
(
dataAddress
!=
0
)
{
// System.out.println(String.format("freeing data at %16x", dataAddress));
// System.out.println(String.format("freeing data at %16x", dataAddress));
UnsafeAdapter
.
UNSAFE
.
freeMemory
(
dataAddress
);
UnsafeAdapter
.
UNSAFE
.
freeMemory
(
dataAddress
);
assert
(
dataAddress
=
0xbadbad
)
!=
0
;
assert
(
dataAddress
=
0xbadbad
)
!=
0
;
...
@@ -493,7 +507,7 @@ public final class NativeDataAccess {
...
@@ -493,7 +507,7 @@ public final class NativeDataAccess {
}
else
{
}
else
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
long
address
=
mirror
.
dataAddress
;
long
address
=
mirror
.
dataAddress
;
assert
address
!=
0
;
assert
address
!=
0
||
address
==
EMPTY_DATA_ADDRESS
;
int
length
=
0
;
int
length
=
0
;
while
(
length
<
mirror
.
length
&&
UnsafeAdapter
.
UNSAFE
.
getByte
(
address
+
length
)
!=
0
)
{
while
(
length
<
mirror
.
length
&&
UnsafeAdapter
.
UNSAFE
.
getByte
(
address
+
length
)
!=
0
)
{
length
++;
length
++;
...
@@ -507,7 +521,7 @@ public final class NativeDataAccess {
...
@@ -507,7 +521,7 @@ public final class NativeDataAccess {
static
long
allocateNativeContents
(
RLogicalVector
vector
,
byte
[]
data
,
int
length
)
{
static
long
allocateNativeContents
(
RLogicalVector
vector
,
byte
[]
data
,
int
length
)
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
assert
mirror
!=
null
;
assert
mirror
!=
null
;
assert
mirror
.
dataAddress
==
0
^
data
==
null
;
assert
mirror
.
dataAddress
==
0
^
(
data
==
null
||
mirror
.
dataAddress
==
EMPTY_DATA_ADDRESS
)
;
if
(
mirror
.
dataAddress
==
0
)
{
if
(
mirror
.
dataAddress
==
0
)
{
int
[]
intArray
=
new
int
[
data
.
length
];
int
[]
intArray
=
new
int
[
data
.
length
];
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
...
@@ -522,7 +536,7 @@ public final class NativeDataAccess {
...
@@ -522,7 +536,7 @@ public final class NativeDataAccess {
static
long
allocateNativeContents
(
RIntVector
vector
,
int
[]
data
,
int
length
)
{
static
long
allocateNativeContents
(
RIntVector
vector
,
int
[]
data
,
int
length
)
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
assert
mirror
!=
null
;
assert
mirror
!=
null
;
assert
mirror
.
dataAddress
==
0
^
data
==
null
;
assert
mirror
.
dataAddress
==
0
^
(
data
==
null
||
mirror
.
dataAddress
==
EMPTY_DATA_ADDRESS
)
;
if
(
mirror
.
dataAddress
==
0
)
{
if
(
mirror
.
dataAddress
==
0
)
{
noIntNative
.
invalidate
();
noIntNative
.
invalidate
();
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_INT_BASE_OFFSET
,
Unsafe
.
ARRAY_INT_INDEX_SCALE
);
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_INT_BASE_OFFSET
,
Unsafe
.
ARRAY_INT_INDEX_SCALE
);
...
@@ -533,7 +547,7 @@ public final class NativeDataAccess {
...
@@ -533,7 +547,7 @@ public final class NativeDataAccess {
static
long
allocateNativeContents
(
RRawVector
vector
,
byte
[]
data
,
int
length
)
{
static
long
allocateNativeContents
(
RRawVector
vector
,
byte
[]
data
,
int
length
)
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
assert
mirror
!=
null
;
assert
mirror
!=
null
;
assert
mirror
.
dataAddress
==
0
^
data
==
null
;
assert
mirror
.
dataAddress
==
0
^
(
data
==
null
||
mirror
.
dataAddress
==
EMPTY_DATA_ADDRESS
)
;
if
(
mirror
.
dataAddress
==
0
)
{
if
(
mirror
.
dataAddress
==
0
)
{
noRawNative
.
invalidate
();
noRawNative
.
invalidate
();
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_BYTE_BASE_OFFSET
,
Unsafe
.
ARRAY_BYTE_INDEX_SCALE
);
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_BYTE_BASE_OFFSET
,
Unsafe
.
ARRAY_BYTE_INDEX_SCALE
);
...
@@ -544,7 +558,7 @@ public final class NativeDataAccess {
...
@@ -544,7 +558,7 @@ public final class NativeDataAccess {
static
long
allocateNativeContents
(
RDoubleVector
vector
,
double
[]
data
,
int
length
)
{
static
long
allocateNativeContents
(
RDoubleVector
vector
,
double
[]
data
,
int
length
)
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
assert
mirror
!=
null
;
assert
mirror
!=
null
;
assert
mirror
.
dataAddress
==
0
^
data
==
null
;
assert
mirror
.
dataAddress
==
0
^
(
data
==
null
||
mirror
.
dataAddress
==
EMPTY_DATA_ADDRESS
)
;
if
(
mirror
.
dataAddress
==
0
)
{
if
(
mirror
.
dataAddress
==
0
)
{
noDoubleNative
.
invalidate
();
noDoubleNative
.
invalidate
();
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_DOUBLE_BASE_OFFSET
,
Unsafe
.
ARRAY_DOUBLE_INDEX_SCALE
);
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_DOUBLE_BASE_OFFSET
,
Unsafe
.
ARRAY_DOUBLE_INDEX_SCALE
);
...
@@ -555,7 +569,7 @@ public final class NativeDataAccess {
...
@@ -555,7 +569,7 @@ public final class NativeDataAccess {
static
long
allocateNativeContents
(
RComplexVector
vector
,
double
[]
data
,
int
length
)
{
static
long
allocateNativeContents
(
RComplexVector
vector
,
double
[]
data
,
int
length
)
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
assert
mirror
!=
null
;
assert
mirror
!=
null
;
assert
mirror
.
dataAddress
==
0
^
data
==
null
;
assert
mirror
.
dataAddress
==
0
^
(
data
==
null
||
mirror
.
dataAddress
==
EMPTY_DATA_ADDRESS
)
;
if
(
mirror
.
dataAddress
==
0
)
{
if
(
mirror
.
dataAddress
==
0
)
{
noComplexNative
.
invalidate
();
noComplexNative
.
invalidate
();
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_DOUBLE_BASE_OFFSET
,
Unsafe
.
ARRAY_DOUBLE_INDEX_SCALE
*
2
);
mirror
.
allocateNative
(
data
,
length
,
Unsafe
.
ARRAY_DOUBLE_BASE_OFFSET
,
Unsafe
.
ARRAY_DOUBLE_INDEX_SCALE
*
2
);
...
@@ -566,7 +580,7 @@ public final class NativeDataAccess {
...
@@ -566,7 +580,7 @@ public final class NativeDataAccess {
static
long
allocateNativeContents
(
CharSXPWrapper
vector
,
String
contents
)
{
static
long
allocateNativeContents
(
CharSXPWrapper
vector
,
String
contents
)
{
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
NativeMirror
mirror
=
(
NativeMirror
)
vector
.
getNativeMirror
();
assert
mirror
!=
null
;
assert
mirror
!=
null
;
assert
mirror
.
dataAddress
==
0
^
contents
==
null
;
assert
mirror
.
dataAddress
==
0
^
(
contents
==
null
||
mirror
.
dataAddress
==
EMPTY_DATA_ADDRESS
)
;
if
(
mirror
.
dataAddress
==
0
)
{
if
(
mirror
.
dataAddress
==
0
)
{
noCahrSXPNative
.
invalidate
();
noCahrSXPNative
.
invalidate
();
mirror
.
allocateNative
(
contents
);
mirror
.
allocateNative
(
contents
);
...
...
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