RFR: 8330851: C2: More efficient TypeFunc creation
Amit Kumar
amitkumar at openjdk.org
Thu Nov 7 04:32:14 UTC 2024
On Tue, 5 Nov 2024 06:53:46 GMT, Dean Long <dlong at openjdk.org> wrote:
>> with that change I am getting this error:
>>
>> === Output from failing command(s) repeated here ===
>> * For target hotspot_variant-server_libjvm_objs_BUILD_LIBJVM_run_ld:
>> Undefined symbols for architecture arm64:
>> "LockNode::_lock_type_tf", referenced from:
>> GraphKit::shared_lock(Node*) in graphKit.o
>> LockNode::lock_type_init() in type.o
>> ld: symbol(s) not found for architecture arm64
>> clang++: error: linker command failed with exit code 1 (use -v to see invocation)
>>
>>
>> Here is shorter version:
>>
>> class Temp {
>> public:
>> static const int* ptr;
>>
>> public:
>> static void set_ptr() {
>> const int *abs = new int(20);
>> ptr = abs;
>> }
>> };
>>
>> // Initialize static member;
>> const int* Temp::ptr = nullptr;
>>
>> int main() {
>> Temp::set_ptr();
>> cout << *Temp::ptr << endl;
>> return 0;
>> }
>>
>>
>> If I comment out `const int* Temp::ptr = nullptr;` then I am getting the similar error as I pasted above which I got from the build failure. Here we might need to give the definition out of scope of the class.
>>
>>
>> Another solution is making the data-field inline:
>>
>> class Temp {
>> public:
>> static inline const int* ptr = nullptr;
>>
>> public:
>> static void set_ptr() {
>> const int *abs = new int(20);
>> ptr = abs;
>> }
>> };
>>
>> // Initialize static member;
>> //const int* Temp::ptr = nullptr;
>>
>> int main() {
>> Temp::set_ptr();
>> cout << *Temp::ptr << endl;
>> return 0;
>> }
>>
>>
>> Here If we mark `ptr` as inline variable that is also acceptable, though C++17 started accepting it, but hotspot code is throwing warning over there as well.
>
>> Here we might need to give the definition out of scope of the class.
>
> Yes. For example, in callnode.cpp:
>
> const TypeFunc *LockNode::_lock_type_tf = nullptr;
@dean-long I have updated the patch, please have a look at the current changes :-)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21782#issuecomment-2457088617
More information about the hotspot-compiler-dev
mailing list