Skip to content

Commit 2863624

Browse files
committed
[GR-29879] Thread Local Globals.
PullRequest: fastr/2704
2 parents df093f0 + 0acb216 commit 2863624

File tree

10 files changed

+53
-84
lines changed

10 files changed

+53
-84
lines changed

com.oracle.truffle.r.native/fficall/Makefile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -85,8 +85,8 @@ ifeq ($(OS_NAME),Darwin)
8585
# Moreover, libR links with libRblas and libRlapack, so those get loaded transitively too
8686
# Note that packages do not link with libR properly via @rpath, but that is OK since libR will be loaded explicitly by FastR
8787
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,@loader_path/ -o $(R_LIB) -L$(FASTR_LIB_DIR) -lRblas -lRlapack $(VERSION_FLAGS)
88-
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,@loader_path/ -Wl,-undefined,dynamic_lookup -o $(NFI_LIB) $(wildcard lib/nfi/*.o) $(wildcard lib/common/*.o) $(wildcard lib/JavaGD/*.o) -L$(FASTR_LIB_DIR) -ldl -lR -lpcre2-8 -lz $(F2C) -liconv $(VERSION_FLAGS)
89-
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,@loader_path/ -Wl,-undefined,dynamic_lookup -o $(LLVM_LIB) $(wildcard lib/llvm/*.o) $(wildcard lib/common/*.o) $(wildcard lib/JavaGD/*.o) -L$(FASTR_LIB_DIR) -L$(LLVM_LIBS_DIR) -lpolyglot-mock -ldl -lR -lpcre2-8 -lz $(F2C) -liconv $(VERSION_FLAGS)
88+
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,@loader_path/ -Wl,-undefined,dynamic_lookup -o $(NFI_LIB) $(wildcard lib/nfi/*.o) $(wildcard lib/common/*.o) -L$(FASTR_LIB_DIR) -ldl -lR -lpcre2-8 -lz $(F2C) -liconv $(VERSION_FLAGS)
89+
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,@loader_path/ -Wl,-undefined,dynamic_lookup -o $(LLVM_LIB) $(wildcard lib/llvm/*.o) $(wildcard lib/common/*.o) -L$(FASTR_LIB_DIR) -L$(LLVM_LIBS_DIR) -lpolyglot-mock -ldl -lR -lpcre2-8 -lz $(F2C) -liconv $(VERSION_FLAGS)
9090

9191
# make the libraries that we just created relocable
9292
install_name_tool -id @rpath/libR.dylib $(R_LIB)
@@ -117,19 +117,19 @@ ifeq ($(OS_NAME),Darwin)
117117
else
118118
# not Darwin:
119119
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,'$$ORIGIN' -o $(R_LIB) -L$(FASTR_LIB_DIR) -lRblas -lRlapack
120-
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,'$$ORIGIN' -o $(NFI_LIB) $(wildcard lib/nfi/*.o) $(wildcard lib/common/*.o) $(wildcard lib/JavaGD/*.o) -L$(FASTR_LIB_DIR) -lRblas -lRlapack -ldl -lpcre2-8 -lz $(F2C)
120+
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,'$$ORIGIN' -o $(NFI_LIB) $(wildcard lib/nfi/*.o) $(wildcard lib/common/*.o) -L$(FASTR_LIB_DIR) -lRblas -lRlapack -ldl -lpcre2-8 -lz $(F2C)
121121
# We do not link with Rlapack and Rblas so that we can load those libraries manually later after loading libR
122122
# Otherwise Sulong would attempt to load Rlapack and Rblas and fail, because there is a dependency cycle:
123123
# libR provides xerbla_, but Rlapack/Rblas depend on it, it seems that Sulong is not able to resolve this unlike the native loader
124-
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,'$$ORIGIN' -o $(LLVM_LIB) $(wildcard lib/llvm/*.o) $(wildcard lib/common/*.o) $(wildcard lib/JavaGD/*.o) -L$(FASTR_LIB_DIR) -ldl -lpcre2-8 -lz $(F2C)
124+
$(DYLIB_LD) $(DYLIB_LDFLAGS) $(shell echo $(PKG_LDFLAGS_OVERRIDE)) -Wl,-rpath,'$$ORIGIN' -o $(LLVM_LIB) $(wildcard lib/llvm/*.o) $(wildcard lib/common/*.o) -L$(FASTR_LIB_DIR) -ldl -lpcre2-8 -lz $(F2C)
125125
endif # Darwin
126126
endif # managed
127127

128128
ifeq ($(FASTR_RFFI),managed)
129129
fficall.done: common.done
130130
touch fficall.done
131131
else
132-
fficall.done: JavaGD.done common.done fficallllvm.done
132+
fficall.done: common.done fficallllvm.done
133133
$(MAKE) -C src/truffle_nfi all
134134
touch fficall.done
135135

@@ -139,10 +139,6 @@ fficallllvm.done: common.done
139139
touch fficallllvm.done
140140
endif #managed
141141

142-
JavaGD.done:
143-
$(MAKE) -C src/JavaGD all
144-
touch JavaGD.done
145-
146142
common.done:
147143
$(MAKE) -C src/common all
148144
touch common.done
@@ -154,8 +150,6 @@ clean:
154150
rm -f fficall.done
155151
rm -f common.done
156152
rm -f fficallllvm.done
157-
$(MAKE) -C src/JavaGD clean
158-
rm -f JavaGD.done
159153
ifneq ($(FASTR_RFFI),managed)
160154
$(MAKE) -C src/truffle_nfi clean
161155
$(MAKE) -C src/truffle_llvm clean

com.oracle.truffle.r.native/fficall/src/JavaGD/Makefile

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NOTE: JavaGD files are not compiled here, but as a part of truffle_nfi
2+
and truffle_llvm. I.e. they are compiled twice, just like truffle_common

com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,15 @@
2626
#include "rffi_upcallsindex.h"
2727
#include <Rdynload.h>
2828

29-
extern __thread void* *callbacks;
29+
#ifdef FASTR_NFI
30+
#define CALLBACKS_T __thread void**
31+
#elif FASTR_LLVM
32+
#define CALLBACKS_T void**
33+
#else
34+
#error unknown RFFI backend type
35+
#endif
36+
37+
extern CALLBACKS_T callbacks;
3038

3139
// This is the complete set , including those not yet implemented
3240

com.oracle.truffle.r.native/fficall/src/truffle_llvm/Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -39,12 +39,19 @@ OBJ = ../../lib/llvm
3939
C_HDRS := $(wildcard *.h)
4040

4141
LOCAL_C_SOURCES := $(wildcard *.c)
42+
4243
TRUFFLE_COMMON_C_SOURCES := $(wildcard ../truffle_common/*.c)
4344
TRUFFLE_COMMON_H_SOURCES := $(wildcard ../truffle_common/*.h)
44-
C_SOURCES := $(LOCAL_C_SOURCES) $(TRUFFLE_COMMON_C_SOURCES)
45+
46+
JAVA_GD_C_SOURCES := $(wildcard ../JavaGD/*.c)
47+
JAVA_GD_H_SOURCES := $(wildcard ../JavaGD/*.h)
48+
49+
C_SOURCES := $(LOCAL_C_SOURCES) $(TRUFFLE_COMMON_C_SOURCES) $(JAVA_GD_C_SOURCES)
50+
4551
LOCAL_C_OBJECTS := $(addprefix $(OBJ)/, $(LOCAL_C_SOURCES:.c=.o))
4652
TRUFFLE_COMMON_C_OBJECTS := $(addprefix $(OBJ)/, $(notdir $(TRUFFLE_COMMON_C_SOURCES:.c=.o)))
47-
C_OBJECTS := $(LOCAL_C_OBJECTS) $(TRUFFLE_COMMON_C_OBJECTS)
53+
JAVA_GD_C_OBJECTS := $(addprefix $(OBJ)/, $(notdir $(JAVA_GD_C_SOURCES:.c=.o)))
54+
C_OBJECTS := $(LOCAL_C_OBJECTS) $(TRUFFLE_COMMON_C_OBJECTS) $(JAVA_GD_C_OBJECTS)
4855

4956
FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/include/R_ext
5057
LOCAL_INCLUDES = -I . -I $(abspath ../include) -I $(abspath ../common)
@@ -58,6 +65,8 @@ FFLAGS :=
5865
# uncomment to see exactly where headers are being read from
5966
#CFLAGS := $(CFLAGS) -H
6067

68+
CFLAGS := $(CFLAGS) -DFASTR_LLVM
69+
6170
all: Makefile $(C_OBJECTS)
6271

6372
$(C_OBJECTS): | $(OBJ)
@@ -71,5 +80,8 @@ $(OBJ)/%.o: %.c $(FASTR_NATIVE_DIR)/include/Rinternals.h rffiutils.h $(TRUFFLE_C
7180
$(OBJ)/%.o: ../truffle_common/%.c
7281
$(CC) $(CFLAGS) $(INCLUDES) $(SUPPRESS_WARNINGS) -c $< -o $@
7382

83+
$(OBJ)/%.o: ../JavaGD/%.c $(TOPDIR)/include/Rinternals.h $(TRUFFLE_COMMON_H_SOURCES) $(JAVA_GD_H_SOURCES) ../common/rffi_upcallsindex.h $(C_HDRS)
84+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
85+
7486
clean:
7587
rm -rf $(OBJ)

com.oracle.truffle.r.native/fficall/src/truffle_llvm/Rinternals.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,7 +38,7 @@ typedef char* (*call_bytesToNativeCharArray)(SEXP e);
3838
typedef char* (*call_charSXPToNativeCharArray)(SEXP e);
3939
typedef char* (*call_R_Home)();
4040

41-
__thread void **callbacks = NULL;
41+
CALLBACKS_T callbacks = NULL;
4242

4343
void Rinternals_setCallbacksAddress(void** theCallbacks) {
4444
callbacks = theCallbacks;

com.oracle.truffle.r.native/fficall/src/truffle_nfi/Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -33,12 +33,19 @@ OBJ = ../../lib/nfi
3333
C_HDRS := $(wildcard *.h)
3434

3535
LOCAL_C_SOURCES = $(wildcard *.c)
36+
3637
TRUFFLE_COMMON_C_SOURCES := $(wildcard ../truffle_common/*.c)
3738
TRUFFLE_COMMON_H_SOURCES := $(wildcard ../truffle_common/*.h)
38-
C_SOURCES := $(LOCAL_C_SOURCES) $(TRUFFLE_COMMON_C_SOURCES)
39+
40+
JAVA_GD_C_SOURCES := $(wildcard ../JavaGD/*.c)
41+
JAVA_GD_H_SOURCES := $(wildcard ../JavaGD/*.h)
42+
43+
C_SOURCES := $(LOCAL_C_SOURCES) $(TRUFFLE_COMMON_C_SOURCES) $(JAVA_GD_C_SOURCES)
44+
3945
TRUFFLE_COMMON_C_OBJECTS := $(addprefix $(OBJ)/, $(notdir $(TRUFFLE_COMMON_C_SOURCES:.c=.o)))
4046
LOCAL_C_OBJECTS := $(patsubst %.c,$(OBJ)/%.o,$(LOCAL_C_SOURCES))
41-
C_OBJECTS := $(LOCAL_C_OBJECTS) $(TRUFFLE_COMMON_C_OBJECTS)
47+
JAVA_GD_C_OBJECTS := $(addprefix $(OBJ)/, $(notdir $(JAVA_GD_C_SOURCES:.c=.o)))
48+
C_OBJECTS := $(LOCAL_C_OBJECTS) $(TRUFFLE_COMMON_C_OBJECTS) $(JAVA_GD_C_OBJECTS)
4249

4350
FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/include/R_ext
4451
#NFI_INCLUDES is set in environment (by mx)
@@ -50,6 +57,8 @@ INCLUDES := $(LOCAL_INCLUDES) $(FFI_INCLUDES) $(NFI_INCLUDES) $(JNI_INCLUDES)
5057
# uncomment to see exactly where headers are being read from
5158
#CFLAGS := $(CFLAGS) -H
5259

60+
CFLAGS := $(CFLAGS) -DFASTR_NFI
61+
5362
all: Makefile $(C_OBJECTS)
5463

5564
$(C_OBJECTS): | $(OBJ)
@@ -63,6 +72,9 @@ $(OBJ)/%.o: %.c $(TOPDIR)/include/Rinternals.h rffiutils.h $(TRUFFLE_COMMON_H_SO
6372
$(OBJ)/%.o: ../truffle_common/%.c $(TOPDIR)/include/Rinternals.h $(TRUFFLE_COMMON_H_SOURCES) ../common/rffi_upcallsindex.h $(C_HDRS)
6473
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
6574

75+
$(OBJ)/%.o: ../JavaGD/%.c $(TOPDIR)/include/Rinternals.h $(TRUFFLE_COMMON_H_SOURCES) $(JAVA_GD_H_SOURCES) ../common/rffi_upcallsindex.h $(C_HDRS)
76+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
77+
6678
# for debugging, to see what's really being compiled
6779
$(OBJ)/%.E: %.c $(TOPDIR)/include/Rinternals.h
6880
$(CC) -E $(CFLAGS) $(INCLUDES) -c $< > $@

com.oracle.truffle.r.native/fficall/src/truffle_nfi/Rinternals.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
2626
#include <Rinternals_common.h>
2727
#include "../common/rffi_upcalls.h"
2828

29-
__thread void **callbacks = NULL;
29+
CALLBACKS_T callbacks = NULL;
3030

3131
void Rinternals_addCallback(TruffleEnv* env, void** theCallbacks, int index, void *closure) {
3232
(*env)->newClosureRef(env, closure);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
70
1+
72

mx.fastr/copyrights/overrides

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,4 +1051,3 @@ com.oracle.truffle.r.native/fficall/src/JavaGD/javaGD.h,no.copyright
10511051
com.oracle.truffle.r.native/fficall/src/JavaGD/javaGD.c,gnu_r_gentleman_ihaka3.copyright
10521052
com.oracle.truffle.r.native/fficall/src/JavaGD/jGDtalk.h,no.copyright
10531053
com.oracle.truffle.r.native/fficall/src/JavaGD/jGDtalk.c,no.copyright
1054-
com.oracle.truffle.r.native/fficall/src/JavaGD/Makefile,no.copyright

0 commit comments

Comments
 (0)