-
Notifications
You must be signed in to change notification settings - Fork 738
/
Copy pathj9method.cpp
9342 lines (8204 loc) · 428 KB
/
j9method.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 2000
*
* 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 "env/j9method.h"
#include <stddef.h>
#include "bcnames.h"
#include "fastJNI.h"
#include "j9.h"
#include "j9cfg.h"
#include "jitprotos.h"
#include "jilconsts.h"
#include "util_api.h"
#include "rommeth.h"
#include "codegen/CodeGenerator.hpp"
#include "env/KnownObjectTable.hpp"
#include "compile/AOTClassInfo.hpp"
#include "compile/Method.hpp"
#include "compile/ResolvedMethod.hpp"
#include "control/Recompilation.hpp"
#include "control/RecompilationInfo.hpp"
#include "env/CompilerEnv.hpp"
#include "env/PersistentCHTable.hpp"
#include "env/StackMemoryRegion.hpp"
#include "env/jittypes.h"
#include "env/VMAccessCriticalSection.hpp"
#include "env/VMJ9.h"
#include "exceptions/DataCacheError.hpp"
#include "exceptions/AOTFailure.hpp"
#include "il/DataTypes.hpp"
#include "il/Node.hpp"
#include "il/Node_inlines.hpp"
#include "infra/SimpleRegex.hpp"
#include "optimizer/Inliner.hpp"
#include "optimizer/PreExistence.hpp"
#include "runtime/J9Runtime.hpp"
#include "runtime/MethodMetaData.h"
#include "runtime/RelocationRuntime.hpp"
#include "runtime/RuntimeAssumptions.hpp"
#include "env/VMJ9.h"
#include "control/CompilationRuntime.hpp"
#include "control/CompilationThread.hpp"
#include "ilgen/J9ByteCodeIlGenerator.hpp"
#include "runtime/IProfiler.hpp"
#include "ras/DebugCounter.hpp"
#include "env/JSR292Methods.h"
#include "control/MethodToBeCompiled.hpp"
#if defined(_MSC_VER)
#include <malloc.h>
#endif
#define J9VMBYTECODES
static TR::DataType J9ToTRMap[] =
{ TR::NoType, TR::Int8, TR::Int8, TR::Int16, TR::Int16, TR::Float, TR::Int32, TR::Double, TR::Int64, TR::Address, TR::Address };
static bool J9ToIsUnsignedMap[] =
{ false, true, false, true, false, false, false, false, false, false, false };
static U_32 J9ToSizeMap[] =
{ 0, sizeof(UDATA), sizeof(UDATA), sizeof(UDATA), sizeof(UDATA), sizeof(UDATA), sizeof(UDATA), sizeof(U_64), sizeof(U_64), sizeof(UDATA) };
static TR::ILOpCodes J9ToTRDirectCallMap[] =
{ TR::call, TR::icall, TR::icall, TR::icall, TR::icall, TR::fcall, TR::icall, TR::dcall, TR::lcall, TR::acall };
static TR::ILOpCodes J9ToTRIndirectCallMap[] =
{ TR::calli, TR::icalli, TR::icalli, TR::icalli, TR::icalli, TR::fcalli, TR::icalli, TR::dcalli, TR::lcalli, TR::acalli };
static TR::ILOpCodes J9ToTRReturnOpCodeMap[] =
{ TR::Return, TR::ireturn, TR::ireturn, TR::ireturn, TR::ireturn, TR::freturn, TR::ireturn, TR::dreturn, TR::lreturn, TR::areturn };
#if defined(DEBUG_LOCAL_CLASS_OPT)
int fieldAttributeCtr = 0;
int staticAttributeCtr = 0;
int resolvedCtr = 0;
int unresolvedCtr = 0;
#endif
#ifndef NO_OPT_DETAILS
#undef performTransformation
#define performTransformation(comp, a,b) \
(comp->getOption(TR_TraceOptDetails) ? comp->getDebug()->performTransformationImpl(true, (a), (b)) : true)
#endif
static inline bool utf8Matches(struct J9UTF8 * name1, struct J9UTF8 * name2)
{
/* optimize if name1 and name2 are identical */
if (name1 == name2)
return true;
/* check lengths before expensive memcmp */
if (J9UTF8_LENGTH(name1) == J9UTF8_LENGTH(name2) && memcmp(utf8Data(name1), utf8Data(name2), J9UTF8_LENGTH(name1)) == 0)
return true;
return false;
}
// takes a J9FieldType and returns the DataTypes associated
// along with the size.
//
static TR::DataType decodeType(U_32 inType)
{
// the J9FieldTypes are bits, so we must case on them.
switch (inType & (J9FieldTypeMask | J9FieldFlagObject))
{
case J9FieldTypeLong: { return TR::Int64; }
case J9FieldTypeDouble: { return TR::Double; }
case J9FieldTypeByte: { return TR::Int8; }
case J9FieldTypeFloat: { return TR::Float; }
case J9FieldTypeChar: { return TR::Int16; }
case J9FieldTypeBoolean: { return TR::Int8; }
case J9FieldTypeShort: { return TR::Int16; }
case J9FieldTypeInt: { return TR::Int32; }
case J9FieldFlagObject: { return TR::Address; }
default:
{
TR_ASSERT(0,"Bad typeCode in JIL_J9VM decodeType");
return TR::NoType;
}
}
}
UDATA getFieldType(J9ROMConstantPoolItem * cp, I_32 cpIndex)
{
J9ROMFieldRef * ref = (J9ROMFieldRef *) (&cp[cpIndex]);
J9ROMNameAndSignature * nameAndSignature = J9ROMFIELDREF_NAMEANDSIGNATURE(ref);
J9UTF8 * data = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature);
UDATA j9FieldType = (UDATA)(J9UTF8_DATA(data)[0]);
switch (j9FieldType)
{ // cannot use characters because on s390 the compiler will generate an EBCDIC value
// internal JVM representation is in ASCII
case J9_SIGBYTE_BYTE:// byte 'B'
return (j9FieldType |= J9FieldTypeByte);
case J9_SIGBYTE_CHAR:// char 'C'
return (j9FieldType |= 0);
case J9_SIGBYTE_DOUBLE:// double 'D'
return (j9FieldType |= (J9FieldTypeDouble | J9FieldSizeDouble ));
case J9_SIGBYTE_FLOAT:// float 'F'
return (j9FieldType |= J9FieldTypeFloat);
case J9_SIGBYTE_INT:// int 'I'
return (j9FieldType |= J9FieldTypeInt);
case J9_SIGBYTE_LONG:// long 'J'
return (j9FieldType |= (J9FieldTypeLong | J9FieldSizeDouble ));
case J9_SIGBYTE_SHORT:// short 'S'
return (j9FieldType |= J9FieldTypeShort);
case J9_SIGBYTE_BOOLEAN:// boolean 'Z'
return (j9FieldType |= J9FieldTypeBoolean);
default:// object
return (j9FieldType |= J9FieldFlagObject);
}
}
bool
TR_J9VMBase::supportsFastNanoTime()
{
static char *disableInlineNanoTime = feGetEnv("TR_disableInlineNanoTime");
if (disableInlineNanoTime)
return false;
else
return true;
}
/*
* VM sets a bit in the j9method->constantPool field to indicate
* if the method is breakpointed
*/
U_32
TR_J9VMBase::offsetOfMethodIsBreakpointedBit()
{
return J9_STARTPC_METHOD_BREAKPOINTED;
}
TR::Method *
TR_J9VMBase::createMethod(TR_Memory * trMemory, TR_OpaqueClassBlock * clazz, int32_t refOffset)
{
return new (trMemory->trHeapMemory()) TR_J9Method(this, trMemory, TR::Compiler->cls.convertClassOffsetToClassPtr(clazz), refOffset);
}
TR_ResolvedMethod *
TR_J9VMBase::createResolvedMethod(TR_Memory * trMemory, TR_OpaqueMethodBlock * aMethod,
TR_ResolvedMethod * owningMethod, TR_OpaqueClassBlock *classForNewInstance)
{
return createResolvedMethodWithSignature(trMemory, aMethod, classForNewInstance, NULL, -1, owningMethod);
}
TR_ResolvedMethod *
TR_J9VMBase::createResolvedMethodWithVTableSlot(TR_Memory * trMemory, uint32_t vTableSlot, TR_OpaqueMethodBlock * aMethod,
TR_ResolvedMethod * owningMethod, TR_OpaqueClassBlock *classForNewInstance)
{
return createResolvedMethodWithSignature(trMemory, aMethod, classForNewInstance, NULL, -1, owningMethod, vTableSlot);
}
TR_ResolvedMethod *
TR_J9VMBase::createResolvedMethodWithSignature(TR_Memory * trMemory, TR_OpaqueMethodBlock * aMethod, TR_OpaqueClassBlock *classForNewInstance,
char *signature, int32_t signatureLength, TR_ResolvedMethod * owningMethod, uint32_t vTableSlot)
{
TR_ResolvedJ9Method *result = NULL;
if (isAOT_DEPRECATED_DO_NOT_USE())
{
#if defined(J9VM_INTERP_AOT_COMPILE_SUPPORT)
#if defined(J9VM_OPT_SHARED_CLASSES) && (defined(TR_HOST_X86) || defined(TR_HOST_POWER) || defined(TR_HOST_S390) || defined(TR_HOST_ARM) || defined(TR_HOST_ARM64))
if (TR::Options::sharedClassCache())
{
result = new (trMemory->trHeapMemory()) TR_ResolvedRelocatableJ9Method(aMethod, this, trMemory, owningMethod, vTableSlot);
TR::Compilation *comp = TR::comp();
if (comp && comp->getOption(TR_UseSymbolValidationManager))
{
TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();
if (!svm->isAlreadyValidated(result->containingClass()))
return NULL;
}
}
else
#endif
return NULL;
#endif
}
else
{
result = new (trMemory->trHeapMemory()) TR_ResolvedJ9Method(aMethod, this, trMemory, owningMethod, vTableSlot);
if (classForNewInstance)
{
result->setClassForNewInstance((J9Class*)classForNewInstance);
TR_ASSERT(result->isNewInstanceImplThunk(), "createResolvedMethodWithSignature: if classForNewInstance is given this must be a thunk");
}
}
if (signature)
result->setSignature(signature, signatureLength, trMemory);
return result;
}
bool TR_ResolvedJ9Method::isMethodInValidLibrary()
{
TR_J9VMBase *fej9 = (TR_J9VMBase *)_fe;
if (fej9->isClassLibraryMethod(getPersistentIdentifier(), true))
return true;
// this is a work-around because DAA library is not part of class library yet.
// TODO: to be cleaned up after DAA library packaged into class library
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/dataaccess/", 19))
return true;
// For WebSphere methods
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/ws/", 11))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/gpu/Kernel", 18))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "jdk/incubator/vector/", 21))
return true;
#ifdef J9VM_OPT_JAVA_CRYPTO_ACCELERATION
// For IBMJCE Crypto
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/jit/Crypto", 18))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/jit/crypto/JITFullHardwareCrypt", 39))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/jit/crypto/JITFullHardwareDigest", 40))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/crypto/provider/P224PrimeField", 38))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/crypto/provider/P256PrimeField", 38))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/crypto/provider/P384PrimeField", 38))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/crypto/provider/AESCryptInHardware", 42))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/crypto/provider/ByteArrayMarshaller", 43))
return true;
if (!strncmp(this->convertToMethod()->classNameChars(), "com/ibm/crypto/provider/ByteArrayUnmarshaller", 45))
return true;
#endif
return false;
}
void
TR_J9MethodBase::parseSignature(TR_Memory * trMemory)
{
U_8 tempArgTypes[512];
jitParseSignature(_signature, tempArgTypes, &_paramElements, &_paramSlots);
_argTypes = (U_8 *) trMemory->allocateHeapMemory((_paramElements + 1) * sizeof(U_8));
memcpy(_argTypes, tempArgTypes, (_paramElements + 1));
}
uintptr_t
TR_J9MethodBase::j9returnType()
{
return _argTypes[_paramElements];
}
uint32_t
TR_J9MethodBase::numberOfExplicitParameters()
{
TR_ASSERT(_paramElements <= 0xFFFFFFFF, "numberOfExplicitParameters() not expected to return 64-bit values\n");
return (uint32_t) _paramElements;
}
// Returns the TR type for the return type of the method
//
TR::DataType
TR_J9MethodBase::returnType()
{
return J9ToTRMap[j9returnType()];
}
bool
TR_J9MethodBase::returnTypeIsUnsigned()
{
return J9ToIsUnsignedMap[j9returnType()];
}
// Returns the TR type of the parmNumber'th parameter
// NB: 0-based. ie: (IC)V has parm0=I, parm1=C, etc..
//
TR::DataType
TR_J9MethodBase::parmType(uint32_t parmNumber)
{
return J9ToTRMap[_argTypes[parmNumber]];
}
// returns the opcode for a direct call version of the method
//
TR::ILOpCodes
TR_J9MethodBase::directCallOpCode()
{
return J9ToTRDirectCallMap[j9returnType()];
}
// returns the opcode for an indirect call version of the method
//
TR::ILOpCodes
TR_J9MethodBase::indirectCallOpCode()
{
return J9ToTRIndirectCallMap[j9returnType()];
}
// returns the return opcode for the method
//
TR::ILOpCodes
TR_J9MethodBase::returnOpCode()
{
return J9ToTRReturnOpCodeMap[j9returnType()];
}
// Returns the width of the return type of the method
//
U_32
TR_J9MethodBase::returnTypeWidth()
{
return J9ToSizeMap[j9returnType()];
}
// returns the length of the class that this method is in.
//
U_16
TR_J9MethodBase::classNameLength()
{
return J9UTF8_LENGTH(_className);
}
// returns the length of the method name
//
U_16
TR_J9MethodBase::nameLength()
{
return J9UTF8_LENGTH(_name);
}
const char *
TR_J9MethodBase::signature(TR_Memory * trMemory, TR_AllocationKind allocKind)
{
if( !_fullSignature )
{
char * s = (char *)trMemory->allocateMemory(classNameLength() + nameLength() + signatureLength() + 3, allocKind);
sprintf(s, "%.*s.%.*s%.*s", classNameLength(), classNameChars(), nameLength(), nameChars(), signatureLength(), signatureChars());
if ( allocKind == heapAlloc)
_fullSignature = s;
return s;
}
else
return _fullSignature;
}
// returns the length of the method signature
U_16
TR_J9MethodBase::signatureLength()
{
return J9UTF8_LENGTH(_signature);
}
// returns the char * pointer to the utf8 encoded name of the class the method is in
//
char *
TR_J9MethodBase::classNameChars()
{
return utf8Data(_className);
}
// returns the char * pointer to the utf8 encoded method name
//
char *
TR_J9MethodBase::nameChars()
{
return utf8Data(_name);
}
// returns the char * pointer to the utf8 encoded method signature
//
char *
TR_J9MethodBase::signatureChars()
{
return utf8Data(_signature);
}
bool
TR_J9MethodBase::isConstructor()
{
return nameLength()==6 && !strncmp(nameChars(), "<init>", 6);
}
bool
TR_J9MethodBase::isFinalInObject()
{
return methodIsFinalInObject(nameLength(), (U_8 *) nameChars(), signatureLength(), (U_8 *) signatureChars()) ? true : false;
}
TR_ResolvedJ9MethodBase::TR_ResolvedJ9MethodBase(TR_FrontEnd * fe, TR_ResolvedMethod * owner)
: _fe((TR_J9VMBase *)fe), _owningMethod(owner)
{
}
J9ROMConstantPoolItem *
TR_ResolvedJ9MethodBase::romLiterals()
{
return _romLiterals;
}
TR_J9VMBase *
TR_ResolvedJ9MethodBase::fej9()
{
return (TR_J9VMBase *)_fe;
}
TR_FrontEnd *
TR_ResolvedJ9MethodBase::fe()
{
return _fe;
}
TR_ResolvedMethod *
TR_ResolvedJ9MethodBase::owningMethod()
{
return _owningMethod;
}
void
TR_ResolvedJ9MethodBase::setOwningMethod(TR_ResolvedMethod *parent)
{
_owningMethod=parent;
}
bool
TR_ResolvedJ9Method::owningMethodDoesntMatter()
{
// Returning true here allows us to ignore the owning method, which lets us
// share symrefs more aggressively and other goodies, but usually ignoring
// the owning method will confuse inliner and others, so only do so when
// it's known not to matter.
static char *aggressiveJSR292Opts = feGetEnv("TR_aggressiveJSR292Opts");
J9UTF8 *className = J9ROMCLASS_CLASSNAME(romClassPtr());
if (aggressiveJSR292Opts && strchr(aggressiveJSR292Opts, '3'))
{
if (J9UTF8_LENGTH(className) >= 17 && !strncmp((char*)J9UTF8_DATA(className), "java/lang/invoke/", 17))
{
return true;
}
else switch (TR_ResolvedJ9MethodBase::getRecognizedMethod())
{
case TR::java_lang_invoke_MethodHandle_invokeExactTargetAddress: // This is just a getter that's practically always inlined
return true;
default:
break;
}
}
else if (!strncmp((char*)J9UTF8_DATA(className), "java/lang/invoke/ILGenMacros", J9UTF8_LENGTH(className)))
{
// ILGen macros are always expanded into other trees, so the owning
// method of the macro's method symbol doesn't matter.
//
return true;
}
// Safe default
//
return false;
}
bool
TR_ResolvedJ9MethodBase::canAlwaysShareSymbolDespiteOwningMethod(TR_ResolvedMethod *otherMethod)
{
if (!owningMethodDoesntMatter())
return false;
TR_ResolvedJ9MethodBase *other = (TR_ResolvedJ9MethodBase*)otherMethod;
if (other == NULL)
return false; // possibly unresolved
if (_methodHandleLocation != other->_methodHandleLocation)
return false;
TR_J9MethodBase *MB = asJ9Method();
TR_J9MethodBase *otherMB = other->asJ9Method();
// A couple of fast checks
if (MB->classNameLength() != otherMB->classNameLength())
return false;
if (MB->nameLength() != otherMB->nameLength())
return false;
if (MB->signatureLength() != otherMB->signatureLength())
return false;
//
// Now we start to get into the more expensive stuff
//
if (strncmp(MB->classNameChars(), otherMB->classNameChars(), MB->classNameLength()))
return false;
if (strncmp(MB->nameChars(), otherMB->nameChars(), MB->nameLength()))
return false;
if (strncmp(MB->signatureChars(), otherMB->signatureChars(), MB->signatureLength()))
return false;
return true;
}
J9ROMFieldRef *
TR_ResolvedJ9MethodBase::romCPBase()
{
return (J9ROMFieldRef *) romLiterals();
}
char *
TR_ResolvedJ9MethodBase::classSignatureOfFieldOrStatic(I_32 cpIndex, int32_t & len)
{
if (cpIndex == -1)
return 0;
J9ROMFieldRef * ref = (J9ROMFieldRef *) (&romCPBase()[cpIndex]);
J9ROMNameAndSignature * nameAndSignature = J9ROMFIELDREF_NAMEANDSIGNATURE(ref);
J9UTF8 * signatureName = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature);
len = J9UTF8_LENGTH(signatureName);
return (char *)J9UTF8_DATA(signatureName);
}
char *
TR_ResolvedJ9MethodBase::classNameOfFieldOrStatic(I_32 cpIndex, int32_t & len)
{
if (cpIndex == -1)
return 0;
J9ROMFieldRef * ref = (J9ROMFieldRef *) (&romCPBase()[cpIndex]);
J9UTF8 * declName = J9ROMCLASSREF_NAME((J9ROMClassRef *) (&romCPBase()[ref->classRefCPIndex]));
len = J9UTF8_LENGTH(declName);
return (char *)J9UTF8_DATA(declName);
}
int32_t
TR_ResolvedJ9MethodBase::classCPIndexOfFieldOrStatic(int32_t cpIndex)
{
if (cpIndex == -1)
return -1;
return ((J9ROMFieldRef *)(&romCPBase()[cpIndex]))->classRefCPIndex;
}
TR_OpaqueClassBlock *
TR_ResolvedJ9MethodBase::getDeclaringClassFromFieldOrStatic(TR::Compilation *comp, int32_t cpIndex)
{
J9Class *cpClass = (J9Class*)getClassFromFieldOrStatic(comp, cpIndex);
if (!cpClass)
return NULL;
J9Class *containingClass = NULL;
{
TR::VMAccessCriticalSection getDeclaringClassFromFieldOrStatic(fej9());
J9VMThread *vmThread = fej9()->vmThread();
int32_t fieldLen; char *field = fieldNameChars (cpIndex, fieldLen);
int32_t sigLen; char *sig = fieldSignatureChars (cpIndex, sigLen);
vmThread->javaVM->internalVMFunctions->instanceFieldOffset(vmThread,
cpClass,
(U_8*)field,
fieldLen,
(U_8*)sig,
sigLen,
&containingClass,
NULL,
J9_LOOK_NO_JAVA);
}
return (TR_OpaqueClassBlock*)containingClass;
}
void
TR_J9MethodBase::setSignature(char *newSignature, int32_t newSignatureLength, TR_Memory *trMemory)
{
_signature = str2utf8(newSignature, newSignatureLength, trMemory, heapAlloc);
parseSignature(trMemory);
_fullSignature = NULL;
}
void
TR_J9MethodBase::setArchetypeSpecimen(bool b)
{
_flags.set(ArchetypeSpecimen, b);
}
char *
TR_ResolvedJ9Method::localName(U_32 slotNumber, U_32 bcIndex, TR_Memory *trMemory)
{
I_32 len;
return localName(slotNumber, bcIndex, len, trMemory);
}
char *
TR_ResolvedJ9Method::localName(U_32 slotNumber, U_32 bcIndex, I_32 &len, TR_Memory *trMemory)
{
J9MethodDebugInfo *methodDebugInfo = getMethodDebugInfoForROMClass(fej9()->getJ9JITConfig()->javaVM, ramMethod());
if (!methodDebugInfo)
return NULL;
J9VariableInfoWalkState state;
J9VariableInfoValues *values = variableInfoStartDo(methodDebugInfo, &state);
while (NULL != values)
{
// TODO: callers should find out bcIndex so we don't need to ignore it
if (values->slotNumber == slotNumber
//&& variableInfo.startVisibility <= bcIndex && bcIndex <= (variableInfo.startVisibility + variableInfo.visibilityLength)
){
J9UTF8 *varName = values->name;
len = J9UTF8_LENGTH(varName);
return (char*)J9UTF8_DATA(varName);
}
values = variableInfoNextDo(&state);
}
return NULL;
}
char *
TR_ResolvedJ9MethodBase::fieldOrStaticName(I_32 cpIndex, int32_t & len, TR_Memory * trMemory, TR_AllocationKind kind)
{
if (cpIndex == -1)
return "<internal name>";
J9ROMFieldRef * ref = (J9ROMFieldRef *) (&romCPBase()[cpIndex]);
J9ROMNameAndSignature * nameAndSignature = J9ROMFIELDREF_NAMEANDSIGNATURE(ref);
J9UTF8 * declName = J9ROMCLASSREF_NAME((J9ROMClassRef *) (&romCPBase()[ref->classRefCPIndex]));
len = J9UTF8_LENGTH(declName) + J9UTF8_LENGTH(J9ROMNAMEANDSIGNATURE_NAME(nameAndSignature)) + J9UTF8_LENGTH(J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature)) +3;
char * s = (char *)trMemory->allocateMemory(len, kind);
sprintf(s, "%.*s.%.*s %.*s",
J9UTF8_LENGTH(declName), utf8Data(declName),
J9UTF8_LENGTH(J9ROMNAMEANDSIGNATURE_NAME(nameAndSignature)), utf8Data(J9ROMNAMEANDSIGNATURE_NAME(nameAndSignature)),
J9UTF8_LENGTH(J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature)), utf8Data(J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSignature)));
return s;
}
char *
TR_ResolvedJ9MethodBase::fieldName(I_32 cpIndex, TR_Memory * m, TR_AllocationKind kind)
{
int32_t len;
return fieldName(cpIndex, len, m, kind);
}
char *
TR_ResolvedJ9MethodBase::staticName(I_32 cpIndex, TR_Memory * m, TR_AllocationKind kind)
{
int32_t len;
return staticName(cpIndex, len, m, kind);
}
char *
TR_ResolvedJ9MethodBase::fieldName(I_32 cpIndex, int32_t & len, TR_Memory * m, TR_AllocationKind kind)
{
if (cpIndex < 0) return "<internal field>";
return fieldOrStaticName(cpIndex, len, m, kind);
}
char *
TR_ResolvedJ9MethodBase::staticName(I_32 cpIndex, int32_t & len, TR_Memory * m, TR_AllocationKind kind)
{
if (cpIndex < 0) return 0;
return fieldOrStaticName(cpIndex, len, m, kind);
}
I_32
TR_ResolvedJ9MethodBase::exceptionData(
J9ExceptionHandler * eh, I_32 bcOffset, I_32 exceptionNumber, I_32 * startIndex, I_32 * endIndex, I_32 * catchType)
{
*startIndex = (I_32) (eh[exceptionNumber].startPC) - bcOffset;
*endIndex = (I_32) (eh[exceptionNumber].endPC) - bcOffset - 1;
*catchType = (I_32) (eh[exceptionNumber].exceptionClassIndex);
return (I_32) (eh[exceptionNumber].handlerPC) - bcOffset;
}
static const char * const excludeArray[] = {
"java/lang/reflect/AccessibleObject.invokeV(Ljava/lang/Object;[Ljava/lang/Object;)V",
"java/lang/reflect/AccessibleObject.invokeI(Ljava/lang/Object;[Ljava/lang/Object;)I",
"java/lang/reflect/AccessibleObject.invokeJ(Ljava/lang/Object;[Ljava/lang/Object;)J",
"java/lang/reflect/AccessibleObject.invokeF(Ljava/lang/Object;[Ljava/lang/Object;)F",
"java/lang/reflect/AccessibleObject.invokeD(Ljava/lang/Object;[Ljava/lang/Object;)D",
"java/lang/reflect/AccessibleObject.invokeL(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;",
"java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;",
"java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;",
"java/security/AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;[Ljava/security/Permission;)Ljava/lang/Object;",
"java/security/AccessController.doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;[Ljava/security/Permission;)Ljava/lang/Object;",
"java/lang/NullPointerException.fillInStackTrace()Ljava/lang/Throwable;",
#if (17 <= JAVA_SPEC_VERSION) && (JAVA_SPEC_VERSION <= 18)
"jdk/internal/loader/NativeLibraries.load(Ljdk/internal/loader/NativeLibraries$NativeLibraryImpl;Ljava/lang/String;ZZZ)Z",
#elif JAVA_SPEC_VERSION >= 15 /* (17 <= JAVA_SPEC_VERSION) && (JAVA_SPEC_VERSION <= 18) */
"jdk/internal/loader/NativeLibraries.load(Ljdk/internal/loader/NativeLibraries$NativeLibraryImpl;Ljava/lang/String;ZZ)Z",
#endif /* (17 <= JAVA_SPEC_VERSION) && (JAVA_SPEC_VERSION <= 18) */
};
bool
TR_ResolvedJ9MethodBase::isCompilable(TR_Memory * trMemory)
{
if (isNative() && (!isJNINative() || getRecognizedMethod() == TR::sun_misc_Unsafe_ensureClassInitialized))
return false;
if (isAbstract())
return false;
// now go through the list of methods that are excluded by name only
//
const char * methodSig = signature(trMemory, stackAlloc);
for (int i=0; i <sizeof(excludeArray) / sizeof(*excludeArray); ++i)
if (!strcmp(excludeArray[i], methodSig))
return false;
return true;
}
bool
TR_ResolvedJ9MethodBase::isInlineable(TR::Compilation *comp)
{
if (comp->getOption(TR_FullSpeedDebug) && comp->getOption(TR_EnableOSR))
{
if (jitMethodIsBreakpointed(fej9()->vmThread(), (J9Method *) getPersistentIdentifier()))
return false;
}
return true;
}
static intptr_t getInitialCountForMethod(TR_ResolvedMethod *rm, TR::Compilation *comp)
{
TR_ResolvedJ9Method *m = static_cast<TR_ResolvedJ9Method *>(rm);
TR::Options * options = comp->getOptions();
intptr_t initialCount = m->hasBackwardBranches() ? options->getInitialBCount() : options->getInitialCount();
#if defined(J9VM_INTERP_AOT_COMPILE_SUPPORT) && defined(J9VM_OPT_SHARED_CLASSES) && (defined(TR_HOST_X86) || defined(TR_HOST_POWER) || defined(TR_HOST_S390) || defined(TR_HOST_ARM) || defined(TR_HOST_ARM64))
if (TR::Options::sharedClassCache())
{
J9ROMClass *romClass = m->romClassPtr();
J9ROMMethod *romMethod = m->romMethod();
if (!comp->fej9()->sharedCache()->isROMClassInSharedCache(romClass))
{
#if defined(J9ZOS390)
// Do not change the counts on zos at the moment since the shared cache capacity is higher on this platform
// and by increasing counts we could end up significantly impacting startup
#else
bool startupTimeMatters = TR::Options::isQuickstartDetected() || comp->getOption(TR_UseLowerMethodCounts);
if (!startupTimeMatters)
{
bool useHigherMethodCounts = false;
if (J9ROMMETHOD_HAS_BACKWARDS_BRANCHES(romMethod))
{
if (initialCount == TR_QUICKSTART_INITIAL_BCOUNT)
useHigherMethodCounts = true;
}
else
{
if (initialCount == TR_QUICKSTART_INITIAL_COUNT)
useHigherMethodCounts = true;
}
if (useHigherMethodCounts)
{
J9UTF8 * className = J9ROMCLASS_CLASSNAME(romClass);
if (J9UTF8_LENGTH(className) > 5 &&
!strncmp(utf8Data(className), "java/", 5))
{
initialCount = 10000;
}
else
{
if (J9ROMMETHOD_HAS_BACKWARDS_BRANCHES(romMethod))
initialCount = TR_DEFAULT_INITIAL_BCOUNT;
else
initialCount = TR_DEFAULT_INITIAL_COUNT;
}
}
}
#endif
}
}
#endif
return initialCount;
}
bool
TR_ResolvedJ9MethodBase::isCold(TR::Compilation * comp, bool isIndirectCall, TR::ResolvedMethodSymbol * sym)
{
if (comp->getOption(TR_DisableMethodIsCold))
return false;
// For methods that are resolved but are still interpreted and have high counts
// we can assume the method is cold
// We do this for direct calls and currently not-overridden virtual calls
// For overridden virtual calls we may decide at some point to traverse all the
// existing targets to see if they are all interpreted with high counts
//
if (!isInterpretedForHeuristics() || maxBytecodeIndex() <= TRIVIAL_INLINER_MAX_SIZE)
return false;
if (isIndirectCall && virtualMethodIsOverridden())
{
// Method is polymorphic virtual - walk all the targets to see
// if all of them are not reached
// FIXME: implement
return false;
}
TR::RecognizedMethod rm = getRecognizedMethod();
switch (rm)
{
case TR::java_math_BigDecimal_noLLOverflowMul:
case TR::java_math_BigDecimal_noLLOverflowAdd:
case TR::com_ibm_jit_DecimalFormatHelper_formatAsDouble:
case TR::com_ibm_jit_DecimalFormatHelper_formatAsFloat:
case TR::java_lang_invoke_MethodHandle_invokeExact:
return false;
default:
break;
}
if (convertToMethod()->isArchetypeSpecimen())
return false;
intptr_t count = getInvocationCount();
intptr_t initialCount = getInitialCountForMethod(this, comp);
if (count < 0 || count > initialCount)
return false;
if (comp->isDLT() || fej9()->compiledAsDLTBefore(this))
return false;
// If the method has been invoked no more that 5% of the first compile interval
//
if (((float)count)/initialCount >= .95)
{
//dumpOptDetails(comp, "callee count %d initial count %d\n", count, initialCount);
TR_ResolvedMethod *compMethod = comp->getCurrentMethod();
count = compMethod->getInvocationCount();
initialCount = getInitialCountForMethod(compMethod, comp);
if ((count < 0) ||
((((float)count)/initialCount) < .50))
{
//dumpOptDetails(comp, "caller count %d initial count %d\n", count, initialCount);
return true;
}
}
// default: assume it's not cold
return false;
}
TR::SymbolReferenceTable *
TR_ResolvedJ9MethodBase::_genMethodILForPeeking(TR::ResolvedMethodSymbol *methodSymbol, TR::Compilation *c, bool resetVisitCount, TR_PrexArgInfo* argInfo)
{
// Check if the size of method being peeked exceeds the limit
TR_ResolvedJ9Method * j9method = static_cast<TR_ResolvedJ9Method *>(methodSymbol->getResolvedMethod());
if (_fe->_jitConfig->bcSizeLimit && (j9method->maxBytecodeIndex() > _fe->_jitConfig->bcSizeLimit))
return 0;
vcount_t oldVisitCount = c->getVisitCount();
bool b = c->getNeedsClassLookahead();
c->setNeedsClassLookahead(false);
c->setVisitCount(1);
methodSymbol->setParameterList();
TR_Array<List<TR::SymbolReference> > * oldAutoSymRefs = methodSymbol->getAutoSymRefs();
TR_Array<List<TR::SymbolReference> > * oldPendingPushSymRefs = methodSymbol->getPendingPushSymRefs();
methodSymbol->setAutoSymRefs(0);
methodSymbol->setPendingPushSymRefs(0);
TR::SymbolReferenceTable *oldSymRefTab = c->getCurrentSymRefTab();
TR::SymbolReferenceTable *newSymRefTab =
new (c->trStackMemory()) TR::SymbolReferenceTable(methodSymbol->getResolvedMethod()->maxBytecodeIndex(), c);
c->setPeekingSymRefTab(newSymRefTab);
// Do this so that all intermediate calls to c->getSymRefTab()
// in codegen.dev go to the new symRefTab
//
c->setCurrentSymRefTab(newSymRefTab);
newSymRefTab->addParameters(methodSymbol);
TR_ByteCodeInfo bci;
//incInlineDepth is a part of a hack to make InvariantArgumentPreexistence
//play nicely if getCurrentInlinedCallArgInfo is provided while peeking.
//If we don't provide either dummy (default is set to NULL) or real argInfo we will end up
//using the wrong argInfo coming from a CALLER rather than the peeking method.
c->getInlinedCallArgInfoStack().push(argInfo);
// IL request depends on what kind of method we are; build it then generate IL
TR::IlGeneratorMethodDetails storage;
TR::IlGeneratorMethodDetails & details = TR::IlGeneratorMethodDetails::create(storage, this);
TR::CompileIlGenRequest request(details);
bool success = methodSymbol->genIL(fej9(), c, newSymRefTab, request);
c->getInlinedCallArgInfoStack().pop();
c->setCurrentSymRefTab(oldSymRefTab);
if (resetVisitCount || (c->getVisitCount() < oldVisitCount))
c->setVisitCount(oldVisitCount);
c->setNeedsClassLookahead(b);
methodSymbol->setAutoSymRefs(oldAutoSymRefs);
methodSymbol->setPendingPushSymRefs(oldPendingPushSymRefs);
if (success)
return newSymRefTab;
return 0;
}
TR_ResolvedRelocatableJ9Method::TR_ResolvedRelocatableJ9Method(TR_OpaqueMethodBlock * aMethod, TR_FrontEnd * fe, TR_Memory * trMemory, TR_ResolvedMethod * owner, uint32_t vTableSlot)
: TR_ResolvedJ9Method(aMethod, fe, trMemory, owner, vTableSlot)
{
TR_J9VMBase *fej9 = (TR_J9VMBase *)fe;
TR::Compilation *comp = TR::comp();
if (comp && this->TR_ResolvedMethod::getRecognizedMethod() != TR::unknownMethod)
{
if (fej9->sharedCache()->rememberClass(containingClass()))
{
if (comp->getOption(TR_UseSymbolValidationManager))
{
TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();