|
4 | 4 | package hotspot // import "go.opentelemetry.io/ebpf-profiler/interpreter/hotspot" |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "bytes" |
8 | 7 | "encoding/binary" |
9 | 8 | "errors" |
10 | 9 | "fmt" |
@@ -399,45 +398,35 @@ func locateJvmciVMStructs(ef *pfelf.File) (libpf.Address, error) { |
399 | 398 | const maxDataReadSize = 1 * 1024 * 1024 // seen in practice: 192 KiB |
400 | 399 | const maxRodataReadSize = 4 * 1024 * 1024 // seen in practice: 753 KiB |
401 | 400 |
|
402 | | - rodataSec := ef.Section(".rodata") |
403 | | - if rodataSec == nil { |
| 401 | + rodata := ef.Section(".rodata") |
| 402 | + if rodata == nil { |
404 | 403 | return 0, errors.New("unable to find `.rodata` section") |
405 | 404 | } |
406 | 405 |
|
407 | | - rodata, err := rodataSec.Data(maxRodataReadSize) |
| 406 | + offs, err := libpf.SearchReader(rodata, []byte("Klass_vtable_start_offset")) |
408 | 407 | if err != nil { |
409 | | - return 0, err |
410 | | - } |
411 | | - |
412 | | - offs := bytes.Index(rodata, []byte("Klass_vtable_start_offset")) |
413 | | - if offs == -1 { |
414 | 408 | return 0, errors.New("unable to find string for heuristic") |
415 | 409 | } |
416 | 410 |
|
417 | | - ptr := rodataSec.Addr + uint64(offs) |
| 411 | + ptr := rodata.Addr + uint64(offs) |
418 | 412 | ptrEncoded := make([]byte, 8) |
419 | 413 | binary.LittleEndian.PutUint64(ptrEncoded, ptr) |
420 | 414 |
|
421 | | - dataSec := ef.Section(".data") |
422 | | - if dataSec == nil { |
| 415 | + data := ef.Section(".data") |
| 416 | + if data == nil { |
423 | 417 | return 0, errors.New("unable to find `.data` section") |
424 | 418 | } |
425 | 419 |
|
426 | | - data, err := dataSec.Data(maxDataReadSize) |
| 420 | + offs, err = libpf.SearchReader(data, ptrEncoded) |
427 | 421 | if err != nil { |
428 | | - return 0, err |
429 | | - } |
430 | | - |
431 | | - offs = bytes.Index(data, ptrEncoded) |
432 | | - if offs == -1 { |
433 | 422 | return 0, errors.New("unable to find string pointer") |
434 | 423 | } |
435 | 424 |
|
436 | 425 | // 8 in the expression below is what we'd usually read from |
437 | 426 | // gHotSpotVMStructEntryFieldNameOffset. This value unfortunately lives in |
438 | 427 | // BSS, so we have no choice but to hard-code it. Fortunately enough this |
439 | 428 | // offset hasn't changed since at least JDK 9. |
440 | | - return libpf.Address(dataSec.Addr + uint64(offs) - 8), nil |
| 429 | + return libpf.Address(data.Addr + uint64(offs) - 8), nil |
441 | 430 | } |
442 | 431 |
|
443 | 432 | // forEachItem walks the given struct reflection fields recursively, and calls the visitor |
|
0 commit comments