簡體   English   中英

什么是jvm字節碼中的stackmap表?

[英]What is stackmap table in jvm bytecode?

我正在學習ASM庫來生成字節碼。 在某些時候我犯了一些錯誤的局部變量類型,並得到一個錯誤:

Exception in thread "main" java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    Loops.start()V @56: aload_1
  Reason:
    Type top (current frame, locals[1]) is not assignable to reference type


  Stackmap Table:
    full_frame(@24,{Object[#2],Object[#9]},{Integer})
    full_frame(@25,{Object[#2],Object[#9]},{Integer,Integer})
    same_locals_1_stack_item_frame(@44,Integer)
    full_frame(@45,{Object[#2],Object[#9]},{Integer,Integer})
    full_frame(@48,{Object[#2]},{Integer})
    full_frame(@80,{Object[#2],Integer},{Integer})
    full_frame(@81,{Object[#2],Integer},{Integer,Integer})
    full_frame(@87,{Object[#2]},{Integer})
    full_frame(@119,{Object[#2],Integer},{Integer})
    full_frame(@120,{Object[#2],Integer},{Integer,Integer})
    same_locals_1_stack_item_frame(@123,Integer)

問題並不難找到並修復,但我很好奇這個堆棧圖表是什么東西?

StackMapTable是使用Java 6或更高版本編譯的類中的屬性。 通過類型檢查進行驗證的過程中,JVM使用它。

基本上,堆棧映射幀定義了方法在執行期間的預期類型的​​局部變量和操作數堆棧(即幀的狀態)。 在運行時,如果預期和實際類型不兼容,JVM將拋出VerifyError

為了節省空間,並非每條指令都有相應的幀。 該表僅定義潛在跳轉目標或異常處理程序的幀。 其他框架可以從這些框架中輕松推斷出來。 您可以在上面的表中看到,幀僅針對某些字節碼偏移進行了定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM