| 953 | } |
| 954 | |
| 955 | Result BytecodeRewriter::rewriteClass() { |
| 956 | u32 magic = get32(); |
| 957 | put32(magic); |
| 958 | |
| 959 | u32 version = get32(); |
| 960 | put32(version); |
| 961 | |
| 962 | _cpool_len = get16(); |
| 963 | u32 cpool_len_idx = _dst_len; |
| 964 | put16(0); // to be patched later |
| 965 | |
| 966 | const u8* cpool_start = _src; |
| 967 | |
| 968 | _cpool = new Constant*[_cpool_len]; |
| 969 | for (int i = 1; i < _cpool_len; i += _cpool[i]->slots()) { |
| 970 | _cpool[i] = getConstant(); |
| 971 | } |
| 972 | |
| 973 | const u8* cpool_end = _src; |
| 974 | put(cpool_start, cpool_end - cpool_start); |
| 975 | |
| 976 | _recordEntry_cpool_idx = _cpool_len; |
| 977 | putConstant(JVM_CONSTANT_Methodref, _cpool_len + 1, _cpool_len + 2); |
| 978 | putConstant(JVM_CONSTANT_Class, _cpool_len + 3); |
| 979 | putConstant(JVM_CONSTANT_NameAndType, _cpool_len + 4, _cpool_len + 5); |
| 980 | putConstant("one/profiler/Instrument"); |
| 981 | putConstant("recordEntry"); |
| 982 | putConstant("()V"); |
| 983 | |
| 984 | _recordExit_cpool_idx = _cpool_len + 6; |
| 985 | putConstant(JVM_CONSTANT_Methodref, _cpool_len + 1, _cpool_len + 7); |
| 986 | putConstant(JVM_CONSTANT_NameAndType, _cpool_len + 8, _cpool_len + 9); |
| 987 | putConstant("recordExit"); |
| 988 | putConstant("(JJ)V"); |
| 989 | |
| 990 | _recordExit_latency0_cpool_idx = _cpool_len + 10; |
| 991 | putConstant(JVM_CONSTANT_Methodref, _cpool_len + 1, _cpool_len + 11); |
| 992 | putConstant(JVM_CONSTANT_NameAndType, _cpool_len + 8, _cpool_len + 12); |
| 993 | putConstant("(J)V"); |
| 994 | |
| 995 | _nanoTime_cpool_idx = _cpool_len + 13; |
| 996 | putConstant(JVM_CONSTANT_Methodref, _cpool_len + 14, _cpool_len + 15); |
| 997 | putConstant(JVM_CONSTANT_Class, _cpool_len + 16); |
| 998 | putConstant(JVM_CONSTANT_NameAndType, _cpool_len + 17, _cpool_len + 18); |
| 999 | putConstant("java/lang/System"); |
| 1000 | putConstant("nanoTime"); |
| 1001 | putConstant("()J"); |
| 1002 | |
| 1003 | // Flushed later to the buffer, after latency-related constants are written to the cpool |
| 1004 | u16 access_flags = get16(); |
| 1005 | u16 this_class = get16(); |
| 1006 | |
| 1007 | u16 class_name_index = _cpool[this_class]->info(); |
| 1008 | _class_name = _cpool[class_name_index]; |
| 1009 | // We should not instrument classes from one.profiler.* to avoid infinite recursion |
| 1010 | if (_class_name->info() >= PROFILER_PACKAGE_LEN && |
| 1011 | strncmp(_class_name->utf8(), PROFILER_PACKAGE, PROFILER_PACKAGE_LEN) == 0) { |
| 1012 | return Result::PROFILER_CLASS; |
nothing calls this directly
no test coverage detected