Changeset 12993
- Timestamp:
- 11/01/10 22:45:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/invokedynamic/abcl/src/org/armedbear/lisp/jvm-class-file.lisp
r12984 r12993 1018 1018 (code-labels code) labels) 1019 1019 (when compute-stack-map-table-p 1020 #+todo (code-add-attribute code stack-map-table)))) 1020 (code-add-attribute 1021 code 1022 (make-stack-map-table-attribute :entries stack-map-table))))) 1021 1023 1022 1024 (setf (code-exception-handlers code) … … 1095 1097 (defun resolve-code (code-attr code class method compute-stack-map-table-p) 1096 1098 "Walks the code, replacing symbolic labels with numeric offsets, and optionally computing the stack map table." 1097 (declare (ignore class))1098 1099 (let* ((length 0) 1099 1100 labels ;; alist … … 1124 1125 (progn 1125 1126 (when (= opcode 202) ;;label: simulate a jump 1126 (record-jump-to-label ( car(instruction-args instruction))))1127 (record-jump-to-label (first (instruction-args instruction)))) 1127 1128 (simulate-instruction-effect instruction) 1128 1129 ;;Simulation must be stopped if we encounter a goto, it will be … … 1140 1141 (acons label length labels))) 1141 1142 (incf length (opcode-size opcode))))) 1142 ;; Pass 2: replace labels with calculated offsets. 1143 ;;Pass 2 (optional): compute the stack map table 1144 (when compute-stack-map-table-p 1145 (let ((last-frame-offset 0) 1146 (must-emit-frame nil)) 1147 (dotimes (i (length code)) 1148 (let ((instruction (aref code i)) 1149 (make-variable-info (lambda (type) 1150 (smf-type->variable-info type class)))) 1151 (cond 1152 ((= (instruction-opcode instruction) 202) ; LABEL 1153 (let* ((label (car (instruction-args instruction))) 1154 (offset (symbol-value label)) 1155 (*print-circle* t)) 1156 (if (get label 'jump-target-p) 1157 (let ((frame 1158 (make-stack-map-full-frame 1159 :offset-delta (- offset last-frame-offset) 1160 :locals 1161 (mapcar make-variable-info 1162 (instruction-input-locals instruction)) 1163 :stack-items 1164 (mapcar make-variable-info 1165 (instruction-input-stack instruction))))) 1166 (push frame stack-map-table) 1167 (sys::%format t "emit frame ~S @ ~A (~A)~%" 1168 frame offset (- offset last-frame-offset)) 1169 (setf last-frame-offset offset)) 1170 (sys::%format t "error - label not target of a jump: ~S~%" label)) 1171 ))))))) 1172 ;;Pass 3: replace labels with calculated offsets. 1143 1173 (let ((index 0)) 1144 1174 (declare (type (unsigned-byte 16) index)) … … 1151 1181 (symbol-value (the symbol label))) 1152 1182 index))) 1153 (unless (get label 'jump-target-p)1154 (sys::%format "error - label not target of a jump ~S~%" label))1155 1183 (setf (instruction-args instruction) (s2 offset)))) 1156 1184 (unless (= (instruction-opcode instruction) 202) ; LABEL 1157 1185 (incf index (opcode-size (instruction-opcode instruction))))))) 1158 ;; Expand instructions into bytes, skipping LABEL pseudo-instructions. 1186 ;;Pass 4: expand instructions into bytes, 1187 ;;skipping LABEL pseudo-instructions. 1159 1188 (let ((bytes (make-array length)) 1160 1189 (index 0)) … … 1170 1199 (let ((idx (constant-index arg)) 1171 1200 (opcode (instruction-opcode instruction))) 1172 ;;(sys::%format t "constant ~A ~A index-size ~A index ~A~%" (type-of arg) idx (constant-index-size arg) index)1173 1201 (if (or (<= 178 opcode 187) 1174 1202 (= opcode 189) … … 1185 1213 (setf (svref bytes index) arg) 1186 1214 (incf index))))))) 1187 (sys::%format t "~%~%~%BYTES ~S~%~%~%" bytes) 1188 (values bytes labels stack-map-table)))) 1215 (values bytes labels (nreverse stack-map-table))))) 1189 1216 1190 1217 (defun unconditional-jump-p (opcode) … … 1402 1429 entries) 1403 1430 1404 (defun add-stack-map-frame (stack-map-table instruction-offset locals1405 stack-items)1406 (error "TODO!"))1407 1408 1431 (defun finalize-stack-map-table-attribute (table parent class) 1409 1432 "Prepares the `stack-map-table' attribute for serialization, within method `parent': replaces all virtual types in the stack map frames with variable-info objects." … … 1414 1437 (write-u2 (length (stack-map-table-entries table)) stream) 1415 1438 (dolist (frame (stack-map-table-entries table)) 1416 (funcall (frame-writer frame) stream)))1439 (funcall (frame-writer frame) frame stream))) 1417 1440 1418 1441 (defstruct (stack-map-frame (:conc-name frame-)) … … 1430 1453 (write-u1 255 stream) 1431 1454 (write-u2 (frame-offset-delta frame) stream) 1455 ;; (write-u2 0 stream) 1456 ;; (write-u2 0 stream) 1457 ;; (return-from write-stack-map-full-frame) 1432 1458 (write-u2 (length (full-frame-locals frame)) stream) 1433 1459 (dolist (local (full-frame-locals frame)) … … 1457 1483 (defun write-simple-verification-type-info (vti stream) 1458 1484 (write-u1 (verification-type-info-tag vti) stream)) 1459 (defun write-object-variable- type-info (vti stream)1485 (defun write-object-variable-info (vti stream) 1460 1486 (write-u1 (verification-type-info-tag vti) stream) 1461 1487 (write-u2 (object-variable-info-constant-pool-index vti) stream)) 1462 (defun write-uninitialized-v erification-type-info (vti stream)1488 (defun write-uninitialized-variable-info (vti stream) 1463 1489 (write-u1 (verification-type-info-tag vti) stream) 1464 1490 (write-u2 (uninitialized-variable-info-offset vti) stream)) … … 1476 1502 (nreverse locals))) 1477 1503 1478 (defun smf-type->variable-info (type) 1479 :todo) 1504 (defun smf-type->variable-info (type class) 1505 (cond 1506 ((eq type :this) 1507 (make-object-variable-info :constant-pool-index (class-file-class class))) 1508 ((eq type :int) (make-integer-variable-info)) 1509 ((typep type 'constant-class) 1510 (make-object-variable-info :constant-pool-index (constant-index type))) 1511 ((typep type 'class-name) 1512 (make-object-variable-info 1513 :constant-pool-index 1514 (constant-index (pool-add-class (class-file-constants class) type)))) 1515 (t (sys::%format t "Don't know how to translate type ~S~%" type) type))) 1480 1516 1481 1517 #|
Note: See TracChangeset
for help on using the changeset viewer.