Skip to content

Commit 5619456

Browse files
authored
Merge pull request #6692 from DarthMax/JOL_fix
Prevent memory size calculation from failing on certain JVMs
2 parents 6fded8e + dac4194 commit 5619456

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

doc/modules/ROOT/pages/graph-list.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ CALL gds.graph.list(
5353
| density | Float | Density of the graph.
5454
| creationTime | Datetime | Time when the graph was projected.
5555
| modificationTime | Datetime | Time when the graph was last modified.
56-
| sizeInBytes | Integer | Number of bytes used in the Java heap to store the graph.
57-
| memoryUsage | String | Human readable description of `sizeInBytes`.
56+
| sizeInBytes | Integer | Number of bytes used in the Java heap to store the graph. This feature is not supported on all JDKs and might return -1 instead.
57+
| memoryUsage | String | Human readable description of `sizeInBytes`. This feature is not supported on all JDKs and might return null instead.
5858
|===
5959
--
6060

memory-usage/src/main/java/org/neo4j/gds/mem/MemoryUsage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ public static long sizeOf(Object thing) {
298298
if (!VmInfoHolder.VM_INFO_AVAILABLE) {
299299
return -1L;
300300
}
301-
return new GraphWalker().walk(thing).totalSize();
301+
302+
try {
303+
return new GraphWalker().walk(thing).totalSize();
304+
} catch (RuntimeException e) {
305+
return -1;
306+
}
302307
}
303308

304309
/**
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.mem;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
25+
26+
class MemoryUsageTest {
27+
28+
@Test
29+
void ofShouldNotFailIfJOLFails() {
30+
assertThatCode(() -> MemoryUsage.sizeOf(new JOLMightFail())).doesNotThrowAnyException();
31+
}
32+
33+
// The nested recursive ThreadLocal causes JOL to be unable to access some attributes of the class on the ZULU JVM
34+
private static final class JOLMightFail {
35+
private final ThreadLocal<JOLMightFail> threadLocal;
36+
37+
private JOLMightFail() {threadLocal = ThreadLocal.withInitial(() -> this);}
38+
39+
ThreadLocal<JOLMightFail> getThreadLocal() {
40+
return threadLocal;
41+
}
42+
}
43+
44+
}

proc/catalog/src/main/java/org/neo4j/gds/catalog/GraphInfo.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ static GraphInfo withMemoryUsage(
8686
GraphStore graphStore
8787
) {
8888
var sizeInBytes = MemoryUsage.sizeOf(graphStore);
89-
var memoryUsage = MemoryUsage.humanReadable(sizeInBytes);
89+
90+
var memoryUsage = sizeInBytes >= 0
91+
? MemoryUsage.humanReadable(sizeInBytes)
92+
: null;
9093

9194
return create(
9295
graphProjectConfig,

0 commit comments

Comments
 (0)