You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/notes_on_jvm_anatomy.md
+155Lines changed: 155 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,161 @@ public class com/slateblua/bytecode/MyClass {
154
154
}
155
155
```
156
156
157
+
For a more "complex" example, let's create a toy-class InMemoryDataSource that extends AbstractDataSource
158
+
and implements the LocalDataSource interface.
159
+
160
+
```java
161
+
package com.slateblua.bytecode;
162
+
163
+
import java.util.List;
164
+
165
+
public class InMemoryDataSource extends AbstractDataSource implements LocalDataSource {
166
+
static {
167
+
System.out.println("In-memory data source first accessed");
168
+
}
169
+
170
+
@Override
171
+
public List<String> getAllRecords () {
172
+
return List.of("Record", "Another record");
173
+
}
174
+
175
+
@Override
176
+
public String getRecordById (int key) {
177
+
return "Record " + key;
178
+
}
179
+
180
+
@Override
181
+
public void addRecord (String record) {
182
+
System.out.println("Record added: " + record);
183
+
}
184
+
185
+
@Override
186
+
public void deleteRecord (int key) {
187
+
System.out.println("Record deleted: " + key);
188
+
}
189
+
}
190
+
```
191
+
192
+
The following bytecode is generated for the InMemoryDataSource class:
193
+
194
+
```java
195
+
// class version 62.0 (62)
196
+
// access flags 0x21
197
+
public class com/slateblua/bytecode/InMemoryDataSource extends com/slateblua/bytecode/AbstractDataSource implements com/slateblua/bytecode/LocalDataSource {
198
+
199
+
// compiled from: InMemoryDataSource.java
200
+
// access flags 0x19
201
+
public final static INNERCLASS java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles Lookup
The <clinit> (the static initializer) method is called only once for a class.
308
+
It is called before any other method of the class can be executed.
309
+
310
+
In contrast, the <init> method is called for every object creation. Here it initializes the <init> method of the super class and the references to the current object.
0 commit comments