comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMethodData.java @ 23717:41fa89f93355

removed jdk.vm.ci.hotspot.HotSpotMethodDataAccessor.Tag (JDK-8159613)
author Doug Simon <doug.simon@oracle.com>
date Thu, 30 Jun 2016 22:07:57 +0200
parents 9e1235406b59
children a52d7039723b
comparison
equal deleted inserted replaced
23716:74c4e0459c11 23717:41fa89f93355
28 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; 28 import static jdk.vm.ci.hotspot.HotSpotVMConfig.config;
29 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; 29 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
30 30
31 import java.util.Arrays; 31 import java.util.Arrays;
32 32
33 import jdk.vm.ci.hotspot.HotSpotMethodDataAccessor.Tag;
34 import jdk.vm.ci.meta.DeoptimizationReason; 33 import jdk.vm.ci.meta.DeoptimizationReason;
35 import jdk.vm.ci.meta.JavaMethodProfile; 34 import jdk.vm.ci.meta.JavaMethodProfile;
36 import jdk.vm.ci.meta.JavaMethodProfile.ProfiledMethod; 35 import jdk.vm.ci.meta.JavaMethodProfile.ProfiledMethod;
37 import jdk.vm.ci.meta.JavaTypeProfile; 36 import jdk.vm.ci.meta.JavaTypeProfile;
38 import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType; 37 import jdk.vm.ci.meta.JavaTypeProfile.ProfiledType;
40 import jdk.vm.ci.meta.ResolvedJavaType; 39 import jdk.vm.ci.meta.ResolvedJavaType;
41 import jdk.vm.ci.meta.TriState; 40 import jdk.vm.ci.meta.TriState;
42 import sun.misc.Unsafe; 41 import sun.misc.Unsafe;
43 42
44 /** 43 /**
45 * Access to a HotSpot MethodData structure (defined in methodData.hpp). 44 * Access to a HotSpot {@code MethodData} structure (defined in methodData.hpp).
46 */ 45 */
47 public final class HotSpotMethodData { 46 final class HotSpotMethodData {
48 47
49 static final HotSpotVMConfig config = config(); 48 static final HotSpotVMConfig config = config();
50 static final HotSpotMethodDataAccessor NO_DATA_NO_EXCEPTION_ACCESSOR = new NoMethodData(TriState.FALSE); 49 static final HotSpotMethodDataAccessor NO_DATA_NO_EXCEPTION_ACCESSOR = new NoMethodData(config, config.dataLayoutNoTag, TriState.FALSE);
51 static final HotSpotMethodDataAccessor NO_DATA_EXCEPTION_POSSIBLY_NOT_RECORDED_ACCESSOR = new NoMethodData(TriState.UNKNOWN); 50 static final HotSpotMethodDataAccessor NO_DATA_EXCEPTION_POSSIBLY_NOT_RECORDED_ACCESSOR = new NoMethodData(config, config.dataLayoutNoTag, TriState.UNKNOWN);
52
53 static final int BIT_DATA_SIZE = cellIndexToOffset(0);
54 static final int BIT_DATA_NULL_SEEN_FLAG = 1 << config.bitDataNullSeenFlag;
55
56 static final int BRANCH_DATA_SIZE = cellIndexToOffset(3);
57 static final int NOT_TAKEN_COUNT_OFFSET = cellIndexToOffset(config.branchDataNotTakenOffset);
58
59 static final int ARG_INFO_DATA_SIZE = cellIndexToOffset(1);
60
61 static final int COUNTER_DATA_SIZE = cellIndexToOffset(1);
62 static final int COUNTER_DATA_COUNT_OFFSET = cellIndexToOffset(config.methodDataCountOffset);
63 static final int JUMP_DATA_SIZE = cellIndexToOffset(2);
64 static final int TAKEN_COUNT_OFFSET = cellIndexToOffset(config.jumpDataTakenOffset);
65 static final int TAKEN_DISPLACEMENT_OFFSET = cellIndexToOffset(config.jumpDataDisplacementOffset);
66 static final int TYPE_DATA_ROW_SIZE = cellsToBytes(config.receiverTypeDataReceiverTypeRowCellCount);
67
68 static final int NONPROFILED_COUNT_OFFSET = cellIndexToOffset(config.receiverTypeDataNonprofiledCountOffset);
69 static final int TYPE_DATA_FIRST_TYPE_OFFSET = cellIndexToOffset(config.receiverTypeDataReceiver0Offset);
70 static final int TYPE_DATA_FIRST_TYPE_COUNT_OFFSET = cellIndexToOffset(config.receiverTypeDataCount0Offset);
71 static final int VIRTUAL_CALL_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * (config.typeProfileWidth + config.methodProfileWidth);
72 static final int VIRTUAL_CALL_DATA_FIRST_METHOD_OFFSET = TYPE_DATA_FIRST_TYPE_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth;
73 static final int VIRTUAL_CALL_DATA_FIRST_METHOD_COUNT_OFFSET = TYPE_DATA_FIRST_TYPE_COUNT_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth;
74
75 static final int ARRAY_DATA_LENGTH_OFFSET = cellIndexToOffset(config.arrayDataArrayLenOffset);
76 static final int ARRAY_DATA_START_OFFSET = cellIndexToOffset(config.arrayDataArrayStartOffset);
77
78 static final int TYPE_CHECK_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * config.typeProfileWidth;
79
80 static final int RET_DATA_ROW_SIZE = cellsToBytes(3);
81 static final int RET_DATA_SIZE = cellIndexToOffset(1) + RET_DATA_ROW_SIZE * config.bciProfileWidth;
82
83 static final int MULTI_BRANCH_DATA_SIZE = cellIndexToOffset(1);
84 static final int MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS = config.multiBranchDataPerCaseCellCount;
85 static final int MULTI_BRANCH_DATA_ROW_SIZE = cellsToBytes(MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS);
86 static final int MULTI_BRANCH_DATA_FIRST_COUNT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(0);
87 static final int MULTI_BRANCH_DATA_FIRST_DISPLACEMENT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(1);
88
89 // sorted by tag
90 // @formatter:off
91 static final HotSpotMethodDataAccessor[] PROFILE_DATA_ACCESSORS = {
92 null,
93 new BitData(),
94 new CounterData(),
95 new JumpData(),
96 new ReceiverTypeData(),
97 new VirtualCallData(),
98 new RetData(),
99 new BranchData(),
100 new MultiBranchData(),
101 new ArgInfoData(),
102 new UnknownProfileData(Tag.CallTypeData),
103 new VirtualCallTypeData(),
104 new UnknownProfileData(Tag.ParametersTypeData),
105 new UnknownProfileData(Tag.SpeculativeTrapData),
106 };
107 // @formatter:on
108 51
109 /** 52 /**
110 * Reference to the C++ MethodData object. 53 * Reference to the C++ MethodData object.
111 */ 54 */
112 private final long metaspaceMethodData; 55 final long metaspaceMethodData;
113 @SuppressWarnings("unused") private final HotSpotResolvedJavaMethodImpl method; 56 @SuppressWarnings("unused") private final HotSpotResolvedJavaMethodImpl method;
114 57
115 public HotSpotMethodData(long metaspaceMethodData, HotSpotResolvedJavaMethodImpl method) { 58 public HotSpotMethodData(long metaspaceMethodData, HotSpotResolvedJavaMethodImpl method) {
116 this.metaspaceMethodData = metaspaceMethodData; 59 this.metaspaceMethodData = metaspaceMethodData;
117 this.method = method; 60 this.method = method;
167 public HotSpotMethodDataAccessor getNormalData(int position) { 110 public HotSpotMethodDataAccessor getNormalData(int position) {
168 if (position >= normalDataSize()) { 111 if (position >= normalDataSize()) {
169 return null; 112 return null;
170 } 113 }
171 114
172 HotSpotMethodDataAccessor result = getData(position); 115 return getData(position);
173 final Tag tag = AbstractMethodData.readTag(this, position);
174 assert result != null : "NO_DATA tag is not allowed " + tag;
175 return result;
176 } 116 }
177 117
178 public HotSpotMethodDataAccessor getExtraData(int position) { 118 public HotSpotMethodDataAccessor getExtraData(int position) {
179 if (position >= normalDataSize() + extraDataSize()) { 119 if (position >= normalDataSize() + extraDataSize()) {
180 return null; 120 return null;
194 } 134 }
195 } 135 }
196 136
197 private HotSpotMethodDataAccessor getData(int position) { 137 private HotSpotMethodDataAccessor getData(int position) {
198 assert position >= 0 : "out of bounds"; 138 assert position >= 0 : "out of bounds";
199 final Tag tag = AbstractMethodData.readTag(this, position); 139 final int tag = HotSpotMethodDataAccessor.readTag(config, this, position);
200 HotSpotMethodDataAccessor accessor = PROFILE_DATA_ACCESSORS[tag.getValue()]; 140 HotSpotMethodDataAccessor accessor = PROFILE_DATA_ACCESSORS[tag];
201 assert accessor == null || accessor.getTag() == tag : "wrong data accessor " + accessor + " for tag " + tag; 141 assert accessor == null || accessor.getTag() == tag : "wrong data accessor " + accessor + " for tag " + tag;
202 return accessor; 142 return accessor;
203 } 143 }
204 144
205 private int readUnsignedByte(int position, int offsetInBytes) { 145 int readUnsignedByte(int position, int offsetInBytes) {
206 long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); 146 long fullOffsetInBytes = computeFullOffset(position, offsetInBytes);
207 return UNSAFE.getByte(metaspaceMethodData + fullOffsetInBytes) & 0xFF; 147 return UNSAFE.getByte(metaspaceMethodData + fullOffsetInBytes) & 0xFF;
208 } 148 }
209 149
210 private int readUnsignedShort(int position, int offsetInBytes) { 150 int readUnsignedShort(int position, int offsetInBytes) {
211 long fullOffsetInBytes = computeFullOffset(position, offsetInBytes); 151 long fullOffsetInBytes = computeFullOffset(position, offsetInBytes);
212 return UNSAFE.getShort(metaspaceMethodData + fullOffsetInBytes) & 0xFFFF; 152 return UNSAFE.getShort(metaspaceMethodData + fullOffsetInBytes) & 0xFFFF;
213 } 153 }
214 154
215 /** 155 /**
303 243
304 } 244 }
305 return sb.toString(); 245 return sb.toString();
306 } 246 }
307 247
308 /**
309 * Corresponds to {@code exception_seen_flag}.
310 */
311 static final int EXCEPTIONS_MASK = 1 << config.bitDataExceptionSeenFlag;
312 static final int NO_DATA_SIZE = cellIndexToOffset(0); 248 static final int NO_DATA_SIZE = cellIndexToOffset(0);
313 249
314 private abstract static class AbstractMethodData implements HotSpotMethodDataAccessor { 250 static class NoMethodData extends HotSpotMethodDataAccessor {
315
316 private final Tag tag;
317 protected final int staticSize;
318
319 protected AbstractMethodData(Tag tag, int staticSize) {
320 this.tag = tag;
321 this.staticSize = staticSize;
322 }
323
324 public Tag getTag() {
325 return tag;
326 }
327
328 public static Tag readTag(HotSpotMethodData data, int position) {
329 final int tag = data.readUnsignedByte(position, config.dataLayoutTagOffset);
330 return Tag.getEnum(tag);
331 }
332
333 @Override
334 public int getBCI(HotSpotMethodData data, int position) {
335 return data.readUnsignedShort(position, config.dataLayoutBCIOffset);
336 }
337
338 @Override
339 public final int getSize(HotSpotMethodData data, int position) {
340 int size = staticSize + getDynamicSize(data, position);
341 // Sanity check against VM
342 int vmSize = HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position);
343 assert size == vmSize : size + " != " + vmSize;
344 return size;
345 }
346
347 @Override
348 public TriState getExceptionSeen(HotSpotMethodData data, int position) {
349 return TriState.get((getFlags(data, position) & EXCEPTIONS_MASK) != 0);
350 }
351
352 @Override
353 public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) {
354 return null;
355 }
356
357 @Override
358 public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) {
359 return null;
360 }
361
362 @Override
363 public double getBranchTakenProbability(HotSpotMethodData data, int position) {
364 return -1;
365 }
366
367 @Override
368 public double[] getSwitchProbabilities(HotSpotMethodData data, int position) {
369 return null;
370 }
371
372 @Override
373 public int getExecutionCount(HotSpotMethodData data, int position) {
374 return -1;
375 }
376
377 @Override
378 public TriState getNullSeen(HotSpotMethodData data, int position) {
379 return TriState.UNKNOWN;
380 }
381
382 protected int getFlags(HotSpotMethodData data, int position) {
383 return data.readUnsignedByte(position, config.dataLayoutFlagsOffset);
384 }
385
386 /**
387 * @param data
388 * @param position
389 */
390 protected int getDynamicSize(HotSpotMethodData data, int position) {
391 return 0;
392 }
393
394 public abstract StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos);
395 }
396
397 static class NoMethodData extends AbstractMethodData {
398 251
399 private final TriState exceptionSeen; 252 private final TriState exceptionSeen;
400 253
401 protected NoMethodData(TriState exceptionSeen) { 254 protected NoMethodData(HotSpotVMConfig config, int tag, TriState exceptionSeen) {
402 super(Tag.No, NO_DATA_SIZE); 255 super(config, tag, NO_DATA_SIZE);
403 this.exceptionSeen = exceptionSeen; 256 this.exceptionSeen = exceptionSeen;
404 } 257 }
405 258
406 @Override 259 @Override
407 public int getBCI(HotSpotMethodData data, int position) { 260 public int getBCI(HotSpotMethodData data, int position) {
417 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { 270 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) {
418 return sb; 271 return sb;
419 } 272 }
420 } 273 }
421 274
422 static class BitData extends AbstractMethodData { 275 static final int BIT_DATA_SIZE = cellIndexToOffset(0);
423 276 static final int BIT_DATA_NULL_SEEN_FLAG = 1 << config.bitDataNullSeenFlag;
424 private BitData() { 277
425 super(Tag.BitData, BIT_DATA_SIZE); 278 static class BitData extends HotSpotMethodDataAccessor {
426 } 279
427 280 private BitData(HotSpotVMConfig config, int tag) {
428 protected BitData(Tag tag, int staticSize) { 281 super(config, tag, BIT_DATA_SIZE);
429 super(tag, staticSize); 282 }
283
284 protected BitData(HotSpotVMConfig config, int tag, int staticSize) {
285 super(config, tag, staticSize);
430 } 286 }
431 287
432 @Override 288 @Override
433 public TriState getNullSeen(HotSpotMethodData data, int position) { 289 public TriState getNullSeen(HotSpotMethodData data, int position) {
434 return TriState.get((getFlags(data, position) & BIT_DATA_NULL_SEEN_FLAG) != 0); 290 return TriState.get((getFlags(data, position) & BIT_DATA_NULL_SEEN_FLAG) != 0);
438 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { 294 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) {
439 return sb.append(format("exception_seen(%s)", getExceptionSeen(data, pos))); 295 return sb.append(format("exception_seen(%s)", getExceptionSeen(data, pos)));
440 } 296 }
441 } 297 }
442 298
299 static final int COUNTER_DATA_SIZE = cellIndexToOffset(1);
300 static final int COUNTER_DATA_COUNT_OFFSET = cellIndexToOffset(config.methodDataCountOffset);
301
443 static class CounterData extends BitData { 302 static class CounterData extends BitData {
444 303
445 CounterData() { 304 CounterData(HotSpotVMConfig config, int tag) {
446 super(Tag.CounterData, COUNTER_DATA_SIZE); 305 super(config, tag, COUNTER_DATA_SIZE);
447 } 306 }
448 307
449 protected CounterData(Tag tag, int staticSize) { 308 protected CounterData(HotSpotVMConfig config, int tag, int staticSize) {
450 super(tag, staticSize); 309 super(config, tag, staticSize);
451 } 310 }
452 311
453 @Override 312 @Override
454 public int getExecutionCount(HotSpotMethodData data, int position) { 313 public int getExecutionCount(HotSpotMethodData data, int position) {
455 return getCounterValue(data, position); 314 return getCounterValue(data, position);
463 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { 322 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) {
464 return sb.append(format("count(%d) null_seen(%s) exception_seen(%s)", getCounterValue(data, pos), getNullSeen(data, pos), getExceptionSeen(data, pos))); 323 return sb.append(format("count(%d) null_seen(%s) exception_seen(%s)", getCounterValue(data, pos), getNullSeen(data, pos), getExceptionSeen(data, pos)));
465 } 324 }
466 } 325 }
467 326
468 static class JumpData extends AbstractMethodData { 327 static final int JUMP_DATA_SIZE = cellIndexToOffset(2);
469 328 static final int TAKEN_COUNT_OFFSET = cellIndexToOffset(config.jumpDataTakenOffset);
470 JumpData() { 329 static final int TAKEN_DISPLACEMENT_OFFSET = cellIndexToOffset(config.jumpDataDisplacementOffset);
471 super(Tag.JumpData, JUMP_DATA_SIZE); 330
472 } 331 static class JumpData extends HotSpotMethodDataAccessor {
473 332
474 protected JumpData(Tag tag, int staticSize) { 333 JumpData(HotSpotVMConfig config, int tag) {
475 super(tag, staticSize); 334 super(config, tag, JUMP_DATA_SIZE);
335 }
336
337 protected JumpData(HotSpotVMConfig config, int tag, int staticSize) {
338 super(config, tag, staticSize);
476 } 339 }
477 340
478 @Override 341 @Override
479 public double getBranchTakenProbability(HotSpotMethodData data, int position) { 342 public double getBranchTakenProbability(HotSpotMethodData data, int position) {
480 return getExecutionCount(data, position) != 0 ? 1 : 0; 343 return getExecutionCount(data, position) != 0 ? 1 : 0;
507 this.counts = counts; 370 this.counts = counts;
508 this.totalCount = totalCount; 371 this.totalCount = totalCount;
509 } 372 }
510 } 373 }
511 374
375 static final int TYPE_DATA_ROW_SIZE = cellsToBytes(config.receiverTypeDataReceiverTypeRowCellCount);
376
377 static final int NONPROFILED_COUNT_OFFSET = cellIndexToOffset(config.receiverTypeDataNonprofiledCountOffset);
378 static final int TYPE_DATA_FIRST_TYPE_OFFSET = cellIndexToOffset(config.receiverTypeDataReceiver0Offset);
379 static final int TYPE_DATA_FIRST_TYPE_COUNT_OFFSET = cellIndexToOffset(config.receiverTypeDataCount0Offset);
380
512 abstract static class AbstractTypeData extends CounterData { 381 abstract static class AbstractTypeData extends CounterData {
513 382
514 protected AbstractTypeData(Tag tag, int staticSize) { 383 protected AbstractTypeData(HotSpotVMConfig config, int tag, int staticSize) {
515 super(tag, staticSize); 384 super(config, tag, staticSize);
516 } 385 }
517 386
518 @Override 387 @Override
519 public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) { 388 public JavaTypeProfile getTypeProfile(HotSpotMethodData data, int position) {
520 return createTypeProfile(getNullSeen(data, position), getRawTypeProfile(data, position)); 389 return createTypeProfile(getNullSeen(data, position), getRawTypeProfile(data, position));
556 return new RawItemProfile<>(entries, types, counts, totalCount); 425 return new RawItemProfile<>(entries, types, counts, totalCount);
557 } 426 }
558 427
559 protected abstract long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position); 428 protected abstract long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position);
560 429
561 private static JavaTypeProfile createTypeProfile(TriState nullSeen, RawItemProfile<ResolvedJavaType> profile) { 430 private JavaTypeProfile createTypeProfile(TriState nullSeen, RawItemProfile<ResolvedJavaType> profile) {
562 if (profile.entries <= 0 || profile.totalCount <= 0) { 431 if (profile.entries <= 0 || profile.totalCount <= 0) {
563 return null; 432 return null;
564 } 433 }
565 434
566 ProfiledType[] ptypes = new ProfiledType[profile.entries]; 435 ProfiledType[] ptypes = new ProfiledType[profile.entries];
600 } 469 }
601 return sb; 470 return sb;
602 } 471 }
603 } 472 }
604 473
474 static final int TYPE_CHECK_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * config.typeProfileWidth;
475
605 static class ReceiverTypeData extends AbstractTypeData { 476 static class ReceiverTypeData extends AbstractTypeData {
606 477
607 ReceiverTypeData() { 478 ReceiverTypeData(HotSpotVMConfig config, int tag) {
608 super(Tag.ReceiverTypeData, TYPE_CHECK_DATA_SIZE); 479 super(config, tag, TYPE_CHECK_DATA_SIZE);
609 } 480 }
610 481
611 protected ReceiverTypeData(Tag tag, int staticSize) { 482 protected ReceiverTypeData(HotSpotVMConfig config, int tag, int staticSize) {
612 super(tag, staticSize); 483 super(config, tag, staticSize);
613 } 484 }
614 485
615 @Override 486 @Override
616 public int getExecutionCount(HotSpotMethodData data, int position) { 487 public int getExecutionCount(HotSpotMethodData data, int position) {
617 return -1; 488 return -1;
621 protected long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position) { 492 protected long getTypesNotRecordedExecutionCount(HotSpotMethodData data, int position) {
622 return data.readUnsignedIntAsSignedInt(position, NONPROFILED_COUNT_OFFSET); 493 return data.readUnsignedIntAsSignedInt(position, NONPROFILED_COUNT_OFFSET);
623 } 494 }
624 } 495 }
625 496
497 static final int VIRTUAL_CALL_DATA_SIZE = cellIndexToOffset(2) + TYPE_DATA_ROW_SIZE * (config.typeProfileWidth + config.methodProfileWidth);
498 static final int VIRTUAL_CALL_DATA_FIRST_METHOD_OFFSET = TYPE_DATA_FIRST_TYPE_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth;
499 static final int VIRTUAL_CALL_DATA_FIRST_METHOD_COUNT_OFFSET = TYPE_DATA_FIRST_TYPE_COUNT_OFFSET + TYPE_DATA_ROW_SIZE * config.typeProfileWidth;
500
626 static class VirtualCallData extends ReceiverTypeData { 501 static class VirtualCallData extends ReceiverTypeData {
627 502
628 VirtualCallData() { 503 VirtualCallData(HotSpotVMConfig config, int tag) {
629 super(Tag.VirtualCallData, VIRTUAL_CALL_DATA_SIZE); 504 super(config, tag, VIRTUAL_CALL_DATA_SIZE);
630 } 505 }
631 506
632 protected VirtualCallData(Tag tag, int staticSize) { 507 protected VirtualCallData(HotSpotVMConfig config, int tag, int staticSize) {
633 super(tag, staticSize); 508 super(config, tag, staticSize);
634 } 509 }
635 510
636 @Override 511 @Override
637 public int getExecutionCount(HotSpotMethodData data, int position) { 512 public int getExecutionCount(HotSpotMethodData data, int position) {
638 final int typeProfileWidth = config.typeProfileWidth; 513 final int typeProfileWidth = config.typeProfileWidth;
658 @Override 533 @Override
659 public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) { 534 public JavaMethodProfile getMethodProfile(HotSpotMethodData data, int position) {
660 return createMethodProfile(getRawMethodProfile(data, position)); 535 return createMethodProfile(getRawMethodProfile(data, position));
661 } 536 }
662 537
663 private static RawItemProfile<ResolvedJavaMethod> getRawMethodProfile(HotSpotMethodData data, int position) { 538 private RawItemProfile<ResolvedJavaMethod> getRawMethodProfile(HotSpotMethodData data, int position) {
664 int profileWidth = config.methodProfileWidth; 539 int profileWidth = config.methodProfileWidth;
665 540
666 ResolvedJavaMethod[] methods = new ResolvedJavaMethod[profileWidth]; 541 ResolvedJavaMethod[] methods = new ResolvedJavaMethod[profileWidth];
667 long[] counts = new long[profileWidth]; 542 long[] counts = new long[profileWidth];
668 long totalCount = 0; 543 long totalCount = 0;
682 557
683 totalCount += getMethodsNotRecordedExecutionCount(data, position); 558 totalCount += getMethodsNotRecordedExecutionCount(data, position);
684 return new RawItemProfile<>(entries, methods, counts, totalCount); 559 return new RawItemProfile<>(entries, methods, counts, totalCount);
685 } 560 }
686 561
687 private static JavaMethodProfile createMethodProfile(RawItemProfile<ResolvedJavaMethod> profile) { 562 private JavaMethodProfile createMethodProfile(RawItemProfile<ResolvedJavaMethod> profile) {
688 if (profile.entries <= 0 || profile.totalCount <= 0) { 563 if (profile.entries <= 0 || profile.totalCount <= 0) {
689 return null; 564 return null;
690 } 565 }
691 566
692 ProfiledMethod[] pmethods = new ProfiledMethod[profile.entries]; 567 ProfiledMethod[] pmethods = new ProfiledMethod[profile.entries];
725 } 600 }
726 } 601 }
727 602
728 static class VirtualCallTypeData extends VirtualCallData { 603 static class VirtualCallTypeData extends VirtualCallData {
729 604
730 VirtualCallTypeData() { 605 VirtualCallTypeData(HotSpotVMConfig config, int tag) {
731 super(Tag.VirtualCallTypeData, 0); 606 super(config, tag, 0);
732 } 607 }
733 608
734 @Override 609 @Override
735 protected int getDynamicSize(HotSpotMethodData data, int position) { 610 protected int getDynamicSize(HotSpotMethodData data, int position) {
736 assert staticSize == 0; 611 assert staticSize == 0;
737 return HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position); 612 return HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position);
738 } 613 }
739 } 614 }
740 615
616 static final int RET_DATA_ROW_SIZE = cellsToBytes(3);
617 static final int RET_DATA_SIZE = cellIndexToOffset(1) + RET_DATA_ROW_SIZE * config.bciProfileWidth;
618
741 static class RetData extends CounterData { 619 static class RetData extends CounterData {
742 620
743 RetData() { 621 RetData(HotSpotVMConfig config, int tag) {
744 super(Tag.RetData, RET_DATA_SIZE); 622 super(config, tag, RET_DATA_SIZE);
745 } 623 }
746 } 624 }
625
626 static final int BRANCH_DATA_SIZE = cellIndexToOffset(3);
627 static final int NOT_TAKEN_COUNT_OFFSET = cellIndexToOffset(config.branchDataNotTakenOffset);
747 628
748 static class BranchData extends JumpData { 629 static class BranchData extends JumpData {
749 630
750 BranchData() { 631 BranchData(HotSpotVMConfig config, int tag) {
751 super(Tag.BranchData, BRANCH_DATA_SIZE); 632 super(config, tag, BRANCH_DATA_SIZE);
752 } 633 }
753 634
754 @Override 635 @Override
755 public double getBranchTakenProbability(HotSpotMethodData data, int position) { 636 public double getBranchTakenProbability(HotSpotMethodData data, int position) {
756 long takenCount = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET); 637 long takenCount = data.readUnsignedInt(position, TAKEN_COUNT_OFFSET);
773 double takenProbability = getBranchTakenProbability(data, pos); 654 double takenProbability = getBranchTakenProbability(data, pos);
774 return sb.append(format("taken(%d, %4.2f) not_taken(%d, %4.2f) displacement(%d)", taken, takenProbability, notTaken, 1.0D - takenProbability, getTakenDisplacement(data, pos))); 655 return sb.append(format("taken(%d, %4.2f) not_taken(%d, %4.2f) displacement(%d)", taken, takenProbability, notTaken, 1.0D - takenProbability, getTakenDisplacement(data, pos)));
775 } 656 }
776 } 657 }
777 658
778 static class ArrayData extends AbstractMethodData { 659 static final int ARRAY_DATA_LENGTH_OFFSET = cellIndexToOffset(config.arrayDataArrayLenOffset);
779 660 static final int ARRAY_DATA_START_OFFSET = cellIndexToOffset(config.arrayDataArrayStartOffset);
780 ArrayData(Tag tag, int staticSize) { 661
781 super(tag, staticSize); 662 static class ArrayData extends HotSpotMethodDataAccessor {
663
664 ArrayData(HotSpotVMConfig config, int tag, int staticSize) {
665 super(config, tag, staticSize);
782 } 666 }
783 667
784 @Override 668 @Override
785 protected int getDynamicSize(HotSpotMethodData data, int position) { 669 protected int getDynamicSize(HotSpotMethodData data, int position) {
786 return cellsToBytes(getLength(data, position)); 670 return cellsToBytes(getLength(data, position));
794 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { 678 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) {
795 return sb.append(format("length(%d)", getLength(data, pos))); 679 return sb.append(format("length(%d)", getLength(data, pos)));
796 } 680 }
797 } 681 }
798 682
683 static final int MULTI_BRANCH_DATA_SIZE = cellIndexToOffset(1);
684 static final int MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS = config.multiBranchDataPerCaseCellCount;
685 static final int MULTI_BRANCH_DATA_ROW_SIZE = cellsToBytes(MULTI_BRANCH_DATA_ROW_SIZE_IN_CELLS);
686 static final int MULTI_BRANCH_DATA_FIRST_COUNT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(0);
687 static final int MULTI_BRANCH_DATA_FIRST_DISPLACEMENT_OFFSET = ARRAY_DATA_START_OFFSET + cellsToBytes(1);
688
799 static class MultiBranchData extends ArrayData { 689 static class MultiBranchData extends ArrayData {
800 690
801 MultiBranchData() { 691 MultiBranchData(HotSpotVMConfig config, int tag) {
802 super(Tag.MultiBranchData, MULTI_BRANCH_DATA_SIZE); 692 super(config, tag, MULTI_BRANCH_DATA_SIZE);
803 } 693 }
804 694
805 @Override 695 @Override
806 public double[] getSwitchProbabilities(HotSpotMethodData data, int position) { 696 public double[] getSwitchProbabilities(HotSpotMethodData data, int position) {
807 int arrayLength = getLength(data, position); 697 int arrayLength = getLength(data, position);
874 } 764 }
875 return sb; 765 return sb;
876 } 766 }
877 } 767 }
878 768
769 static final int ARG_INFO_DATA_SIZE = cellIndexToOffset(1);
770
879 static class ArgInfoData extends ArrayData { 771 static class ArgInfoData extends ArrayData {
880 772
881 ArgInfoData() { 773 ArgInfoData(HotSpotVMConfig config, int tag) {
882 super(Tag.ArgInfoData, ARG_INFO_DATA_SIZE); 774 super(config, tag, ARG_INFO_DATA_SIZE);
883 } 775 }
884 } 776 }
885 777
886 static class UnknownProfileData extends AbstractMethodData { 778 static class UnknownProfileData extends HotSpotMethodDataAccessor {
887 UnknownProfileData(Tag tag) { 779 UnknownProfileData(HotSpotVMConfig config, int tag) {
888 super(tag, 0); 780 super(config, tag, 0);
889 } 781 }
890 782
891 @Override 783 @Override
892 protected int getDynamicSize(HotSpotMethodData data, int position) { 784 protected int getDynamicSize(HotSpotMethodData data, int position) {
893 assert staticSize == 0; 785 assert staticSize == 0;
894 return HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position); 786 return HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position);
895 } 787 }
896 788
897 @Override 789 @Override
898 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) { 790 public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) {
899 // TODO Auto-generated method stub
900 return null; 791 return null;
901 } 792 }
902 } 793 }
903 794
904 public void setCompiledIRSize(int size) { 795 public void setCompiledIRSize(int size) {
906 } 797 }
907 798
908 public int getCompiledIRSize() { 799 public int getCompiledIRSize() {
909 return UNSAFE.getInt(metaspaceMethodData + config.methodDataIRSizeOffset); 800 return UNSAFE.getInt(metaspaceMethodData + config.methodDataIRSizeOffset);
910 } 801 }
802
803 // sorted by tag
804 // @formatter:off
805 static final HotSpotMethodDataAccessor[] PROFILE_DATA_ACCESSORS = {
806 null,
807 new BitData(config, config.dataLayoutBitDataTag),
808 new CounterData(config, config.dataLayoutCounterDataTag),
809 new JumpData(config, config.dataLayoutJumpDataTag),
810 new ReceiverTypeData(config, config.dataLayoutReceiverTypeDataTag),
811 new VirtualCallData(config, config.dataLayoutVirtualCallDataTag),
812 new RetData(config, config.dataLayoutRetDataTag),
813 new BranchData(config, config.dataLayoutBranchDataTag),
814 new MultiBranchData(config, config.dataLayoutMultiBranchDataTag),
815 new ArgInfoData(config, config.dataLayoutArgInfoDataTag),
816 new UnknownProfileData(config, config.dataLayoutCallTypeDataTag),
817 new VirtualCallTypeData(config, config.dataLayoutVirtualCallTypeDataTag),
818 new UnknownProfileData(config, config.dataLayoutParametersTypeDataTag),
819 new UnknownProfileData(config, config.dataLayoutSpeculativeTrapDataTag),
820 };
821
822 private static boolean checkAccessorTags() {
823 int expectedTag = 0;
824 for (HotSpotMethodDataAccessor accessor : PROFILE_DATA_ACCESSORS) {
825 if (expectedTag ==0 ) {
826 assert accessor == null;
827 } else {
828 assert accessor.tag == expectedTag: expectedTag + " != " + accessor.tag + " " + accessor;
829 }
830 expectedTag++;
831 }
832 return true;
833 }
834
835 static {
836 assert checkAccessorTags();
837 }
838 // @formatter:on
911 } 839 }