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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "class.h"
#include "art_field-inl.h"
#include "art_method-inl.h"
#include "class_linker-inl.h"
#include "class_loader.h"
#include "class-inl.h"
#include "dex_cache.h"
#include "dex_file-inl.h"
#include "gc/accounting/card_table-inl.h"
#include "handle_scope-inl.h"
#include "method.h"
#include "object_array-inl.h"
#include "object-inl.h"
#include "runtime.h"
#include "thread.h"
#include "throwable.h"
#include "utils.h"
#include "well_known_classes.h"
namespace art {
namespace mirror {
GcRoot<Class> Class::java_lang_Class_;
void Class::SetClassClass(Class* java_lang_Class) {
CHECK(java_lang_Class_.IsNull())
<< java_lang_Class_.Read()
<< " " << java_lang_Class;
CHECK(java_lang_Class != nullptr);
java_lang_Class->SetClassFlags(mirror::kClassFlagClass);
java_lang_Class_ = GcRoot<Class>(java_lang_Class);
}
void Class::ResetClass() {
CHECK(!java_lang_Class_.IsNull());
java_lang_Class_ = GcRoot<Class>(nullptr);
}
void Class::VisitRoots(RootVisitor* visitor) {
java_lang_Class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
}
inline void Class::SetVerifyError(mirror::Object* error) {
CHECK(error != nullptr) << PrettyClass(this);
if (Runtime::Current()->IsActiveTransaction()) {
SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_), error);
} else {
SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_), error);
}
}
void Class::SetStatus(Handle<Class> h_this, Status new_status, Thread* self) {
Status old_status = h_this->GetStatus();
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
bool class_linker_initialized = class_linker != nullptr && class_linker->IsInitialized();
if (LIKELY(class_linker_initialized)) {
if (UNLIKELY(new_status <= old_status && new_status != kStatusError &&
new_status != kStatusRetired)) {
LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(h_this.Get())
<< " " << old_status << " -> " << new_status;
}
if (new_status >= kStatusResolved || old_status >= kStatusResolved) {
// When classes are being resolved the resolution code should hold the lock.
CHECK_EQ(h_this->GetLockOwnerThreadId(), self->GetThreadId())
<< "Attempt to change status of class while not holding its lock: "
<< PrettyClass(h_this.Get()) << " " << old_status << " -> " << new_status;
}
}
if (UNLIKELY(new_status == kStatusError)) {
CHECK_NE(h_this->GetStatus(), kStatusError)
<< "Attempt to set as erroneous an already erroneous class "
<< PrettyClass(h_this.Get());
if (VLOG_IS_ON(class_linker)) {
LOG(ERROR) << "Setting " << PrettyDescriptor(h_this.Get()) << " to erroneous.";
if (self->IsExceptionPending()) {
LOG(ERROR) << "Exception: " << self->GetException()->Dump();
}
}
// Remember the current exception.
CHECK(self->GetException() != nullptr);
h_this->SetVerifyError(self->GetException());
}
static_assert(sizeof(Status) == sizeof(uint32_t), "Size of status not equal to uint32");
if (Runtime::Current()->IsActiveTransaction()) {
h_this->SetField32Volatile<true>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status);
} else {
h_this->SetField32Volatile<false>(OFFSET_OF_OBJECT_MEMBER(Class, status_), new_status);
}
if (!class_linker_initialized) {
// When the class linker is being initialized its single threaded and by definition there can be
// no waiters. During initialization classes may appear temporary but won't be retired as their
// size was statically computed.
} else {
// Classes that are being resolved or initialized need to notify waiters that the class status
// changed. See ClassLinker::EnsureResolved and ClassLinker::WaitForInitializeClass.
if (h_this->IsTemp()) {
// Class is a temporary one, ensure that waiters for resolution get notified of retirement
// so that they can grab the new version of the class from the class linker's table.
CHECK_LT(new_status, kStatusResolved) << PrettyDescriptor(h_this.Get());
if (new_status == kStatusRetired || new_status == kStatusError) {
h_this->NotifyAll(self);
}
} else {
CHECK_NE(new_status, kStatusRetired);
if (old_status >= kStatusResolved || new_status >= kStatusResolved) {
h_this->NotifyAll(self);
}
}
}
}
void Class::SetDexCache(DexCache* new_dex_cache) {
SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), new_dex_cache);
SetDexCacheStrings(new_dex_cache != nullptr ? new_dex_cache->GetStrings() : nullptr);
}
void Class::SetClassSize(uint32_t new_class_size) {
if (kIsDebugBuild && new_class_size < GetClassSize()) {
DumpClass(LOG(INTERNAL_FATAL), kDumpClassFullDetail);
LOG(INTERNAL_FATAL) << new_class_size << " vs " << GetClassSize();
LOG(FATAL) << " class=" << PrettyTypeOf(this);
}
// Not called within a transaction.
SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size);
}
// Return the class' name. The exact format is bizarre, but it's the specified behavior for
// Class.getName: keywords for primitive types, regular "[I" form for primitive arrays (so "int"
// but "[I"), and arrays of reference types written between "L" and ";" but with dots rather than
// slashes (so "java.lang.String" but "[Ljava.lang.String;"). Madness.
String* Class::ComputeName(Handle<Class> h_this) {
String* name = h_this->GetName();
if (name != nullptr) {
return name;
}
std::string temp;
const char* descriptor = h_this->GetDescriptor(&temp);
Thread* self = Thread::Current();
if ((descriptor[0] != 'L') && (descriptor[0] != '[')) {
// The descriptor indicates that this is the class for
// a primitive type; special-case the return value.
const char* c_name = nullptr;
switch (descriptor[0]) {
case 'Z': c_name = "boolean"; break;
case 'B': c_name = "byte"; break;
case 'C': c_name = "char"; break;
case 'S': c_name = "short"; break;
case 'I': c_name = "int"; break;
case 'J': c_name = "long"; break;
case 'F': c_name = "float"; break;
case 'D': c_name = "double"; break;
case 'V': c_name = "void"; break;
default:
LOG(FATAL) << "Unknown primitive type: " << PrintableChar(descriptor[0]);
}
name = String::AllocFromModifiedUtf8(self, c_name);
} else {
// Convert the UTF-8 name to a java.lang.String. The name must use '.' to separate package
// components.
name = String::AllocFromModifiedUtf8(self, DescriptorToDot(descriptor).c_str());
}
h_this->SetName(name);
return name;
}
void Class::DumpClass(std::ostream& os, int flags) {
if ((flags & kDumpClassFullDetail) == 0) {
os << PrettyClass(this);
if ((flags & kDumpClassClassLoader) != 0) {
os << ' ' << GetClassLoader();
}
if ((flags & kDumpClassInitialized) != 0) {
os << ' ' << GetStatus();
}
os << "\n";
return;
}
Thread* const self = Thread::Current();
StackHandleScope<2> hs(self);
Handle<mirror::Class> h_this(hs.NewHandle(this));
Handle<mirror::Class> h_super(hs.NewHandle(GetSuperClass()));
auto image_pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
std::string temp;
os << "----- " << (IsInterface() ? "interface" : "class") << " "
<< "'" << GetDescriptor(&temp) << "' cl=" << GetClassLoader() << " -----\n",
os << " objectSize=" << SizeOf() << " "
<< "(" << (h_super.Get() != nullptr ? h_super->SizeOf() : -1) << " from super)\n",
os << StringPrintf(" access=0x%04x.%04x\n",
GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask);
if (h_super.Get() != nullptr) {
os << " super='" << PrettyClass(h_super.Get()) << "' (cl=" << h_super->GetClassLoader()
<< ")\n";
}
if (IsArrayClass()) {
os << " componentType=" << PrettyClass(GetComponentType()) << "\n";
}
const size_t num_direct_interfaces = NumDirectInterfaces();
if (num_direct_interfaces > 0) {
os << " interfaces (" << num_direct_interfaces << "):\n";
for (size_t i = 0; i < num_direct_interfaces; ++i) {
Class* interface = GetDirectInterface(self, h_this, i);
if (interface == nullptr) {
os << StringPrintf(" %2zd: nullptr!\n", i);
} else {
const ClassLoader* cl = interface->GetClassLoader();
os << StringPrintf(" %2zd: %s (cl=%p)\n", i, PrettyClass(interface).c_str(), cl);
}
}
}
if (!IsLoaded()) {
os << " class not yet loaded";
} else {
// After this point, this may have moved due to GetDirectInterface.
os << " vtable (" << h_this->NumVirtualMethods() << " entries, "
<< (h_super.Get() != nullptr ? h_super->NumVirtualMethods() : 0) << " in super):\n";
for (size_t i = 0; i < NumVirtualMethods(); ++i) {
os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(
h_this->GetVirtualMethodDuringLinking(i, image_pointer_size)).c_str());
}
os << " direct methods (" << h_this->NumDirectMethods() << " entries):\n";
for (size_t i = 0; i < h_this->NumDirectMethods(); ++i) {
os << StringPrintf(" %2zd: %s\n", i, PrettyMethod(
h_this->GetDirectMethod(i, image_pointer_size)).c_str());
}
if (h_this->NumStaticFields() > 0) {
os << " static fields (" << h_this->NumStaticFields() << " entries):\n";
if (h_this->IsResolved() || h_this->IsErroneous()) {
for (size_t i = 0; i < h_this->NumStaticFields(); ++i) {
os << StringPrintf(" %2zd: %s\n", i, PrettyField(h_this->GetStaticField(i)).c_str());
}
} else {
os << " <not yet available>";
}
}
if (h_this->NumInstanceFields() > 0) {
os << " instance fields (" << h_this->NumInstanceFields() << " entries):\n";
if (h_this->IsResolved() || h_this->IsErroneous()) {
for (size_t i = 0; i < h_this->NumInstanceFields(); ++i) {
os << StringPrintf(" %2zd: %s\n", i, PrettyField(h_this->GetInstanceField(i)).c_str());
}
} else {
os << " <not yet available>";
}
}
}
}
void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) {
if (kIsDebugBuild && new_reference_offsets != kClassWalkSuper) {
// Sanity check that the number of bits set in the reference offset bitmap
// agrees with the number of references
uint32_t count = 0;
for (Class* c = this; c != nullptr; c = c->GetSuperClass()) {
count += c->NumReferenceInstanceFieldsDuringLinking();
}
// +1 for the Class in Object.
CHECK_EQ(static_cast<uint32_t>(POPCOUNT(new_reference_offsets)) + 1, count);
}
// Not called within a transaction.
SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_),
new_reference_offsets);
}
bool Class::IsInSamePackage(const StringPiece& descriptor1, const StringPiece& descriptor2) {
size_t i = 0;
size_t min_length = std::min(descriptor1.size(), descriptor2.size());
while (i < min_length && descriptor1[i] == descriptor2[i]) {
++i;
}
if (descriptor1.find('/', i) != StringPiece::npos ||
descriptor2.find('/', i) != StringPiece::npos) {
return false;
} else {
return true;
}
}
bool Class::IsInSamePackage(Class* that) {
Class* klass1 = this;
Class* klass2 = that;
if (klass1 == klass2) {
return true;
}
// Class loaders must match.
if (klass1->GetClassLoader() != klass2->GetClassLoader()) {
return false;
}
// Arrays are in the same package when their element classes are.
while (klass1->IsArrayClass()) {
klass1 = klass1->GetComponentType();
}
while (klass2->IsArrayClass()) {
klass2 = klass2->GetComponentType();
}
// trivial check again for array types
if (klass1 == klass2) {
return true;
}
// Compare the package part of the descriptor string.
std::string temp1, temp2;
return IsInSamePackage(klass1->GetDescriptor(&temp1), klass2->GetDescriptor(&temp2));
}
bool Class::IsThrowableClass() {
return WellKnownClasses::ToClass(WellKnownClasses::java_lang_Throwable)->IsAssignableFrom(this);
}
void Class::SetClassLoader(ClassLoader* new_class_loader) {
if (Runtime::Current()->IsActiveTransaction()) {
SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader);
} else {
SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader);
}
}
ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const StringPiece& signature,
size_t pointer_size) {
// Check the current class before checking the interfaces.
ArtMethod* method = FindDeclaredVirtualMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
int32_t iftable_count = GetIfTableCount();
IfTable* iftable = GetIfTable();
for (int32_t i = 0; i < iftable_count; ++i) {
method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindInterfaceMethod(const StringPiece& name, const Signature& signature,
size_t pointer_size) {
// Check the current class before checking the interfaces.
ArtMethod* method = FindDeclaredVirtualMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
int32_t iftable_count = GetIfTableCount();
IfTable* iftable = GetIfTable();
for (int32_t i = 0; i < iftable_count; ++i) {
method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindInterfaceMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
size_t pointer_size) {
// Check the current class before checking the interfaces.
ArtMethod* method = FindDeclaredVirtualMethod(dex_cache, dex_method_idx, pointer_size);
if (method != nullptr) {
return method;
}
int32_t iftable_count = GetIfTableCount();
IfTable* iftable = GetIfTable();
for (int32_t i = 0; i < iftable_count; ++i) {
method = iftable->GetInterface(i)->FindDeclaredVirtualMethod(
dex_cache, dex_method_idx, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const StringPiece& signature,
size_t pointer_size) {
for (auto& method : GetDirectMethods(pointer_size)) {
if (name == method.GetName() && method.GetSignature() == signature) {
return &method;
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredDirectMethod(const StringPiece& name, const Signature& signature,
size_t pointer_size) {
for (auto& method : GetDirectMethods(pointer_size)) {
if (name == method.GetName() && signature == method.GetSignature()) {
return &method;
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredDirectMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
size_t pointer_size) {
if (GetDexCache() == dex_cache) {
for (auto& method : GetDirectMethods(pointer_size)) {
if (method.GetDexMethodIndex() == dex_method_idx) {
return &method;
}
}
}
return nullptr;
}
ArtMethod* Class::FindDirectMethod(const StringPiece& name, const StringPiece& signature,
size_t pointer_size) {
for (Class* klass = this; klass != nullptr; klass = klass->GetSuperClass()) {
ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindDirectMethod(const StringPiece& name, const Signature& signature,
size_t pointer_size) {
for (Class* klass = this; klass != nullptr; klass = klass->GetSuperClass()) {
ArtMethod* method = klass->FindDeclaredDirectMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindDirectMethod(
const DexCache* dex_cache, uint32_t dex_method_idx, size_t pointer_size) {
for (Class* klass = this; klass != nullptr; klass = klass->GetSuperClass()) {
ArtMethod* method = klass->FindDeclaredDirectMethod(dex_cache, dex_method_idx, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredDirectMethodByName(const StringPiece& name, size_t pointer_size) {
for (auto& method : GetDirectMethods(pointer_size)) {
ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
if (name == np_method->GetName()) {
return &method;
}
}
return nullptr;
}
// TODO These should maybe be changed to be named FindOwnedVirtualMethod or something similar
// because they do not only find 'declared' methods and will return copied methods. This behavior is
// desired and correct but the naming can lead to confusion because in the java language declared
// excludes interface methods which might be found by this.
ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature,
size_t pointer_size) {
for (auto& method : GetVirtualMethods(pointer_size)) {
ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
if (name == np_method->GetName() && np_method->GetSignature() == signature) {
return &method;
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature,
size_t pointer_size) {
for (auto& method : GetVirtualMethods(pointer_size)) {
ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
if (name == np_method->GetName() && signature == np_method->GetSignature()) {
return &method;
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredVirtualMethod(const DexCache* dex_cache, uint32_t dex_method_idx,
size_t pointer_size) {
if (GetDexCache() == dex_cache) {
for (auto& method : GetDeclaredVirtualMethods(pointer_size)) {
if (method.GetDexMethodIndex() == dex_method_idx) {
return &method;
}
}
}
return nullptr;
}
ArtMethod* Class::FindDeclaredVirtualMethodByName(const StringPiece& name, size_t pointer_size) {
for (auto& method : GetVirtualMethods(pointer_size)) {
ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
if (name == np_method->GetName()) {
return &method;
}
}
return nullptr;
}
ArtMethod* Class::FindVirtualMethod(
const StringPiece& name, const StringPiece& signature, size_t pointer_size) {
for (Class* klass = this; klass != nullptr; klass = klass->GetSuperClass()) {
ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindVirtualMethod(
const StringPiece& name, const Signature& signature, size_t pointer_size) {
for (Class* klass = this; klass != nullptr; klass = klass->GetSuperClass()) {
ArtMethod* method = klass->FindDeclaredVirtualMethod(name, signature, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindVirtualMethod(
const DexCache* dex_cache, uint32_t dex_method_idx, size_t pointer_size) {
for (Class* klass = this; klass != nullptr; klass = klass->GetSuperClass()) {
ArtMethod* method = klass->FindDeclaredVirtualMethod(dex_cache, dex_method_idx, pointer_size);
if (method != nullptr) {
return method;
}
}
return nullptr;
}
ArtMethod* Class::FindVirtualMethodForInterfaceSuper(ArtMethod* method, size_t pointer_size) {
DCHECK(method->GetDeclaringClass()->IsInterface());
DCHECK(IsInterface()) << "Should only be called on a interface class";
// Check if we have one defined on this interface first. This includes searching copied ones to
// get any conflict methods. Conflict methods are copied into each subtype from the supertype. We
// don't do any indirect method checks here.
for (ArtMethod& iface_method : GetVirtualMethods(pointer_size)) {
if (method->HasSameNameAndSignature(&iface_method)) {
return &iface_method;
}
}
std::vector<ArtMethod*> abstract_methods;
// Search through the IFTable for a working version. We don't need to check for conflicts
// because if there was one it would appear in this classes virtual_methods_ above.
Thread* self = Thread::Current();
StackHandleScope<2> hs(self);
MutableHandle<mirror::IfTable> iftable(hs.NewHandle(GetIfTable()));
MutableHandle<mirror::Class> iface(hs.NewHandle<mirror::Class>(nullptr));
size_t iftable_count = GetIfTableCount();
// Find the method. We don't need to check for conflicts because they would have been in the
// copied virtuals of this interface. Order matters, traverse in reverse topological order; most
// subtypiest interfaces get visited first.
for (size_t k = iftable_count; k != 0;) {
k--;
DCHECK_LT(k, iftable->Count());
iface.Assign(iftable->GetInterface(k));
// Iterate through every declared method on this interface. Each direct method's name/signature
// is unique so the order of the inner loop doesn't matter.
for (auto& method_iter : iface->GetDeclaredVirtualMethods(pointer_size)) {
ArtMethod* current_method = &method_iter;
if (current_method->HasSameNameAndSignature(method)) {
if (current_method->IsDefault()) {
// Handle JLS soft errors, a default method from another superinterface tree can
// "override" an abstract method(s) from another superinterface tree(s). To do this,
// ignore any [default] method which are dominated by the abstract methods we've seen so
// far. Check if overridden by any in abstract_methods. We do not need to check for
// default_conflicts because we would hit those before we get to this loop.
bool overridden = false;
for (ArtMethod* possible_override : abstract_methods) {
DCHECK(possible_override->HasSameNameAndSignature(current_method));
if (iface->IsAssignableFrom(possible_override->GetDeclaringClass())) {
overridden = true;
break;
}
}
if (!overridden) {
return current_method;
}
} else {
// Is not default.
// This might override another default method. Just stash it for now.
abstract_methods.push_back(current_method);
}
}
}
}
// If we reach here we either never found any declaration of the method (in which case
// 'abstract_methods' is empty or we found no non-overriden default methods in which case
// 'abstract_methods' contains a number of abstract implementations of the methods. We choose one
// of these arbitrarily.
return abstract_methods.empty() ? nullptr : abstract_methods[0];
}
ArtMethod* Class::FindClassInitializer(size_t pointer_size) {
for (ArtMethod& method : GetDirectMethods(pointer_size)) {
if (method.IsClassInitializer()) {
DCHECK_STREQ(method.GetName(), "<clinit>");
DCHECK_STREQ(method.GetSignature().ToString().c_str(), "()V");
return &method;
}
}
return nullptr;
}
// Custom binary search to avoid double comparisons from std::binary_search.
static ArtField* FindFieldByNameAndType(LengthPrefixedArray<ArtField>* fields,
const StringPiece& name,
const StringPiece& type)
SHARED_REQUIRES(Locks::mutator_lock_) {
if (fields == nullptr) {
return nullptr;
}
size_t low = 0;
size_t high = fields->size();
ArtField* ret = nullptr;
while (low < high) {
size_t mid = (low + high) / 2;
ArtField& field = fields->At(mid);
// Fields are sorted by class, then name, then type descriptor. This is verified in dex file
// verifier. There can be multiple fields with the same in the same class name due to proguard.
int result = StringPiece(field.GetName()).Compare(name);
if (result == 0) {
result = StringPiece(field.GetTypeDescriptor()).Compare(type);
}
if (result < 0) {
low = mid + 1;
} else if (result > 0) {
high = mid;
} else {
ret = &field;
break;
}
}
if (kIsDebugBuild) {
ArtField* found = nullptr;
for (ArtField& field : MakeIterationRangeFromLengthPrefixedArray(fields)) {
if (name == field.GetName() && type == field.GetTypeDescriptor()) {
found = &field;
break;
}
}
CHECK_EQ(found, ret) << "Found " << PrettyField(found) << " vs " << PrettyField(ret);
}
return ret;
}
ArtField* Class::FindDeclaredInstanceField(const StringPiece& name, const StringPiece& type) {
// Binary search by name. Interfaces are not relevant because they can't contain instance fields.
return FindFieldByNameAndType(GetIFieldsPtr(), name, type);
}
ArtField* Class::FindDeclaredInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
if (GetDexCache() == dex_cache) {
for (ArtField& field : GetIFields()) {
if (field.GetDexFieldIndex() == dex_field_idx) {
return &field;
}
}
}
return nullptr;
}
ArtField* Class::FindInstanceField(const StringPiece& name, const StringPiece& type) {
// Is the field in this class, or any of its superclasses?
// Interfaces are not relevant because they can't contain instance fields.
for (Class* c = this; c != nullptr; c = c->GetSuperClass()) {
ArtField* f = c->FindDeclaredInstanceField(name, type);
if (f != nullptr) {
return f;
}
}
return nullptr;
}
ArtField* Class::FindInstanceField(const DexCache* dex_cache, uint32_t dex_field_idx) {
// Is the field in this class, or any of its superclasses?
// Interfaces are not relevant because they can't contain instance fields.
for (Class* c = this; c != nullptr; c = c->GetSuperClass()) {
ArtField* f = c->FindDeclaredInstanceField(dex_cache, dex_field_idx);
if (f != nullptr) {
return f;
}
}
return nullptr;
}
ArtField* Class::FindDeclaredStaticField(const StringPiece& name, const StringPiece& type) {
DCHECK(type != nullptr);
return FindFieldByNameAndType(GetSFieldsPtr(), name, type);
}
ArtField* Class::FindDeclaredStaticField(const DexCache* dex_cache, uint32_t dex_field_idx) {
if (dex_cache == GetDexCache()) {
for (ArtField& field : GetSFields()) {
if (field.GetDexFieldIndex() == dex_field_idx) {
return &field;
}
}
}
return nullptr;
}
ArtField* Class::FindStaticField(Thread* self, Handle<Class> klass, const StringPiece& name,
const StringPiece& type) {
// Is the field in this class (or its interfaces), or any of its
// superclasses (or their interfaces)?
for (Class* k = klass.Get(); k != nullptr; k = k->GetSuperClass()) {
// Is the field in this class?
ArtField* f = k->FindDeclaredStaticField(name, type);
if (f != nullptr) {
return f;
}
// Wrap k incase it moves during GetDirectInterface.
StackHandleScope<1> hs(self);
HandleWrapper<mirror::Class> h_k(hs.NewHandleWrapper(&k));
// Is this field in any of this class' interfaces?
for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) {
StackHandleScope<1> hs2(self);
Handle<mirror::Class> interface(hs2.NewHandle(GetDirectInterface(self, h_k, i)));
f = FindStaticField(self, interface, name, type);
if (f != nullptr) {
return f;
}
}
}
return nullptr;
}
ArtField* Class::FindStaticField(Thread* self, Handle<Class> klass, const DexCache* dex_cache,
uint32_t dex_field_idx) {
for (Class* k = klass.Get(); k != nullptr; k = k->GetSuperClass()) {
// Is the field in this class?
ArtField* f = k->FindDeclaredStaticField(dex_cache, dex_field_idx);
if (f != nullptr) {
return f;
}
// Wrap k incase it moves during GetDirectInterface.
StackHandleScope<1> hs(self);
HandleWrapper<mirror::Class> h_k(hs.NewHandleWrapper(&k));
// Is this field in any of this class' interfaces?
for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) {
StackHandleScope<1> hs2(self);
Handle<mirror::Class> interface(hs2.NewHandle(GetDirectInterface(self, h_k, i)));
f = FindStaticField(self, interface, dex_cache, dex_field_idx);
if (f != nullptr) {
return f;
}
}
}
return nullptr;
}
ArtField* Class::FindField(Thread* self, Handle<Class> klass, const StringPiece& name,
const StringPiece& type) {
// Find a field using the JLS field resolution order
for (Class* k = klass.Get(); k != nullptr; k = k->GetSuperClass()) {
// Is the field in this class?
ArtField* f = k->FindDeclaredInstanceField(name, type);
if (f != nullptr) {
return f;
}
f = k->FindDeclaredStaticField(name, type);
if (f != nullptr) {
return f;
}
// Is this field in any of this class' interfaces?
StackHandleScope<1> hs(self);
HandleWrapper<mirror::Class> h_k(hs.NewHandleWrapper(&k));
for (uint32_t i = 0; i < h_k->NumDirectInterfaces(); ++i) {
StackHandleScope<1> hs2(self);
Handle<mirror::Class> interface(hs2.NewHandle(GetDirectInterface(self, h_k, i)));
f = interface->FindStaticField(self, interface, name, type);
if (f != nullptr) {
return f;
}
}
}
return nullptr;
}
void Class::SetSkipAccessChecksFlagOnAllMethods(size_t pointer_size) {
DCHECK(IsVerified());
for (auto& m : GetMethods(pointer_size)) {
if (!m.IsNative() && m.IsInvokable()) {
m.SetSkipAccessChecks();
}
}
}
const char* Class::GetDescriptor(std::string* storage) {
if (IsPrimitive()) {
return Primitive::Descriptor(GetPrimitiveType());
} else if (IsArrayClass()) {
return GetArrayDescriptor(storage);
} else if (IsProxyClass()) {
*storage = Runtime::Current()->GetClassLinker()->GetDescriptorForProxy(this);
return storage->c_str();
} else {
const DexFile& dex_file = GetDexFile();
const DexFile::TypeId& type_id = dex_file.GetTypeId(GetClassDef()->class_idx_);
return dex_file.GetTypeDescriptor(type_id);
}
}
const char* Class::GetArrayDescriptor(std::string* storage) {
std::string temp;
const char* elem_desc = GetComponentType()->GetDescriptor(&temp);
*storage = "[";
*storage += elem_desc;
return storage->c_str();
}
const DexFile::ClassDef* Class::GetClassDef() {
uint16_t class_def_idx = GetDexClassDefIndex();
if (class_def_idx == DexFile::kDexNoIndex16) {
return nullptr;
}
return &GetDexFile().GetClassDef(class_def_idx);
}
uint16_t Class::GetDirectInterfaceTypeIdx(uint32_t idx) {
DCHECK(!IsPrimitive());
DCHECK(!IsArrayClass());
return GetInterfaceTypeList()->GetTypeItem(idx).type_idx_;
}
mirror::Class* Class::GetDirectInterface(Thread* self, Handle<mirror::Class> klass,
uint32_t idx) {
DCHECK(klass.Get() != nullptr);
DCHECK(!klass->IsPrimitive());
if (klass->IsArrayClass()) {
ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
if (idx == 0) {
return class_linker->FindSystemClass(self, "Ljava/lang/Cloneable;");
} else {
DCHECK_EQ(1U, idx);
return class_linker->FindSystemClass(self, "Ljava/io/Serializable;");
}
} else if (klass->IsProxyClass()) {
mirror::ObjectArray<mirror::Class>* interfaces = klass.Get()->GetInterfaces();
DCHECK(interfaces != nullptr);
return interfaces->Get(idx);
} else {
uint16_t type_idx = klass->GetDirectInterfaceTypeIdx(idx);
mirror::Class* interface = klass->GetDexCache()->GetResolvedType(type_idx);
if (interface == nullptr) {
interface = Runtime::Current()->GetClassLinker()->ResolveType(klass->GetDexFile(), type_idx,
klass.Get());
CHECK(interface != nullptr || self->IsExceptionPending());
}
return interface;
}
}
mirror::Class* Class::GetCommonSuperClass(Handle<Class> klass) {
DCHECK(klass.Get() != nullptr);
DCHECK(!klass->IsInterface());
DCHECK(!IsInterface());
mirror::Class* common_super_class = this;
while (!common_super_class->IsAssignableFrom(klass.Get())) {
common_super_class = common_super_class->GetSuperClass();
}
DCHECK(common_super_class != nullptr);
return common_super_class;
}
const char* Class::GetSourceFile() {
const DexFile& dex_file = GetDexFile();
const DexFile::ClassDef* dex_class_def = GetClassDef();
if (dex_class_def == nullptr) {
// Generated classes have no class def.
return nullptr;
}
return dex_file.GetSourceFile(*dex_class_def);
}
std::string Class::GetLocation() {
mirror::DexCache* dex_cache = GetDexCache();
if (dex_cache != nullptr && !IsProxyClass()) {
return dex_cache->GetLocation()->ToModifiedUtf8();
}
// Arrays and proxies are generated and have no corresponding dex file location.
return "generated class";
}
const DexFile::TypeList* Class::GetInterfaceTypeList() {
const DexFile::ClassDef* class_def = GetClassDef();
if (class_def == nullptr) {
return nullptr;
}
return GetDexFile().GetInterfacesList(*class_def);
}
void Class::PopulateEmbeddedImtAndVTable(ArtMethod* const (&methods)[kImtSize],
size_t pointer_size) {
for (size_t i = 0; i < kImtSize; i++) {
auto method = methods[i];
DCHECK(method != nullptr);
SetEmbeddedImTableEntry(i, method, pointer_size);
}
PointerArray* table = GetVTableDuringLinking();
CHECK(table != nullptr) << PrettyClass(this);
const size_t table_length = table->GetLength();
SetEmbeddedVTableLength(table_length);
for (size_t i = 0; i < table_length; i++) {
SetEmbeddedVTableEntry(i, table->GetElementPtrSize<ArtMethod*>(i, pointer_size), pointer_size);
}
// Keep java.lang.Object class's vtable around for since it's easier
// to be reused by array classes during their linking.
if (!IsObjectClass()) {
SetVTable(nullptr);
}
}
class ReadBarrierOnNativeRootsVisitor {
public:
void operator()(mirror::Object* obj ATTRIBUTE_UNUSED,
MemberOffset offset ATTRIBUTE_UNUSED,
bool is_static ATTRIBUTE_UNUSED) const {}
void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root) const
SHARED_REQUIRES(Locks::mutator_lock_) {
if (!root->IsNull()) {
VisitRoot(root);
}
}
void VisitRoot(mirror::CompressedReference<mirror::Object>* root) const
SHARED_REQUIRES(Locks::mutator_lock_) {
mirror::Object* old_ref = root->AsMirrorPtr();
mirror::Object* new_ref = ReadBarrier::BarrierForRoot(root);
if (old_ref != new_ref) {
// Update the field atomically. This may fail if mutator updates before us, but it's ok.
auto* atomic_root =
reinterpret_cast<Atomic<mirror::CompressedReference<mirror::Object>>*>(root);
atomic_root->CompareExchangeStrongSequentiallyConsistent(
mirror::CompressedReference<mirror::Object>::FromMirrorPtr(old_ref),
mirror::CompressedReference<mirror::Object>::FromMirrorPtr(new_ref));
}
}
};
// The pre-fence visitor for Class::CopyOf().
class CopyClassVisitor {
public:
CopyClassVisitor(Thread* self, Handle<mirror::Class>* orig, size_t new_length,
size_t copy_bytes, ArtMethod* const (&imt)[mirror::Class::kImtSize],
size_t pointer_size)
: self_(self), orig_(orig), new_length_(new_length),
copy_bytes_(copy_bytes), imt_(imt), pointer_size_(pointer_size) {
}
void operator()(mirror::Object* obj, size_t usable_size ATTRIBUTE_UNUSED) const
SHARED_REQUIRES(Locks::mutator_lock_) {
StackHandleScope<1> hs(self_);
Handle<mirror::Class> h_new_class_obj(hs.NewHandle(obj->AsClass()));
mirror::Object::CopyObject(self_, h_new_class_obj.Get(), orig_->Get(), copy_bytes_);
mirror::Class::SetStatus(h_new_class_obj, Class::kStatusResolving, self_);
h_new_class_obj->PopulateEmbeddedImtAndVTable(imt_, pointer_size_);
h_new_class_obj->SetClassSize(new_length_);
// Visit all of the references to make sure there is no from space references in the native
// roots.
static_cast<mirror::Object*>(h_new_class_obj.Get())->VisitReferences(
ReadBarrierOnNativeRootsVisitor(), VoidFunctor());
}
private:
Thread* const self_;
Handle<mirror::Class>* const orig_;
const size_t new_length_;
const size_t copy_bytes_;
ArtMethod* const (&imt_)[mirror::Class::kImtSize];
const size_t pointer_size_;
DISALLOW_COPY_AND_ASSIGN(CopyClassVisitor);
};
Class* Class::CopyOf(Thread* self, int32_t new_length,
ArtMethod* const (&imt)[mirror::Class::kImtSize], size_t pointer_size) {
DCHECK_GE(new_length, static_cast<int32_t>(sizeof(Class)));
// We may get copied by a compacting GC.
StackHandleScope<1> hs(self);
Handle<mirror::Class> h_this(hs.NewHandle(this));
gc::Heap* heap = Runtime::Current()->GetHeap();
// The num_bytes (3rd param) is sizeof(Class) as opposed to SizeOf()
// to skip copying the tail part that we will overwrite here.
CopyClassVisitor visitor(self, &h_this, new_length, sizeof(Class), imt, pointer_size);
mirror::Object* new_class = kMovingClasses ?
heap->AllocObject<true>(self, java_lang_Class_.Read(), new_length, visitor) :
heap->AllocNonMovableObject<true>(self, java_lang_Class_.Read(), new_length, visitor);
if (UNLIKELY(new_class == nullptr)) {
self->AssertPendingOOMException();
return nullptr;
}
return new_class->AsClass();
}
bool Class::ProxyDescriptorEquals(const char* match) {
DCHECK(IsProxyClass());
return Runtime::Current()->GetClassLinker()->GetDescriptorForProxy(this) == match;
}
// TODO: Move this to java_lang_Class.cc?
ArtMethod* Class::GetDeclaredConstructor(
Thread* self, Handle<mirror::ObjectArray<mirror::Class>> args, size_t pointer_size) {
for (auto& m : GetDirectMethods(pointer_size)) {
// Skip <clinit> which is a static constructor, as well as non constructors.
if (m.IsStatic() || !m.IsConstructor()) {
continue;
}
// May cause thread suspension and exceptions.
if (m.GetInterfaceMethodIfProxy(sizeof(void*))->EqualParameters(args)) {
return &m;
}
if (UNLIKELY(self->IsExceptionPending())) {
return nullptr;
}
}
return nullptr;
}
uint32_t Class::Depth() {
uint32_t depth = 0;
for (Class* klass = this; klass->GetSuperClass() != nullptr; klass = klass->GetSuperClass()) {
depth++;
}
return depth;
}
uint32_t Class::FindTypeIndexInOtherDexFile(const DexFile& dex_file) {
std::string temp;
const DexFile::TypeId* type_id = dex_file.FindTypeId(GetDescriptor(&temp));
return (type_id == nullptr) ? DexFile::kDexNoIndex : dex_file.GetIndexForTypeId(*type_id);
}
template <bool kTransactionActive>
mirror::Method* Class::GetDeclaredMethodInternal(Thread* self,
mirror::Class* klass,
mirror::String* name,
mirror::ObjectArray<mirror::Class>* args) {
// Covariant return types permit the class to define multiple
// methods with the same name and parameter types. Prefer to
// return a non-synthetic method in such situations. We may
// still return a synthetic method to handle situations like
// escalated visibility. We never return miranda methods that
// were synthesized by the runtime.
constexpr uint32_t kSkipModifiers = kAccMiranda | kAccSynthetic;
StackHandleScope<3> hs(self);
auto h_method_name = hs.NewHandle(name);
if (UNLIKELY(h_method_name.Get() == nullptr)) {
ThrowNullPointerException("name == null");
return nullptr;
}
auto h_args = hs.NewHandle(args);
Handle<mirror::Class> h_klass = hs.NewHandle(klass);
ArtMethod* result = nullptr;
const size_t pointer_size = kTransactionActive
? Runtime::Current()->GetClassLinker()->GetImagePointerSize()
: sizeof(void*);
for (auto& m : h_klass->GetDeclaredVirtualMethods(pointer_size)) {
auto* np_method = m.GetInterfaceMethodIfProxy(pointer_size);
// May cause thread suspension.
mirror::String* np_name = np_method->GetNameAsString(self);
if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) {
if (UNLIKELY(self->IsExceptionPending())) {
return nullptr;
}
continue;
}
auto modifiers = m.GetAccessFlags();
if ((modifiers & kSkipModifiers) == 0) {
return mirror::Method::CreateFromArtMethod<kTransactionActive>(self, &m);
}
if ((modifiers & kAccMiranda) == 0) {
result = &m; // Remember as potential result if it's not a miranda method.
}
}
if (result == nullptr) {
for (auto& m : h_klass->GetDirectMethods(pointer_size)) {
auto modifiers = m.GetAccessFlags();
if ((modifiers & kAccConstructor) != 0) {
continue;
}
auto* np_method = m.GetInterfaceMethodIfProxy(pointer_size);
// May cause thread suspension.
mirror::String* np_name = np_method->GetNameAsString(self);
if (np_name == nullptr) {
self->AssertPendingException();
return nullptr;
}
if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) {
if (UNLIKELY(self->IsExceptionPending())) {
return nullptr;
}
continue;
}
if ((modifiers & kSkipModifiers) == 0) {
return mirror::Method::CreateFromArtMethod<kTransactionActive>(self, &m);
}
// Direct methods cannot be miranda methods, so this potential result must be synthetic.
result = &m;
}
}
return result != nullptr
? mirror::Method::CreateFromArtMethod<kTransactionActive>(self, result)
: nullptr;
}
template
mirror::Method* Class::GetDeclaredMethodInternal<false>(Thread* self,
mirror::Class* klass,
mirror::String* name,
mirror::ObjectArray<mirror::Class>* args);
template
mirror::Method* Class::GetDeclaredMethodInternal<true>(Thread* self,
mirror::Class* klass,
mirror::String* name,
mirror::ObjectArray<mirror::Class>* args);
template <bool kTransactionActive>
mirror::Constructor* Class::GetDeclaredConstructorInternal(
Thread* self,
mirror::Class* klass,
mirror::ObjectArray<mirror::Class>* args) {
StackHandleScope<1> hs(self);
const size_t pointer_size = kTransactionActive
? Runtime::Current()->GetClassLinker()->GetImagePointerSize()
: sizeof(void*);
ArtMethod* result = klass->GetDeclaredConstructor(self, hs.NewHandle(args), pointer_size);
return result != nullptr
? mirror::Constructor::CreateFromArtMethod<kTransactionActive>(self, result)
: nullptr;
}
// mirror::Constructor::CreateFromArtMethod<kTransactionActive>(self, result)
template mirror::Constructor* Class::GetDeclaredConstructorInternal<false>(
Thread* self,
mirror::Class* klass,
mirror::ObjectArray<mirror::Class>* args);
template mirror::Constructor* Class::GetDeclaredConstructorInternal<true>(
Thread* self,
mirror::Class* klass,
mirror::ObjectArray<mirror::Class>* args);
} // namespace mirror
} // namespace art
|