-
Notifications
You must be signed in to change notification settings - Fork 738
/
Copy pathj9methodServer.cpp
2671 lines (2363 loc) · 108 KB
/
j9methodServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright IBM Corp. and others 2018
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "j9methodServer.hpp"
#include "control/CompilationRuntime.hpp"
#include "control/CompilationThread.hpp"
#include "control/JITServerCompilationThread.hpp"
#include "control/JITServerHelpers.hpp"
#include "control/MethodToBeCompiled.hpp"
#include "env/VMJ9Server.hpp"
#include "exceptions/DataCacheError.hpp"
#include "ilgen/J9ByteCodeIterator.hpp"
#include "net/ServerStream.hpp"
ClientSessionData::ClassInfo &
getJ9ClassInfo(TR::CompilationInfoPerThread *threadCompInfo, J9Class *clazz)
{
// This function assumes that you are inside of _romMapMonitor
// Do not use it otherwise
auto &classMap = threadCompInfo->getClientData()->getROMClassMap();
auto it = classMap.find(clazz);
TR_ASSERT_FATAL(it != classMap.end(),"compThreadID %d, ClientData %p, clazz %p: ClassInfo is not in the class map %p!!\n",
threadCompInfo->getCompThreadId(), threadCompInfo->getClientData(), clazz, &classMap);
return it->second;
}
static J9ROMMethod *
romMethodAtClassIndex(J9ROMClass *romClass, uint64_t methodIndex)
{
J9ROMMethod * romMethod = J9ROMCLASS_ROMMETHODS(romClass);
for (size_t i = methodIndex; i; --i)
romMethod = nextROMMethod(romMethod);
return romMethod;
}
TR_ResolvedJ9JITServerMethod::TR_ResolvedJ9JITServerMethod(TR_OpaqueMethodBlock * aMethod, TR_FrontEnd * fe, TR_Memory * trMemory, TR_ResolvedMethod * owningMethod, uint32_t vTableSlot)
: TR_ResolvedJ9Method(fe, owningMethod)
{
TR_J9VMBase *fej9 = (TR_J9VMBase *)fe;
TR::CompilationInfo *compInfo = TR::CompilationInfo::get(fej9->getJ9JITConfig());
TR::CompilationInfoPerThread *threadCompInfo = compInfo->getCompInfoForThread(fej9->vmThread());
_stream = threadCompInfo->getMethodBeingCompiled()->_stream;
// Create client side mirror of this object to use for calls involving RAM data
TR_ResolvedJ9Method* owningMethodMirror = owningMethod ? ((TR_ResolvedJ9JITServerMethod*) owningMethod)->_remoteMirror : NULL;
// If in AOT mode, will actually create relocatable version of resolved method on the client
_stream->write(JITServer::MessageType::mirrorResolvedJ9Method, aMethod, owningMethodMirror, vTableSlot, fej9->isAOT_DEPRECATED_DO_NOT_USE());
auto recv = _stream->read<TR_ResolvedJ9JITServerMethodInfo>();
auto &methodInfo = std::get<0>(recv);
unpackMethodInfo(aMethod, fe, trMemory, vTableSlot, threadCompInfo, methodInfo);
}
TR_ResolvedJ9JITServerMethod::TR_ResolvedJ9JITServerMethod(TR_OpaqueMethodBlock * aMethod, TR_FrontEnd * fe, TR_Memory * trMemory, const TR_ResolvedJ9JITServerMethodInfo &methodInfo, TR_ResolvedMethod * owningMethod, uint32_t vTableSlot)
: TR_ResolvedJ9Method(fe, owningMethod)
{
// Mirror has already been created, its parameters are passed in methodInfo
TR_J9VMBase *fej9 = (TR_J9VMBase *)fe;
TR::CompilationInfo *compInfo = TR::CompilationInfo::get(fej9->getJ9JITConfig());
TR::CompilationInfoPerThread *threadCompInfo = compInfo->getCompInfoForThread(fej9->vmThread());
_stream = threadCompInfo->getMethodBeingCompiled()->_stream;
unpackMethodInfo(aMethod, fe, trMemory, vTableSlot, threadCompInfo, methodInfo);
}
J9ROMClass *
TR_ResolvedJ9JITServerMethod::romClassPtr()
{
return _romClass;
}
J9RAMConstantPoolItem *
TR_ResolvedJ9JITServerMethod::literals()
{
return _literals;
}
J9Class *
TR_ResolvedJ9JITServerMethod::constantPoolHdr()
{
return _ramClass;
}
bool
TR_ResolvedJ9JITServerMethod::isJNINative()
{
return _isJNINative;
}
void
TR_ResolvedJ9JITServerMethod::setRecognizedMethodInfo(TR::RecognizedMethod rm)
{
TR_ResolvedJ9Method::setRecognizedMethodInfo(rm);
_stream->write(JITServer::MessageType::ResolvedMethod_setRecognizedMethodInfo, _remoteMirror, rm);
_stream->read<JITServer::Void>();
}
J9ClassLoader *
TR_ResolvedJ9JITServerMethod::getClassLoader()
{
return _classLoader; // cached version
}
bool
TR_ResolvedJ9JITServerMethod::staticAttributes(TR::Compilation * comp, I_32 cpIndex, void * * address, TR::DataType * type, bool * volatileP, bool * isFinal, bool * isPrivate, bool isStore, bool * unresolvedInCP, bool needAOTValidation)
{
bool isStatic = true;
TR_J9MethodFieldAttributes attributes;
if(!getCachedFieldAttributes(cpIndex, attributes, isStatic))
{
// make a remote call, if attributes are not cached
_stream->write(JITServer::MessageType::ResolvedMethod_staticAttributes, _remoteMirror, cpIndex, isStore, needAOTValidation);
auto recv = _stream->read<TR_J9MethodFieldAttributes>();
attributes = std::get<0>(recv);
cacheFieldAttributes(cpIndex, attributes, isStatic);
}
else
{
TR_ASSERT(validateMethodFieldAttributes(attributes, isStatic, cpIndex, isStore, needAOTValidation), "static attributes from client and cache do not match");
}
bool result;
attributes.setMethodFieldAttributesResult(address, type, volatileP, isFinal, isPrivate, unresolvedInCP, &result);
return result;
}
TR_OpaqueClassBlock *
TR_ResolvedJ9JITServerMethod::definingClassFromCPFieldRef(TR::Compilation *comp, int32_t cpIndex, bool isStatic, TR_OpaqueClassBlock **fromResolvedJ9Method)
{
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDefiningClassCache;
auto it = cache.find(cpIndex);
if (it != cache.end())
{
if (fromResolvedJ9Method != NULL)
*fromResolvedJ9Method = it->second;
return it->second;
}
}
_stream->write(JITServer::MessageType::ResolvedMethod_definingClassFromCPFieldRef, _remoteMirror, cpIndex, isStatic);
TR_OpaqueClassBlock *resolvedClass = std::get<0>(_stream->read<TR_OpaqueClassBlock *>());
// Do not cache if the class is unresolved, because it may become resolved later on
if (resolvedClass)
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDefiningClassCache;
cache.insert({cpIndex, resolvedClass});
}
if (fromResolvedJ9Method != NULL)
*fromResolvedJ9Method = resolvedClass;
return resolvedClass;
}
TR_OpaqueClassBlock *
TR_ResolvedJ9JITServerMethod::getClassFromConstantPool(TR::Compilation * comp, uint32_t cpIndex, bool returnClassForAOT)
{
if (cpIndex == -1)
return NULL;
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
bool doRuntimeResolve = compInfoPT->getClientData()->getRtResolve() && !comp->ilGenRequest().details().isMethodHandleThunk();
if (doRuntimeResolve &&
performTransformation(comp, "Setting as unresolved class from CP cpIndex=%d\n",cpIndex))
{
return NULL;
}
{
// This persistent cache must only be checked when doRuntimeResolve is false,
// otherwise a non method handle thunk compilation can return cached value, instead of NULL.
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &constantClassPoolCache = getJ9ClassInfo(compInfoPT, _ramClass)._constantClassPoolCache;
auto it = constantClassPoolCache.find(cpIndex);
if (it != constantClassPoolCache.end())
return it->second;
}
_stream->write(JITServer::MessageType::ResolvedMethod_getClassFromConstantPool, _remoteMirror, cpIndex, returnClassForAOT);
TR_OpaqueClassBlock *resolvedClass = std::get<0>(_stream->read<TR_OpaqueClassBlock *>());
if (resolvedClass)
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &constantClassPoolCache = getJ9ClassInfo(compInfoPT, _ramClass)._constantClassPoolCache;
constantClassPoolCache.insert({cpIndex, resolvedClass});
}
return resolvedClass;
}
TR_OpaqueClassBlock *
TR_ResolvedJ9JITServerMethod::getDeclaringClassFromFieldOrStatic(TR::Compilation *comp, int32_t cpIndex)
{
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDeclaringClassCache;
auto it = cache.find(cpIndex);
if (it != cache.end())
return it->second;
}
_stream->write(JITServer::MessageType::ResolvedMethod_getDeclaringClassFromFieldOrStatic, _remoteMirror, cpIndex);
TR_OpaqueClassBlock *declaringClass = std::get<0>(_stream->read<TR_OpaqueClassBlock *>());
if (declaringClass)
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &cache = getJ9ClassInfo(compInfoPT, _ramClass)._fieldOrStaticDeclaringClassCache;
cache.insert({cpIndex, declaringClass});
}
return declaringClass;
}
TR_OpaqueClassBlock *
TR_ResolvedJ9JITServerMethod::classOfStatic(I_32 cpIndex, bool returnClassForAOT)
{
// if method is unresolved, return right away
if (cpIndex < 0)
return NULL;
auto compInfoPT = static_cast<TR::CompilationInfoPerThreadRemote *>(_fe->_compInfoPT);
{
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &classOfStaticCache = getJ9ClassInfo(compInfoPT, _ramClass)._classOfStaticCache;
auto it = classOfStaticCache.find(cpIndex);
if (it != classOfStaticCache.end())
return it->second;
}
// check per-compilation cache, which can only contain NULL values
if (compInfoPT->getCachedNullClassOfStatic((TR_OpaqueClassBlock *) _ramClass, cpIndex))
return NULL;
_stream->write(JITServer::MessageType::ResolvedMethod_classOfStatic, _remoteMirror, cpIndex, returnClassForAOT);
TR_OpaqueClassBlock *classOfStatic = std::get<0>(_stream->read<TR_OpaqueClassBlock *>());
if (classOfStatic)
{
// reacquire monitor and cache, if client returned a valid class
// if client returned NULL, don't cache, because class might not be fully initialized,
// so the result may change in the future
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &classOfStaticCache = getJ9ClassInfo(compInfoPT, _ramClass)._classOfStaticCache;
classOfStaticCache.insert({cpIndex, classOfStatic});
}
else
{
// cache NULL in a per-compilation cache, even if it becomes initialized during
// current compilation, shouldn't have much of an effect on performance.
compInfoPT->cacheNullClassOfStatic((TR_OpaqueClassBlock *) _ramClass, cpIndex);
}
return classOfStatic;
}
void *
TR_ResolvedJ9JITServerMethod::getConstantDynamicTypeFromCP(I_32 cpIndex)
{
TR_ASSERT_FATAL(cpIndex != -1, "ConstantDynamic cpIndex shouldn't be -1");
_stream->write(JITServer::MessageType::ResolvedMethod_getConstantDynamicTypeFromCP, _remoteMirror, cpIndex);
auto recv = _stream->read<std::string>();
auto &retConstantDynamicTypeStr = std::get<0>(recv);
TR_Memory *trMemory = ((TR::CompilationInfoPerThreadRemote *)_fe->_compInfoPT)->getCompilation()->trMemory();
J9UTF8 *constantDynamicType = str2utf8(retConstantDynamicTypeStr.data(), retConstantDynamicTypeStr.length(), trMemory, heapAlloc);
return constantDynamicType;
}
bool
TR_ResolvedJ9JITServerMethod::isConstantDynamic(I_32 cpIndex)
{
TR_ASSERT_FATAL(cpIndex != -1, "ConstantDynamic cpIndex shouldn't be -1");
UDATA cpType = J9_CP_TYPE(J9ROMCLASS_CPSHAPEDESCRIPTION(_romClass), cpIndex);
return (J9CPTYPE_CONSTANT_DYNAMIC == cpType);
}
bool
TR_ResolvedJ9JITServerMethod::isUnresolvedConstantDynamic(I_32 cpIndex)
{
TR_ASSERT(cpIndex != -1, "ConstantDynamic cpIndex shouldn't be -1");
_stream->write(JITServer::MessageType::ResolvedMethod_isUnresolvedConstantDynamic, _remoteMirror, cpIndex);
return std::get<0>(_stream->read<bool>());
}
void *
TR_ResolvedJ9JITServerMethod::dynamicConstant(I_32 cpIndex, uintptr_t *obj)
{
TR_ASSERT_FATAL(cpIndex != -1, "ConstantDynamic cpIndex shouldn't be -1");
_stream->write(JITServer::MessageType::ResolvedMethod_dynamicConstant, _remoteMirror, cpIndex);
auto recv = _stream->read<uintptr_t *, uintptr_t>();
uintptr_t *objLocation = std::get<0>(recv);
if (obj)
{
*obj = std::get<1>(recv);
}
return objLocation;
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedPossiblyPrivateVirtualMethod(TR::Compilation * comp, I_32 cpIndex, bool ignoreRtResolve, bool * unresolvedInCP)
{
TR_ASSERT(cpIndex != -1, "cpIndex shouldn't be -1");
#if TURN_OFF_INLINING
return 0;
#else
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
TR_ResolvedMethod *resolvedMethod = NULL;
// See if the constant pool entry is already resolved or not
if (unresolvedInCP)
*unresolvedInCP = true;
bool shouldCompileTimeResolve = shouldCompileTimeResolveMethod(cpIndex);
if (!((compInfoPT->getClientData()->getRtResolve()) &&
!comp->ilGenRequest().details().isMethodHandleThunk() && // cmvc 195373
performTransformation(comp, "Setting as unresolved virtual call cpIndex=%d\n",cpIndex) ) || ignoreRtResolve || shouldCompileTimeResolve)
{
if (compInfoPT->getCachedResolvedMethod(
compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromCP, (TR_OpaqueClassBlock *) _ramClass, cpIndex),
this,
&resolvedMethod,
unresolvedInCP))
{
if (resolvedMethod == NULL)
{
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/virtual/null");
if (unresolvedInCP)
handleUnresolvedVirtualMethodInCP(cpIndex, unresolvedInCP);
}
else
{
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/virtual");
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/virtual:#bytes", sizeof(TR_ResolvedJ9Method));
}
return resolvedMethod;
}
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedPossiblyPrivateVirtualMethodAndMirror, (TR_ResolvedMethod *) _remoteMirror, literals(), cpIndex);
auto recv = _stream->read<J9Method *, UDATA, bool, TR_ResolvedJ9JITServerMethodInfo>();
J9Method *ramMethod = std::get<0>(recv);
UDATA vTableIndex = std::get<1>(recv);
bool isUnresolvedInCP = std::get<2>(recv);
if (unresolvedInCP)
*unresolvedInCP = isUnresolvedInCP;
bool createResolvedMethod = true;
if (comp->compileRelocatableCode() && ramMethod && comp->getOption(TR_UseSymbolValidationManager))
{
if (!comp->getSymbolValidationManager()->addVirtualMethodFromCPRecord((TR_OpaqueMethodBlock *)ramMethod, cp(), cpIndex))
createResolvedMethod = false;
}
if (vTableIndex)
{
TR_AOTInliningStats *aotStats = NULL;
if (comp->getOption(TR_EnableAOTStats))
aotStats = & (((TR_JitPrivateConfig *)_fe->_jitConfig->privateConfig)->aotStats->virtualMethods);
TR_ResolvedJ9JITServerMethodInfo &methodInfo = std::get<3>(recv);
// call constructor without making a new query
if (createResolvedMethod)
{
resolvedMethod = createResolvedMethodFromJ9Method(comp, cpIndex, vTableIndex, ramMethod, unresolvedInCP, aotStats, methodInfo);
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromCP, (TR_OpaqueClassBlock *) _ramClass, cpIndex), (TR_OpaqueMethodBlock *) ramMethod, (uint32_t) vTableIndex, methodInfo);
}
}
}
TR_ASSERT_FATAL(resolvedMethod || !shouldCompileTimeResolve, "Method has to be resolved in %s at cpIndex %d", signature(comp->trMemory()), cpIndex);
if (resolvedMethod == NULL)
{
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/virtual/null");
if (unresolvedInCP)
handleUnresolvedVirtualMethodInCP(cpIndex, unresolvedInCP);
}
else
{
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/virtual");
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/virtual:#bytes", sizeof(TR_ResolvedJ9Method));
}
return resolvedMethod;
#endif
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedVirtualMethod(
TR::Compilation *comp,
I_32 cpIndex,
bool ignoreRtResolve,
bool *unresolvedInCP)
{
TR_ResolvedMethod *method = getResolvedPossiblyPrivateVirtualMethod(
comp,
cpIndex,
ignoreRtResolve,
unresolvedInCP);
return (method == NULL || method->isPrivate()) ? NULL : method;
}
bool
TR_ResolvedJ9JITServerMethod::fieldsAreSame(int32_t cpIndex1, TR_ResolvedMethod *m2, int32_t cpIndex2, bool &sigSame)
{
if (TR::comp()->compileRelocatableCode())
// in AOT, this should always return false, because mainline compares class loaders
// with fe->sameClassLoaders, which always returns false for AOT compiles
return false;
TR_ResolvedJ9JITServerMethod *serverMethod2 = static_cast<TR_ResolvedJ9JITServerMethod*>(m2);
if (getClassLoader() != serverMethod2->getClassLoader())
return false;
if (cpIndex1 == -1 || cpIndex2 == -1)
return false;
if (cpIndex1 == cpIndex2 && ramMethod() == serverMethod2->ramMethod())
return true;
int32_t sig1Len = 0, sig2Len = 0;
char *signature1 = fieldOrStaticSignatureChars(cpIndex1, sig1Len);
char *signature2 = serverMethod2->fieldOrStaticSignatureChars(cpIndex2, sig2Len);
int32_t name1Len = 0, name2Len = 0;
char *name1 = fieldOrStaticNameChars(cpIndex1, name1Len);
char *name2 = serverMethod2->fieldOrStaticNameChars(cpIndex2, name2Len);
if (sig1Len == sig2Len && !memcmp(signature1, signature2, sig1Len) &&
name1Len == name2Len && !memcmp(name1, name2, name1Len))
{
int32_t class1Len = 0, class2Len = 0;
char *declaringClassName1 = classNameOfFieldOrStatic(cpIndex1, class1Len);
char *declaringClassName2 = serverMethod2->classNameOfFieldOrStatic(cpIndex2, class2Len);
if (class1Len == class2Len && !memcmp(declaringClassName1, declaringClassName2, class1Len))
return true;
}
else
{
sigSame = false;
}
return false;
}
bool
TR_ResolvedJ9JITServerMethod::staticsAreSame(int32_t cpIndex1, TR_ResolvedMethod *m2, int32_t cpIndex2, bool &sigSame)
{
if (TR::comp()->compileRelocatableCode())
// in AOT, this should always return false, because mainline compares class loaders
// with fe->sameClassLoaders, which always returns false for AOT compiles
return false;
TR_ResolvedJ9JITServerMethod *serverMethod2 = static_cast<TR_ResolvedJ9JITServerMethod*>(m2);
if (getClassLoader() != serverMethod2->getClassLoader())
return false;
if (cpIndex1 == -1 || cpIndex2 == -1)
return false;
if (cpIndex1 == cpIndex2 && ramMethod() == serverMethod2->ramMethod())
return true;
// the client version of this method compares the addresses of values first, which we cannot do on the server.
// skipping that step affects performance, but does not affect correctness.
int32_t sig1Len = 0, sig2Len = 0;
char *signature1 = fieldOrStaticSignatureChars(cpIndex1, sig1Len);
char *signature2 = serverMethod2->fieldOrStaticSignatureChars(cpIndex2, sig2Len);
int32_t name1Len = 0, name2Len = 0;
char *name1 = fieldOrStaticNameChars(cpIndex1, name1Len);
char *name2 = serverMethod2->fieldOrStaticNameChars(cpIndex2, name2Len);
if (sig1Len == sig2Len && !memcmp(signature1, signature2, sig1Len) &&
name1Len == name2Len && !memcmp(name1, name2, name1Len))
{
int32_t class1Len = 0, class2Len = 0;
char *declaringClassName1 = classNameOfFieldOrStatic(cpIndex1, class1Len);
char *declaringClassName2 = serverMethod2->classNameOfFieldOrStatic(cpIndex2, class2Len);
if (class1Len == class2Len && !memcmp(declaringClassName1, declaringClassName2, class1Len))
return true;
}
else
{
sigSame = false;
}
return false;
}
TR_FieldAttributesCache &
TR_ResolvedJ9JITServerMethod::getAttributesCache(bool isStatic, bool unresolvedInCP)
{
// Return a persistent attributes cache for regular JIT compilations
TR::CompilationInfoPerThread *compInfoPT = _fe->_compInfoPT;
auto &attributesCache = isStatic ?
getJ9ClassInfo(compInfoPT, _ramClass)._staticAttributesCache :
getJ9ClassInfo(compInfoPT, _ramClass)._fieldAttributesCache;
return attributesCache;
}
bool
TR_ResolvedJ9JITServerMethod::getCachedFieldAttributes(int32_t cpIndex, TR_J9MethodFieldAttributes &attributes, bool isStatic)
{
auto compInfoPT = static_cast<TR::CompilationInfoPerThreadRemote *>(_fe->_compInfoPT);
{
// First, search a global cache
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &attributesCache = getAttributesCache(isStatic);
auto it = attributesCache.find(cpIndex);
if (it != attributesCache.end())
{
attributes = it->second;
return true;
}
}
// If global cache is empty, search local cache
// Local cache is searched after global, because it only stores
// unresolved field attributes, so most attributes should be stored globally
return compInfoPT->getCachedFieldOrStaticAttributes((TR_OpaqueClassBlock *) _ramClass, cpIndex, attributes, isStatic);
}
void
TR_ResolvedJ9JITServerMethod::cacheFieldAttributes(int32_t cpIndex, const TR_J9MethodFieldAttributes &attributes, bool isStatic)
{
// When caching field or static attributes, there are 2 caches where they can go:
// 1. Persistent cache - stores attributes of all resolved fields. Since the field is resolved,
// the attributes should not change, so the contents should be valid.
// 2. Per-compilation cache - stores attributes of unresolved fields, which might become resolved
// during the current compilation, but assuming they are unresolved until the end of the compilation
// is still functionally correct and does not seem to affect performance.
auto compInfoPT = static_cast<TR::CompilationInfoPerThreadRemote *>(_fe->_compInfoPT);
if (attributes.isUnresolvedInCP())
{
// field is unresolved in CP, can later become resolved, can only be cached per resolved method.
compInfoPT->cacheFieldOrStaticAttributes((TR_OpaqueClassBlock *) _ramClass, cpIndex, attributes, isStatic);
}
else
{
// field is resolved in CP, can cache globally per RAM class.
OMR::CriticalSection getRemoteROMClass(compInfoPT->getClientData()->getROMMapMonitor());
auto &attributesCache = getAttributesCache(isStatic);
#if defined(DEBUG) || defined(PROD_WITH_ASSUMES)
TR_ASSERT(canCacheFieldAttributes(cpIndex, attributes, isStatic), "new and cached field attributes are not equal");
#endif
attributesCache.insert({cpIndex, attributes});
}
}
bool
TR_ResolvedJ9JITServerMethod::canCacheFieldAttributes(int32_t cpIndex, const TR_J9MethodFieldAttributes &attributes, bool isStatic)
{
auto &attributesCache = getAttributesCache(isStatic);
auto it = attributesCache.find(cpIndex);
if (it != attributesCache.end())
{
// Attempting to cache attributes when this key is already cached.
// This case can happen when two threads call `getCachedFieldAttributes`,
// see that attributes are not cached, and they both make a remote call
// and call this method.
// Make sure that attributes they are caching are the same.
auto cachedAttrs = it->second;
return attributes == cachedAttrs;
}
return true;
}
bool
TR_ResolvedJ9JITServerMethod::fieldAttributes(TR::Compilation * comp, I_32 cpIndex, U_32 * fieldOffset, TR::DataType * type, bool * volatileP, bool * isFinal, bool * isPrivate, bool isStore, bool * unresolvedInCP, bool needAOTValidation)
{
bool isStatic = false;
TR_J9MethodFieldAttributes attributes;
if(!getCachedFieldAttributes(cpIndex, attributes, isStatic))
{
// make a remote call, if attributes are not cached
_stream->write(JITServer::MessageType::ResolvedMethod_fieldAttributes, _remoteMirror, cpIndex, isStore, needAOTValidation);
auto recv = _stream->read<TR_J9MethodFieldAttributes>();
attributes = std::get<0>(recv);
cacheFieldAttributes(cpIndex, attributes, isStatic);
}
else
{
TR_ASSERT(validateMethodFieldAttributes(attributes, isStatic, cpIndex, isStore, needAOTValidation), "field attributes from client and cache do not match");
}
bool result;
attributes.setMethodFieldAttributesResult(fieldOffset, type, volatileP, isFinal, isPrivate, unresolvedInCP, &result);
return result;
}
static bool doResolveAtRuntime(J9Method *method, I_32 cpIndex, TR::Compilation *comp)
{
if (!method)
return true;
TR_J9VMBase *fej9 = (TR_J9VMBase *)(comp->fe());
auto stream = fej9->_compInfoPT->getMethodBeingCompiled()->_stream;
if (comp->ilGenRequest().details().isMethodHandleThunk()) // cmvc 195373
{
return false;
}
else if (fej9->_compInfoPT->getClientData()->getRtResolve())
{
return performTransformation(comp, "Setting as unresolved static call cpIndex=%d\n", cpIndex);
}
return false;
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedStaticMethod(TR::Compilation * comp, I_32 cpIndex, bool * unresolvedInCP)
{
// JITServer TODO: Decide whether the counters should be updated on the server or the client
TR_ASSERT(cpIndex != -1, "cpIndex shouldn't be -1");
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
TR_ResolvedMethod *resolvedMethod = NULL;
if (compInfoPT->getCachedResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Static, (TR_OpaqueClassBlock *) _ramClass, cpIndex), this, &resolvedMethod, unresolvedInCP))
{
if ((resolvedMethod == NULL) && unresolvedInCP)
handleUnresolvedStaticMethodInCP(cpIndex, unresolvedInCP);
return resolvedMethod;
}
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedStaticMethodAndMirror, _remoteMirror, cpIndex);
auto recv = _stream->read<J9Method *, TR_ResolvedJ9JITServerMethodInfo, bool>();
J9Method * ramMethod = std::get<0>(recv);
bool isUnresolvedInCP = std::get<2>(recv);
if (unresolvedInCP)
*unresolvedInCP = isUnresolvedInCP;
if (comp->compileRelocatableCode() && comp->getOption(TR_UseSymbolValidationManager) && ramMethod)
{
if (!comp->getSymbolValidationManager()->addStaticMethodFromCPRecord((TR_OpaqueMethodBlock *)ramMethod, cp(), cpIndex))
ramMethod = NULL;
}
bool skipForDebugging = doResolveAtRuntime(ramMethod, cpIndex, comp);
if (isArchetypeSpecimen())
{
// ILGen macros currently must be resolved for correctness, or else they
// are not recognized and expanded. If we have unresolved calls, we can't
// tell whether they're ilgen macros because the recognized-method system
// only works on resovled methods.
//
if (ramMethod)
skipForDebugging = false;
else
{
comp->failCompilation<TR::ILGenFailure>("Can't compile an archetype specimen with unresolved calls");
}
}
auto &methodInfo = std::get<1>(recv);
if (ramMethod && !skipForDebugging)
{
TR_AOTInliningStats *aotStats = NULL;
if (comp->getOption(TR_EnableAOTStats))
aotStats = & (((TR_JitPrivateConfig *)_fe->_jitConfig->privateConfig)->aotStats->staticMethods);
resolvedMethod = createResolvedMethodFromJ9Method(comp, cpIndex, 0, ramMethod, unresolvedInCP, aotStats, methodInfo);
if (unresolvedInCP)
*unresolvedInCP = false;
}
if (resolvedMethod == NULL)
{
if (unresolvedInCP)
handleUnresolvedStaticMethodInCP(cpIndex, unresolvedInCP);
}
else
{
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Static, (TR_OpaqueClassBlock *) _ramClass, cpIndex), (TR_OpaqueMethodBlock *) ramMethod, 0, methodInfo);
}
return resolvedMethod;
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedSpecialMethod(TR::Compilation * comp, I_32 cpIndex, bool * unresolvedInCP)
{
// JITServer TODO: Decide whether the counters should be updated on the server or the client
TR_ASSERT(cpIndex != -1, "cpIndex shouldn't be -1");
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
TR_ResolvedMethod *resolvedMethod = NULL;
TR_OpaqueClassBlock *clazz = (TR_OpaqueClassBlock *) _ramClass;
if (compInfoPT->getCachedResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Special, clazz, cpIndex), this, &resolvedMethod, unresolvedInCP))
{
if ((resolvedMethod == NULL) && unresolvedInCP)
handleUnresolvedSpecialMethodInCP(cpIndex, unresolvedInCP);
return resolvedMethod;
}
// Comments from TR_ResolvedJ9Method::getResolvedSpecialMethod
// We init the CP with a special magic method, which has no bytecodes (hence bytecode start is NULL)
// i.e. the CP will always contain a method for special and static methods
if (unresolvedInCP)
*unresolvedInCP = true;
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedSpecialMethodAndMirror, _remoteMirror, cpIndex);
auto recv = _stream->read<J9Method *, TR_ResolvedJ9JITServerMethodInfo>();
J9Method * ramMethod = std::get<0>(recv);
auto &methodInfo = std::get<1>(recv);
if (ramMethod)
{
bool createResolvedMethod = true;
if (comp->getOption(TR_UseSymbolValidationManager))
{
if (!comp->getSymbolValidationManager()->addSpecialMethodFromCPRecord((TR_OpaqueMethodBlock *)ramMethod, cp(), cpIndex))
createResolvedMethod = false;
}
TR_AOTInliningStats *aotStats = NULL;
if (comp->getOption(TR_EnableAOTStats))
aotStats = & (((TR_JitPrivateConfig *)_fe->_jitConfig->privateConfig)->aotStats->specialMethods);
if (createResolvedMethod)
resolvedMethod = createResolvedMethodFromJ9Method(comp, cpIndex, 0, ramMethod, unresolvedInCP, aotStats, methodInfo);
if (unresolvedInCP)
*unresolvedInCP = false;
}
if (resolvedMethod == NULL)
{
if (unresolvedInCP)
handleUnresolvedSpecialMethodInCP(cpIndex, unresolvedInCP);
}
else
{
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Special, clazz, cpIndex), (TR_OpaqueMethodBlock *) ramMethod, 0, methodInfo);
}
return resolvedMethod;
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::createResolvedMethodFromJ9Method( TR::Compilation *comp, int32_t cpIndex, uint32_t vTableSlot, J9Method *j9Method, bool * unresolvedInCP, TR_AOTInliningStats *aotStats)
{
TR_ResolvedMethod *m = new (comp->trHeapMemory()) TR_ResolvedJ9JITServerMethod((TR_OpaqueMethodBlock *) j9Method, _fe, comp->trMemory(), this, vTableSlot);
if (((TR_ResolvedJ9Method*)m)->isSignaturePolymorphicMethod())
{
// Signature polymorphic method's signature varies at different call sites and will be different than its declared signature
int32_t signatureLength;
char *signature = getMethodSignatureFromConstantPool(cpIndex, signatureLength);
((TR_ResolvedJ9Method *)m)->setSignature(signature, signatureLength, comp->trMemory());
}
return m;
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::createResolvedMethodFromJ9Method( TR::Compilation *comp, int32_t cpIndex, uint32_t vTableSlot, J9Method *j9Method, bool * unresolvedInCP, TR_AOTInliningStats *aotStats, const TR_ResolvedJ9JITServerMethodInfo &methodInfo)
{
TR_ResolvedMethod *m = new (comp->trHeapMemory()) TR_ResolvedJ9JITServerMethod((TR_OpaqueMethodBlock *) j9Method, _fe, comp->trMemory(), methodInfo, this, vTableSlot);
if (((TR_ResolvedJ9Method*)m)->isSignaturePolymorphicMethod())
{
// Signature polymorphic method's signature varies at different call sites and will be different than its declared signature
int32_t signatureLength;
char *signature = getMethodSignatureFromConstantPool(cpIndex, signatureLength);
((TR_ResolvedJ9Method *)m)->setSignature(signature, signatureLength, comp->trMemory());
}
return m;
}
void *
TR_ResolvedJ9JITServerMethod::startAddressForJittedMethod()
{
// return the cached value if we have any
if (_startAddressForJittedMethod)
{
return _startAddressForJittedMethod;
}
else // Otherwise ask the client for it
{
_stream->write(JITServer::MessageType::ResolvedMethod_startAddressForJittedMethod, _remoteMirror);
return std::get<0>(_stream->read<void *>());
}
}
char *
TR_ResolvedJ9JITServerMethod::localName(U_32 slotNumber, U_32 bcIndex, I_32 &len, TR_Memory *trMemory)
{
_stream->write(JITServer::MessageType::ResolvedMethod_localName, _remoteMirror, slotNumber, bcIndex);
auto recv = _stream->read<std::string>();
auto &nameString = std::get<0>(recv);
len = nameString.length();
char *out = (char *)trMemory->allocateHeapMemory(len);
memcpy(out, nameString.data(), len);
return out;
}
TR_OpaqueClassBlock *
TR_ResolvedJ9JITServerMethod::getResolvedInterfaceMethod(I_32 cpIndex, UDATA *pITableIndex)
{
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedInterfaceMethod_2, _remoteMirror, cpIndex);
auto recv = _stream->read<TR_OpaqueClassBlock *, UDATA>();
*pITableIndex = std::get<1>(recv);
auto result = std::get<0>(recv);
auto comp = _fe->_compInfoPT->getCompilation();
if (comp && comp->compileRelocatableCode() && comp->getOption(TR_UseSymbolValidationManager))
{
if (!comp->getSymbolValidationManager()->addClassFromITableIndexCPRecord(result, cp(), cpIndex))
result = NULL;
}
return result;
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedInterfaceMethod(TR::Compilation * comp, TR_OpaqueClassBlock * classObject, I_32 cpIndex)
{
TR_ResolvedMethod *resolvedMethod = NULL;
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
TR_OpaqueClassBlock *clazz = (TR_OpaqueClassBlock *) _ramClass;
if (compInfoPT->getCachedResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Interface, clazz, cpIndex, classObject), this, &resolvedMethod))
return resolvedMethod;
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedInterfaceMethodAndMirror_3, getPersistentIdentifier(), classObject, cpIndex, _remoteMirror);
auto recv = _stream->read<bool, J9Method*, TR_ResolvedJ9JITServerMethodInfo>();
bool resolved = std::get<0>(recv);
J9Method *ramMethod = std::get<1>(recv);
auto &methodInfo = std::get<2>(recv);
if (comp && comp->getOption(TR_UseSymbolValidationManager))
{
if (!comp->getSymbolValidationManager()->addInterfaceMethodFromCPRecord((TR_OpaqueMethodBlock *) ramMethod,
(TR_OpaqueClassBlock *) ((TR_J9VM *) _fe)->getClassFromMethodBlock(getPersistentIdentifier()),
classObject,
cpIndex))
{
return NULL;
}
}
// If the method ref is unresolved, the bytecodes of the ramMethod will be NULL.
// IFF resolved, then we can look at the rest of the ref.
//
if (resolved)
{
TR_AOTInliningStats *aotStats = NULL;
if (comp->getOption(TR_EnableAOTStats))
aotStats = & (((TR_JitPrivateConfig *)_fe->_jitConfig->privateConfig)->aotStats->interfaceMethods);
TR_ResolvedMethod *m = createResolvedMethodFromJ9Method(comp, cpIndex, 0, ramMethod, NULL, aotStats, methodInfo);
TR_OpaqueClassBlock *c = NULL;
if (m)
{
c = m->classOfMethod();
if (c && !_fe->isInterfaceClass(c))
{
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/interface");
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/interface:#bytes", sizeof(TR_ResolvedJ9Method));
resolvedMethod = m;
}
}
}
// for resolved interface method, need to know cpIndex, as well as classObject
// to uniquely identify it.
if (resolvedMethod)
{
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::Interface, clazz, cpIndex, classObject), (TR_OpaqueMethodBlock *) ramMethod, 0, methodInfo);
return resolvedMethod;
}
TR::DebugCounter::incStaticDebugCounter(comp, "resources.resolvedMethods/interface/null");
return 0;
}
U_32
TR_ResolvedJ9JITServerMethod::getResolvedInterfaceMethodOffset(TR_OpaqueClassBlock * classObject, I_32 cpIndex)
{
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedInterfaceMethodOffset, _remoteMirror, classObject, cpIndex);
auto recv = _stream->read<U_32>();
return std::get<0>(recv);
}
/* Only returns non-null if the method is not to be dispatched by itable, i.e.
* if it is:
* - private (isPrivate()), using direct dispatch;
* - a final method of Object (isFinalInObject()), using direct dispatch; or
* - a non-final method of Object, using virtual dispatch.
*/
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedImproperInterfaceMethod(TR::Compilation * comp, I_32 cpIndex)
{
TR_ASSERT(cpIndex != -1, "cpIndex shouldn't be -1");
#if TURN_OFF_INLINING
return 0;
#else
if (!(_fe->_compInfoPT->getClientData()->getRtResolve()))
{
// check for cache first
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
TR_ResolvedMethod * resolvedMethod = NULL;
if (compInfoPT->getCachedResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::ImproperInterface, (TR_OpaqueClassBlock *) _ramClass, cpIndex), this, &resolvedMethod))
return resolvedMethod;
// query for resolved method and create its mirror at the same time
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedImproperInterfaceMethodAndMirror, _remoteMirror, cpIndex);
auto recv = _stream->read<J9Method *, TR_ResolvedJ9JITServerMethodInfo, UDATA>();
auto j9method = std::get<0>(recv);
auto &methodInfo = std::get<1>(recv);
auto vtableOffset = std::get<2>(recv);
if (comp->getOption(TR_UseSymbolValidationManager) && j9method)
{
if (!comp->getSymbolValidationManager()->addImproperInterfaceMethodFromCPRecord((TR_OpaqueMethodBlock *)j9method, cp(), cpIndex))
j9method = NULL;
}
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::ImproperInterface, (TR_OpaqueClassBlock *) _ramClass, cpIndex),
(TR_OpaqueMethodBlock *) j9method, vtableOffset, methodInfo);
if (j9method == NULL)
return NULL;
else
return createResolvedMethodFromJ9Method(comp, cpIndex, vtableOffset, j9method, NULL, NULL, methodInfo);
}
return NULL;
#endif
}
void *
TR_ResolvedJ9JITServerMethod::startAddressForJNIMethod(TR::Compilation *comp)
{
// For fastJNI methods, we have the address cached
if (_jniProperties)
return _jniTargetAddress;
_stream->write(JITServer::MessageType::ResolvedMethod_startAddressForJNIMethod, _remoteMirror);
return std::get<0>(_stream->read<void *>());
}
void *
TR_ResolvedJ9JITServerMethod::startAddressForInterpreterOfJittedMethod()
{
_stream->write(JITServer::MessageType::ResolvedMethod_startAddressForInterpreterOfJittedMethod, _remoteMirror);
return std::get<0>(_stream->read<void *>());
}
TR_ResolvedMethod *
TR_ResolvedJ9JITServerMethod::getResolvedVirtualMethod(TR::Compilation * comp, TR_OpaqueClassBlock * classObject, I_32 virtualCallOffset, bool ignoreRtResolve)
{
TR_J9VMBase *fej9 = (TR_J9VMBase *)_fe;
if (_fe->_compInfoPT->getClientData()->getRtResolve() && !ignoreRtResolve)
return NULL;
auto compInfoPT = (TR::CompilationInfoPerThreadRemote *) _fe->_compInfoPT;
TR_OpaqueClassBlock *clazz = (TR_OpaqueClassBlock *) _ramClass;
TR_ResolvedMethod *resolvedMethod = NULL;
// If method is already cached, return right away
if (compInfoPT->getCachedResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromOffset, clazz, virtualCallOffset, classObject), this, &resolvedMethod))
return resolvedMethod;
// Remote call finds RAM method at offset and creates a resolved method at the client
_stream->write(JITServer::MessageType::ResolvedMethod_getResolvedVirtualMethod, classObject, virtualCallOffset, ignoreRtResolve, (TR_ResolvedJ9Method *) getRemoteMirror());
auto recv = _stream->read<TR_OpaqueMethodBlock *, TR_ResolvedJ9JITServerMethodInfo>();
auto ramMethod = std::get<0>(recv);
auto &methodInfo = std::get<1>(recv);
// it seems better to override this method for AOT but that's what baseline is doing
// maybe there is a reason for it
if (_fe->isAOT_DEPRECATED_DO_NOT_USE())
{
if (comp && comp->getOption(TR_UseSymbolValidationManager))
{
if (!comp->getSymbolValidationManager()->addVirtualMethodFromOffsetRecord(ramMethod, classObject, virtualCallOffset, ignoreRtResolve))
return NULL;
}
resolvedMethod = ramMethod ? new (comp->trHeapMemory()) TR_ResolvedRelocatableJ9JITServerMethod((TR_OpaqueMethodBlock *) ramMethod, _fe, comp->trMemory(), methodInfo, this) : 0;
}
else
{
resolvedMethod = ramMethod ? new (comp->trHeapMemory()) TR_ResolvedJ9JITServerMethod((TR_OpaqueMethodBlock *) ramMethod, _fe, comp->trMemory(), methodInfo, this) : 0;
}
if (resolvedMethod)
compInfoPT->cacheResolvedMethod(compInfoPT->getResolvedMethodKey(TR_ResolvedMethodType::VirtualFromOffset, clazz, virtualCallOffset, classObject), ramMethod, 0, methodInfo);