How jvm covers all scenarios to avoid not giving away stored value in reference variable

In java, a reference variable contains object reference which is some kind of wrapper over raw addr or pointer or some sort of mapping and during dereferencing this mapping is used to navigate to the object’s location in heap.

To see stored value, we tried 2 examples: Print it and Access without printing

Printing:
This is basic, just printing using println method to see exact stored value (we can use some logging framework also), here the high level code calls toString indirectly somewhere due to this we are not able to just print the reference variable’s exact stored value, i.e. now obj.toString() is being called and our intention is to print(obj) alone. And this is reason which most give as to why you can’t print actual value stored in reference variable.

Accessing:
Here we are not printing reference variable value but we try to access just the reference variable (without any explicit dereferencing) like string concat using + operator:

String str = new String("Test String ");
String newStr = str + new Student();

If we check newStr:

Test String com.ex.objref.Student@3b07d329

Here also we are almost sure that toString is called during concat, so we checked in decompiled bytecode and found out that concat op + is replaced with this method:

18: invokedynamic #7,  0              // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;Student;)Ljava/lang/String;

BootstrapMethods:
  0: #26 REF_invokeStatic java/lang/invoke/StringConcatFactory.makeConcatWithConstants:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;

And that inside is calling toString().
In this example where we are just accessing the reference variable, for this specific example we can see that now the toString is called from low level code and that is not allowing only the reference value to be accessed.

I want to know:

  1. Is java abstracting or restricting to not see/print/access the actual value of reference variable by virtue of toString() as seen in above 2 usecases?
  2. Or there are some other checks which are placed in jvm or in bytecode instructions which ensure that if we are accessing/ printing any reference variable without any dereferencing on it, don’t allow it and instead do some sort of dereferencing on it?
  3. And some example of those checks like what all does jvm check like it checks if the value is primitive or non-primitive?

PS: I don’t want to understand everything like how it works but atleast
if I am thinking it in right direction, I just want to know
what all does jvm do to
restrict/abstract the reference variable value and not how it does.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật