Changeset 12953
- Timestamp:
- 10/06/10 22:03:56 (13 years ago)
- Location:
- branches/invokedynamic/abcl/src/org/armedbear/lisp
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/invokedynamic/abcl/src/org/armedbear/lisp/JavaClassLoader.java
r12802 r12953 118 118 return c; 119 119 } 120 } 121 catch (VerifyError e) 122 { 120 } catch (VerifyError e) { 123 121 error(new LispError("Class verification failed: " + e.getMessage())); 124 } 125 catch (Throwable t) { 122 } catch (Throwable t) { 123 Debug.trace("Classloading error for " + className); 126 124 Debug.trace(t); 125 LispThread.currentThread().printBacktrace(); 126 Debug.trace("Classloading error for " + className); 127 127 } 128 128 return null; -
branches/invokedynamic/abcl/src/org/armedbear/lisp/Main.java
r12921 r12953 41 41 public static final long startTimeMillis = System.currentTimeMillis(); 42 42 43 static { Linkage.registerBootstrapMethod(Function.class, "linkLispFunction"); }43 // static { Linkage.registerBootstrapMethod(Function.class, "linkLispFunction"); } 44 44 45 45 public static void main(final String[] args) … … 57 57 }; 58 58 new Thread(null, r, "interpreter", 4194304L).start(); 59 try {59 /*try { 60 60 for(int i = 0; i < 2; i++) { 61 61 Thread.sleep(5000); 62 62 InvokeDynamic.<LispObject>#"COMMON-LISP:PRINT"((LispObject) new SimpleString("foo")); 63 63 InvokeDynamic.<LispObject>#"COMMON-LISP:PRINT"((LispObject) new SimpleString("bar")); 64 InvokeDynamic.<LispObject>#"CL-USER::FOO"((LispObject) new SimpleString("baz"));64 // InvokeDynamic.<LispObject>#"CL-USER::FOO"((LispObject) new SimpleString("baz")); 65 65 } 66 66 } catch(Throwable t) { 67 67 t.printStackTrace(); 68 }68 }*/ 69 69 //java.dyn.InvokeDynamic.foo(new SimpleString("foo")); 70 70 } -
branches/invokedynamic/abcl/src/org/armedbear/lisp/compile-system.lisp
r12918 r12953 271 271 272 272 (defun compile-system (&key quit (zip t) output-path) 273 (let ((status -1)) 274 (check-lisp-home) 275 (time 276 (with-compilation-unit () 277 (let ((*compile-file-zip* zip) 278 failure-p) 279 (handler-bind (((or warning 280 compiler-error) 281 #'(lambda (c) 282 (declare (ignore c)) 283 (setf failure-p t) 284 ;; only register that we had this type of signal 285 ;; defer the actual handling to another handler 286 nil))) 287 (%compile-system :output-path output-path)) 288 (unless failure-p 289 (setf status 0))))) 290 (create-system-logical-translations output-path) 273 (let ((status -1) failure) 274 (handler-bind ((error #'(lambda (c) 275 (declare (ignore c)) 276 (let ((*print-circle* t)) 277 (pprint (sys::backtrace-as-list))) 278 nil))) 279 (check-lisp-home) 280 (time 281 (with-compilation-unit () 282 (let ((*compile-file-zip* zip)) 283 (handler-bind (((or warning 284 compiler-error) 285 #'(lambda (c) 286 (setf failure c) 287 ;; only register that we had this type of signal 288 ;; defer the actual handling to another handler 289 nil))) 290 (%compile-system :output-path output-path)) 291 (unless failure 292 (setf status 0))))) 293 (create-system-logical-translations output-path)) 294 (when failure 295 (format t "Failure: ~A~%" failure)) 291 296 (when quit 292 297 (quit :status status)))) -
branches/invokedynamic/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r12918 r12953 205 205 (defun emit-invokestatic (class-name method-name arg-types return-type) 206 206 (let* ((stack-effect (apply #'descriptor-stack-effect return-type arg-types)) 207 (index (pool-add-method-ref *pool* class-name 208 method-name (cons return-type arg-types))) 207 (index (constant-index (pool-add-method-ref 208 *pool* class-name 209 method-name (cons return-type arg-types)))) 209 210 (instruction (apply #'%emit 'invokestatic (u2 index)))) 210 211 (setf (instruction-stack instruction) stack-effect))) … … 226 227 (defun emit-invokevirtual (class-name method-name arg-types return-type) 227 228 (let* ((stack-effect (apply #'descriptor-stack-effect return-type arg-types)) 228 (index (pool-add-method-ref *pool* class-name 229 method-name (cons return-type arg-types))) 229 (index (constant-index (pool-add-method-ref 230 *pool* class-name 231 method-name (cons return-type arg-types)))) 230 232 (instruction (apply #'%emit 'invokevirtual (u2 index)))) 231 233 (declare (type (signed-byte 8) stack-effect)) … … 243 245 (defun emit-invokespecial-init (class-name arg-types) 244 246 (let* ((stack-effect (apply #'descriptor-stack-effect :void arg-types)) 245 (index (pool-add-method-ref *pool* class-name 246 "<init>" (cons nil arg-types))) 247 (index (constant-index (pool-add-method-ref 248 *pool* class-name 249 "<init>" (cons nil arg-types)))) 247 250 (instruction (apply #'%emit 'invokespecial (u2 index)))) 248 251 (declare (type (signed-byte 8) stack-effect)) … … 284 287 (defknown emit-getstatic (t t t) t) 285 288 (defun emit-getstatic (class-name field-name type) 286 (let (( index(pool-add-field-ref *pool* class-name field-name type)))287 (apply #'%emit 'getstatic (u2 index))))289 (let ((ref (pool-add-field-ref *pool* class-name field-name type))) 290 (apply #'%emit 'getstatic (u2 (constant-index ref))))) 288 291 289 292 (defknown emit-putstatic (t t t) t) 290 293 (defun emit-putstatic (class-name field-name type) 291 (let (( index(pool-add-field-ref *pool* class-name field-name type)))292 (apply #'%emit 'putstatic (u2 index))))294 (let ((ref (pool-add-field-ref *pool* class-name field-name type))) 295 (apply #'%emit 'putstatic (u2 (constant-index ref))))) 293 296 294 297 (declaim (inline emit-getfield emit-putfield)) 295 298 (defknown emit-getfield (t t t) t) 296 299 (defun emit-getfield (class-name field-name type) 297 (let* (( index(pool-add-field-ref *pool* class-name field-name type)))298 (apply #'%emit 'getfield (u2 index))))300 (let* ((ref (pool-add-field-ref *pool* class-name field-name type))) 301 (apply #'%emit 'getfield (u2 (constant-index ref))))) 299 302 300 303 (defknown emit-putfield (t t t) t) 301 304 (defun emit-putfield (class-name field-name type) 302 (let* (( index(pool-add-field-ref *pool* class-name field-name type)))303 (apply #'%emit 'putfield (u2 index))))305 (let* ((ref (pool-add-field-ref *pool* class-name field-name type))) 306 (apply #'%emit 'putfield (u2 (constant-index ref))))) 304 307 305 308 … … 307 310 (declaim (inline emit-new emit-anewarray emit-checkcast emit-instanceof)) 308 311 (defun emit-new (class-name) 309 (apply #'%emit 'new (u2 ( pool-class class-name))))312 (apply #'%emit 'new (u2 (constant-index (pool-class class-name))))) 310 313 311 314 (defknown emit-anewarray (t) t) 312 315 (defun emit-anewarray (class-name) 313 (apply #'%emit 'anewarray (u2 ( pool-class class-name))))316 (apply #'%emit 'anewarray (u2 (constant-index (pool-class class-name))))) 314 317 315 318 (defknown emit-checkcast (t) t) 316 319 (defun emit-checkcast (class-name) 317 (apply #'%emit 'checkcast (u2 ( pool-class class-name))))320 (apply #'%emit 'checkcast (u2 (constant-index (pool-class class-name))))) 318 321 319 322 (defknown emit-instanceof (t) t) 320 323 (defun emit-instanceof (class-name) 321 (apply #'%emit 'instanceof (u2 ( pool-class class-name))))324 (apply #'%emit 'instanceof (u2 (constant-index (pool-class class-name))))) 322 325 323 326 … … 908 911 909 912 913 (defun make-static-initializer () 914 (let* ((*compiler-debug* nil) 915 ;; We don't normally need to see debugging output for <clinit>. 916 (method (make-method :static-initializer 917 :void nil :flags '(:public :static))) 918 (code (method-add-code method)) 919 (*code* ()) 920 (*current-code-attribute* code)) 921 (setf (code-max-locals code) 1) 922 (emit 'ldc (pool-class +lisp-function+)) 923 (emit 'ldc (pool-string "linkLispFunction")) 924 (emit-invokestatic +dyn-linkage+ "registerBootstrapMethod" 925 (list +java-class+ +java-string+) :void) 926 ;(setf *code* (append *static-code* *code*)) 927 (emit 'return) 928 (setf (code-code code) *code*) 929 method)) 930 910 931 (defvar *source-line-number* nil) 911 932 … … 919 940 (abcl-class-file-lambda-name class) 920 941 (abcl-class-file-lambda-list class))) 942 (class-add-method class (make-static-initializer)) 921 943 (finalize-class-file class) 922 944 (write-class-file class stream)) 923 924 945 925 946 (defknown declare-field (t t t) t) -
branches/invokedynamic/abcl/src/org/armedbear/lisp/jvm-class-file.lisp
r12918 r12953 134 134 (define-class-name +java-string+ "java.lang.String") 135 135 (define-class-name +java-system+ "java.lang.System") 136 (define-class-name +java-class+ "java.lang.Class") 136 137 (define-class-name +lisp-object+ "org.armedbear.lisp.LispObject") 138 (define-class-name +dyn-linkage+ "java.dyn.Linkage") 139 (define-class-name +dyn-invokedynamic+ "java.dyn.InvokeDynamic") 137 140 (defconstant +lisp-object-array+ (class-array +lisp-object+)) 138 141 (define-class-name +lisp-simple-string+ "org.armedbear.lisp.SimpleString") … … 168 171 (define-class-name +lisp-go+ "org.armedbear.lisp.Go") 169 172 (define-class-name +lisp-primitive+ "org.armedbear.lisp.Primitive") 173 (define-class-name +lisp-function+ "org.armedbear.lisp.Function") 170 174 (define-class-name +lisp-eql-hash-table+ "org.armedbear.lisp.EqlHashTable") 171 175 (define-class-name +lisp-hash-table+ "org.armedbear.lisp.HashTable") … … 277 281 (:utf8 1 1))) 278 282 283 (defun constant-type (constant) 284 (car (find (constant-tag constant) +constant-type-map+ :key #'cadr))) 285 279 286 (defstruct (constant-class (:constructor make-constant-class (index name-index)) 280 287 (:include constant … … 368 375 369 376 (defun pool-add-class (pool class) 370 "Returns the index of theconstant-pool class item for `class'.377 "Returns the constant-pool class item for `class'. 371 378 372 379 `class' must be an instance of `class-name'." 373 380 (let ((entry (gethash class (pool-entries pool)))) 374 381 (unless entry 375 (let ((utf8 ( pool-add-utf8 pool (class-name-internal class))))382 (let ((utf8 (constant-index (pool-add-utf8 pool (class-name-internal class))))) 376 383 (setf entry 377 384 (make-constant-class (incf (pool-index pool)) utf8) 378 385 (gethash class (pool-entries pool)) entry)) 379 386 (push entry (pool-entries-list pool))) 380 (constant-index entry)))387 entry)) 381 388 382 389 (defun pool-add-field-ref (pool class name type) 383 "Returns the index of theconstant-pool item which denotes a reference390 "Returns the constant-pool item which denotes a reference 384 391 to the `name' field of the `class', being of `type'. 385 392 … … 389 396 (let ((entry (gethash (acons name type class) (pool-entries pool)))) 390 397 (unless entry 391 (let ((c ( pool-add-class pool class))392 (n/t ( pool-add-name/type pool name type)))398 (let ((c (constant-index (pool-add-class pool class))) 399 (n/t (constant-index (pool-add-name/type pool name type)))) 393 400 (setf entry (make-constant-field-ref (incf (pool-index pool)) c n/t) 394 401 (gethash (acons name type class) (pool-entries pool)) entry)) 395 402 (push entry (pool-entries-list pool))) 396 (constant-index entry)))403 entry)) 397 404 398 405 (defun pool-add-method-ref (pool class name type) 399 "Returns the index of theconstant-pool item which denotes a reference406 "Returns the constant-pool item which denotes a reference 400 407 to the method with `name' in `class', which is of `type'. 401 408 … … 404 411 (let ((entry (gethash (acons name type class) (pool-entries pool)))) 405 412 (unless entry 406 (let ((c ( pool-add-class pool class))407 (n/t ( pool-add-name/type pool name type)))413 (let ((c (constant-index (pool-add-class pool class))) 414 (n/t (constant-index (pool-add-name/type pool name type)))) 408 415 (setf entry (make-constant-method-ref (incf (pool-index pool)) c n/t) 409 416 (gethash (acons name type class) (pool-entries pool)) entry)) 410 417 (push entry (pool-entries-list pool))) 411 (constant-index entry)))418 entry)) 412 419 413 420 (defun pool-add-interface-method-ref (pool class name type) 414 "Returns the index of theconstant-pool item which denotes a reference to421 "Returns the constant-pool item which denotes a reference to 415 422 the method `name' in the interface `class', which is of `type'. 416 423 … … 418 425 (let ((entry (gethash (acons name type class) (pool-entries pool)))) 419 426 (unless entry 420 (let ((c ( pool-add-class pool class))421 (n/t ( pool-add-name/type pool name type)))427 (let ((c (constant-index (pool-add-class pool class))) 428 (n/t (constant-index (pool-add-name/type pool name type)))) 422 429 (setf entry 423 430 (make-constant-interface-method-ref (incf (pool-index pool)) c n/t) 424 431 (gethash (acons name type class) (pool-entries pool)) entry)) 425 432 (push entry (pool-entries-list pool))) 426 (constant-index entry)))433 entry)) 427 434 428 435 (defun pool-add-string (pool string) 429 "Returns the index of theconstant-pool item denoting the string."436 "Returns the constant-pool item denoting the string." 430 437 (let ((entry (gethash (cons 8 string) ;; 8 == string-tag 431 438 (pool-entries pool)))) 432 439 (unless entry 433 440 (let ((utf8 (pool-add-utf8 pool string))) 434 (setf entry (make-constant-string (incf (pool-index pool)) utf8) 441 (setf entry (make-constant-string (incf (pool-index pool)) 442 (constant-index utf8)) 435 443 (gethash (cons 8 string) (pool-entries pool)) entry)) 436 444 (push entry (pool-entries-list pool))) 437 (constant-index entry)))445 entry)) 438 446 439 447 (defun pool-add-int (pool int) 440 "Returns the index of theconstant-pool item denoting the int."448 "Returns the constant-pool item denoting the int." 441 449 (let ((entry (gethash (cons 3 int) (pool-entries pool)))) 442 450 (unless entry … … 444 452 (gethash (cons 3 int) (pool-entries pool)) entry) 445 453 (push entry (pool-entries-list pool))) 446 (constant-index entry)))454 entry)) 447 455 448 456 (defun pool-add-float (pool float) 449 "Returns the index of theconstant-pool item denoting the float."457 "Returns the constant-pool item denoting the float." 450 458 (let ((entry (gethash (cons 4 float) (pool-entries pool)))) 451 459 (unless entry … … 454 462 (gethash (cons 4 float) (pool-entries pool)) entry) 455 463 (push entry (pool-entries-list pool))) 456 (constant-index entry)))464 entry)) 457 465 458 466 (defun pool-add-long (pool long) 459 "Returns the index of theconstant-pool item denoting the long."467 "Returns the constant-pool item denoting the long." 460 468 (let ((entry (gethash (cons 5 long) (pool-entries pool)))) 461 469 (unless entry … … 464 472 (push entry (pool-entries-list pool)) 465 473 (incf (pool-index pool))) ;; double index increase; long takes 2 slots 466 (constant-index entry)))474 entry)) 467 475 468 476 (defun pool-add-double (pool double) 469 "Returns the index of theconstant-pool item denoting the double."477 "Returns constant-pool item denoting the double." 470 478 (let ((entry (gethash (cons 6 double) (pool-entries pool)))) 471 479 (unless entry … … 475 483 (push entry (pool-entries-list pool)) 476 484 (incf (pool-index pool))) ;; double index increase; 'double' takes 2 slots 477 (constant-index entry)))485 entry)) 478 486 479 487 (defun pool-add-name/type (pool name type) 480 "Returns the index of the constant-pool item denoting 481 the name/type identifier." 488 "Returns the constant-pool item denoting the name/type identifier." 482 489 (let ((entry (gethash (cons name type) (pool-entries pool))) 483 490 (internal-type (if (listp type) … … 485 492 (internal-field-ref type)))) 486 493 (unless entry 487 (let ((n ( pool-add-utf8 pool name))488 (i-t ( pool-add-utf8 pool internal-type)))494 (let ((n (constant-index (pool-add-utf8 pool name))) 495 (i-t (constant-index (pool-add-utf8 pool internal-type)))) 489 496 (setf entry (make-constant-name/type (incf (pool-index pool)) n i-t) 490 497 (gethash (cons name type) (pool-entries pool)) entry)) 491 498 (push entry (pool-entries-list pool))) 492 (constant-index entry)))499 entry)) 493 500 494 501 (defun pool-add-utf8 (pool utf8-as-string) 495 "Returns the index of the textual value that will be stored in the 496 class file as UTF-8 encoded data." 502 "Returns the textual value that will be stored in the class file as UTF-8 encoded data." 497 503 (let ((entry (gethash (cons 11 utf8-as-string) ;; 11 == utf8 498 504 (pool-entries pool)))) … … 501 507 (gethash (cons 11 utf8-as-string) (pool-entries pool)) entry) 502 508 (push entry (pool-entries-list pool))) 503 (constant-index entry)))509 entry)) 504 510 505 511 (defstruct (class-file (:constructor … … 507 513 "Holds the components of a class file." 508 514 (constants (make-pool)) 515 (major-version 51) 516 (minor-version 0) 509 517 access-flags 510 518 class … … 568 576 (map-flags (class-file-access-flags class))) 569 577 (setf (class-file-superclass class) 570 ( pool-add-class (class-file-constants class)571 (class-file-superclass class))578 (constant-index (pool-add-class (class-file-constants class) 579 (class-file-superclass class))) 572 580 (class-file-class class) 573 ( pool-add-class (class-file-constants class)574 (class-file-class class)))581 (constant-index (pool-add-class (class-file-constants class) 582 (class-file-class class)))) 575 583 ;; (finalize-interfaces) 576 584 (dolist (field (class-file-fields class)) … … 668 676 ;; header 669 677 (write-u4 #xCAFEBABE stream) 670 (write-u2 3stream)671 (write-u2 45stream)678 (write-u2 (class-file-minor-version class) stream) 679 (write-u2 (class-file-major-version class) stream) 672 680 673 681 ;; constants pool … … 821 829 (map-flags (field-access-flags field)) 822 830 (field-descriptor field) 823 ( pool-add-utf8 pool (internal-field-ref (field-descriptor field)))831 (constant-index (pool-add-utf8 pool (internal-field-ref (field-descriptor field)))) 824 832 (field-name field) 825 ( pool-add-utf8 pool (field-name field))))833 (constant-index (pool-add-utf8 pool (field-name field))))) 826 834 (finalize-attributes (field-attributes field) nil class)) 827 835 … … 898 906 (map-flags (method-access-flags method)) 899 907 (method-descriptor method) 900 ( pool-add-utf8 pool (apply #'descriptor (method-descriptor method)))908 (constant-index (pool-add-utf8 pool (apply #'descriptor (method-descriptor method)))) 901 909 (method-name method) 902 ( pool-add-utf8 pool (method-name method))))910 (constant-index (pool-add-utf8 pool (method-name method))))) 903 911 (finalize-attributes (method-attributes method) nil class)) 904 912 … … 930 938 ;; assure header: make sure 'name' is in the pool 931 939 (setf (attribute-name attribute) 932 ( pool-add-utf8 (class-file-constants class)933 (attribute-name attribute)))940 (constant-index (pool-add-utf8 (class-file-constants class) 941 (attribute-name attribute)))) 934 942 ;; we're saving "root" attributes: attributes which have no parent 935 943 (funcall (attribute-finalizer attribute) attribute att class))) … … 969 977 labels ;; an alist 970 978 971 (current-local 0)) ;; used for handling nested WITH-CODE-TO-METHOD blocks 979 ;; these two are used for handling nested WITH-CODE-TO-METHOD blocks 980 (current-local 0) 981 stack-map-frames) 972 982 973 983 … … 986 996 (defun finalize-code-attribute (code parent class) 987 997 "Prepares the `code' attribute for serialization, within method `parent'." 988 (declare (ignore parent))989 998 (let* ((handlers (code-exception-handlers code)) 990 999 (c (finalize-code … … 1000 1009 (setf (code-max-locals code) 1001 1010 (analyze-locals code))) 1011 (when (>= (class-file-major-version class) 50) 1012 (code-add-attribute code (compute-stack-map-table class parent))) 1002 1013 (multiple-value-bind 1003 1014 (c labels) … … 1022 1033 (if (null (exception-catch-type exception)) 1023 1034 0 ;; generic 'catch all' class index number 1024 ( pool-add-class (class-file-constants class)1025 (exception-catch-type exception)))))1035 (constant-index (pool-add-class (class-file-constants class) 1036 (exception-catch-type exception)))))) 1026 1037 1027 1038 (finalize-attributes (code-attributes code) code class)) … … 1118 1129 (setf (checked-table checked-exceptions) 1119 1130 (mapcar #'(lambda (exception) 1120 ( pool-add-class (class-file-constants class)1121 exception))1131 (constant-index (pool-add-class (class-file-constants class) 1132 exception))) 1122 1133 (checked-table checked-exceptions)))) 1123 1134 … … 1183 1194 (declare (ignorable code class)) 1184 1195 (setf (source-filename source-file) 1185 ( pool-add-utf8 (class-file-constants class)1186 (source-filename source-file))))1196 (constant-index (pool-add-utf8 (class-file-constants class) 1197 (source-filename source-file))))) 1187 1198 1188 1199 (defun write-source-file (source-file stream) … … 1259 1270 (local-start-pc local-variable)) 1260 1271 (local-name local-variable) 1261 ( pool-add-utf8 (class-file-constants class)1262 (local-name local-variable))1272 (constant-index (pool-add-utf8 (class-file-constants class) 1273 (local-name local-variable))) 1263 1274 (local-descriptor local-variable) 1264 ( pool-add-utf8 (class-file-constants class)1265 (local-descriptor local-variable)))))1275 (constant-index (pool-add-utf8 (class-file-constants class) 1276 (local-descriptor local-variable)))))) 1266 1277 1267 1278 (defun write-local-variables (local-variables stream) … … 1274 1285 (write-u2 (local-index local-variable) stream))) 1275 1286 1287 ;;Support for the StackMapTable attribute used by the typechecking verifier 1288 ;;from class file version number 50.0 onward (astalla) 1289 1290 (defstruct (stack-map-table-attribute 1291 (:conc-name stack-map-table-) 1292 (:include attribute 1293 (name "StackMapTable") 1294 (finalizer #'finalize-stack-map-table-attribute) 1295 (writer #'write-stack-map-table-attribute))) 1296 ;(:constructor %make-stack-map-table-attribute)) 1297 "The attribute containing the stack map table, a map from bytecode offsets to frames containing information about the types of locals and values on the operand stack at that offset. This is an attribute of a method." 1298 entries) 1299 1300 (defun finalize-stack-map-table-attribute (table parent class) 1301 "Prepares the `stack-map-table' attribute for serialization, within method `parent'." 1302 (declare (ignore parent class)) ;;TODO 1303 table) 1304 1305 (defun write-stack-map-table-attribute (table stream) 1306 (write-u2 (length (stack-map-table-entries table)) stream) 1307 (dolist (frame (stack-map-table-entries table)) 1308 (funcall (frame-writer frame) stream))) 1309 1310 (defstruct (stack-map-frame (:conc-name frame-)) 1311 offset-delta 1312 writer) 1313 1314 (defstruct (stack-map-full-frame 1315 (:conc-name full-frame-) 1316 (:include stack-map-frame 1317 (writer #'write-stack-map-full-frame))) 1318 locals 1319 stack-items) 1320 1321 (defun write-stack-map-full-frame (frame stream) 1322 (write-u1 255 stream) 1323 (write-u2 (frame-offset-delta frame) stream) 1324 (write-u2 (length (full-frame-locals frame)) stream) 1325 (dolist (local (full-frame-locals frame)) 1326 (funcall (verification-type-info-writer local) local stream)) 1327 (write-u2 (length (full-frame-stack-items frame)) stream) 1328 (dolist (stack-item (full-frame-stack-items frame)) 1329 (funcall (verification-type-info-writer stack-item) stack-item stream))) 1330 1331 (defstruct verification-type-info tag (writer #'write-simple-verification-type-info)) 1332 1333 (defstruct (top-variable-info (:include verification-type-info (tag 0)))) 1334 (defstruct (integer-variable-info (:include verification-type-info (tag 1)))) 1335 (defstruct (float-variable-info (:include verification-type-info (tag 2)))) 1336 (defstruct (double-variable-info (:include verification-type-info (tag 3)))) 1337 (defstruct (long-variable-info (:include verification-type-info (tag 4)))) 1338 (defstruct (null-variable-info (:include verification-type-info (tag 5)))) 1339 (defstruct (uninitialized-this-variable-info (:include verification-type-info (tag 6)))) 1340 (defstruct (object-variable-info 1341 (:include verification-type-info 1342 (tag 7) (writer #'write-object-variable-info))) 1343 constant-pool-index) 1344 (defstruct (uninitialized-variable-info 1345 (:include verification-type-info 1346 (tag 8) (writer #'write-unitialized-variable-info))) 1347 offset) 1348 1349 (defun write-simple-verification-type-info (vti stream) 1350 (write-u1 (verification-type-info-tag vti) stream)) 1351 (defun write-object-variable-type-info (vti stream) 1352 (write-u1 (verification-type-info-tag vti) stream) 1353 (write-u2 (object-variable-info-constant-pool-index vti) stream)) 1354 (defun write-uninitialized-verification-type-info (vti stream) 1355 (write-u1 (verification-type-info-tag vti) stream) 1356 (write-u2 (uninitialized-variable-info-offset vti) stream)) 1357 1358 (defconst *opcode-effect-table* 1359 (make-array 256 :initial-element #'(lambda (a b) (declare (ignore b)) a))) 1360 1361 (defun opcode-effect-function (opcode) 1362 (svref *opcode-effect-table* opcode)) 1363 1364 (defvar *computed-stack* nil "The list of types on the stack calculated from the last emitted instruction, or from the method signature if no instruction has been emitted yet for the current method.") 1365 1366 (defvar *computed-locals* nil "The list of types of local variables calculated from the last emitted instruction, or from the method signature if no instruction has been emitted yet for the current method.") 1367 1368 (defmacro define-opcode-effect (opcode &body body) 1369 `(setf (svref *opcode-effect-table* 1370 (opcode-number ',opcode)) 1371 #'(lambda (instruction) 1372 (declare (ignorable instruction)) 1373 ,@body))) 1374 1375 (defun update-stack-map-effect! (*computed-stack* *computed-locals* instruction) 1376 (funcall (opcode-effect-function (instruction-opcode instruction)) 1377 instruction) 1378 (setf (instruction-stack-map-locals instruction) *computed-locals*) 1379 (setf (instruction-stack-map-stack instruction) *computed-stack*) 1380 instruction) 1381 1382 (defun compute-stack-map-table (class method) 1383 (let ((table (make-stack-map-table-attribute)) 1384 (*computed-stack* (compute-initial-method-stack class method)) 1385 (*computed-locals*)) 1386 (finalize-stack-map-table table))) 1387 1388 (defun finalize-stack-map-table (table) 1389 "Replaces all virtual types in the stack map frames with variable-info objects." 1390 ;;TODO 1391 table) 1392 1393 (defun compute-initial-method-stack (class method) 1394 (let (locals) 1395 (unless (member :static (method-access-flags method)) 1396 (if (string= "<init>" (method-name method)) 1397 ;;the method is a constructor. 1398 (push :uninitialized-this locals) 1399 ;;the method is an instance method. 1400 (push (class-name class) locals))) 1401 (dolist (x (cdr (method-descriptor method))) 1402 (push x locals)) 1403 locals)) 1404 1405 (defun smf-type->variable-info (type) 1406 (case type)) 1407 1408 (defun smf-push (type) 1409 (push type *computed-stack*)) 1410 1411 (defun smf-push2 (type) 1412 (smf-push type) 1413 (smf-push :top)) 1414 1415 (defun smf-pop () 1416 (pop *computed-stack*)) 1417 1418 (defun smf-popn (n) 1419 (dotimes (i n) 1420 (pop *computed-stack*))) 1421 1422 (defun smf-element-of (type) 1423 (if (consp type) 1424 (cdr type) 1425 (error "Not an array stack map type: ~S" type))) 1426 1427 (defun smf-array-of (type) 1428 (cons :array-of type)) 1429 1430 (define-opcode-effect aconst_null (smf-push :null)) 1431 (define-opcode-effect iconst_m1 (smf-push :int)) 1432 (define-opcode-effect iconst_0 (smf-push :int)) 1433 (define-opcode-effect iconst_1 (smf-push :int)) 1434 (define-opcode-effect iconst_2 (smf-push :int)) 1435 (define-opcode-effect iconst_3 (smf-push :int)) 1436 (define-opcode-effect iconst_4 (smf-push :int)) 1437 (define-opcode-effect iconst_5 (smf-push :int)) 1438 (define-opcode-effect lconst_0 (smf-push2 :long)) 1439 (define-opcode-effect lconst_1 (smf-push2 :long)) 1440 (define-opcode-effect fconst_0 (smf-push :float)) 1441 (define-opcode-effect fconst_1 (smf-push :float)) 1442 (define-opcode-effect fconst_2 (smf-push :float)) 1443 (define-opcode-effect dconst_0 (smf-push2 :double)) 1444 (define-opcode-effect dconst_1 (smf-push2 :double)) 1445 (define-opcode-effect bipush (smf-push :int)) 1446 (define-opcode-effect sipush (smf-push :int)) 1447 (define-opcode-effect ldc 1448 (case (constant-type (car (instruction-args instruction))) 1449 (:int (smf-push :int)) 1450 (:long (smf-push2 :long)) 1451 (:float (smf-push :float)) 1452 (:double (smf-push2 :double)) 1453 (t (smf-push (car (instruction-args instruction)))))) 1454 (define-opcode-effect iload (smf-push :int)) 1455 (define-opcode-effect lload (smf-push2 :long)) 1456 (define-opcode-effect fload (smf-push :float)) 1457 (define-opcode-effect dload (smf-push2 :double)) 1458 #|(define-opcode aload 25 2 1) ;;TODO 1459 (define-opcode iload_0 26 1 1) 1460 (define-opcode iload_1 27 1 1) 1461 (define-opcode iload_2 28 1 1) 1462 (define-opcode iload_3 29 1 1) 1463 (define-opcode lload_0 30 1 2) 1464 (define-opcode lload_1 31 1 2) 1465 (define-opcode lload_2 32 1 2) 1466 (define-opcode lload_3 33 1 2) 1467 (define-opcode fload_0 34 1 nil) 1468 (define-opcode fload_1 35 1 nil) 1469 (define-opcode fload_2 36 1 nil) 1470 (define-opcode fload_3 37 1 nil) 1471 (define-opcode dload_0 38 1 nil) 1472 (define-opcode dload_1 39 1 nil) 1473 (define-opcode dload_2 40 1 nil) 1474 (define-opcode dload_3 41 1 nil) 1475 (define-opcode aload_0 42 1 1) 1476 (define-opcode aload_1 43 1 1) 1477 (define-opcode aload_2 44 1 1) 1478 (define-opcode aload_3 45 1 1)|# 1479 (define-opcode-effect iaload (smf-popn 2) (smf-push :int)) 1480 (define-opcode-effect laload (smf-popn 2) (smf-push2 :long)) 1481 (define-opcode-effect faload (smf-popn 2) (smf-push :float)) 1482 (define-opcode-effect daload (smf-popn 2) (smf-push2 :double)) 1483 #+nil ;;until there's newarray 1484 (define-opcode-effect aaload 1485 (progn 1486 (smf-pop) 1487 (smf-push (smf-element-of (smf-pop))))) 1488 (define-opcode-effect baload (smf-popn 2) (smf-push :int)) 1489 (define-opcode-effect caload (smf-popn 2) (smf-push :int)) 1490 (define-opcode-effect saload (smf-popn 2) (smf-push :int)) 1491 #|(define-opcode istore 54 2 -1) 1492 (define-opcode lstore 55 2 -2) 1493 (define-opcode fstore 56 2 nil) 1494 (define-opcode dstore 57 2 nil) 1495 (define-opcode astore 58 2 -1) 1496 (define-opcode istore_0 59 1 -1) 1497 (define-opcode istore_1 60 1 -1) 1498 (define-opcode istore_2 61 1 -1) 1499 (define-opcode istore_3 62 1 -1) 1500 (define-opcode lstore_0 63 1 -2) 1501 (define-opcode lstore_1 64 1 -2) 1502 (define-opcode lstore_2 65 1 -2) 1503 (define-opcode lstore_3 66 1 -2) 1504 (define-opcode fstore_0 67 1 nil) 1505 (define-opcode fstore_1 68 1 nil) 1506 (define-opcode fstore_2 69 1 nil) 1507 (define-opcode fstore_3 70 1 nil) 1508 (define-opcode dstore_0 71 1 nil) 1509 (define-opcode dstore_1 72 1 nil) 1510 (define-opcode dstore_2 73 1 nil) 1511 (define-opcode dstore_3 74 1 nil) 1512 (define-opcode astore_0 75 1 -1) 1513 (define-opcode astore_1 76 1 -1) 1514 (define-opcode astore_2 77 1 -1) 1515 (define-opcode astore_3 78 1 -1) 1516 (define-opcode iastore 79 1 -3) 1517 (define-opcode lastore 80 1 -4) 1518 (define-opcode fastore 81 1 -3) 1519 (define-opcode dastore 82 1 -4) 1520 (define-opcode aastore 83 1 -3) 1521 (define-opcode bastore 84 1 nil) 1522 (define-opcode castore 85 1 nil) 1523 (define-opcode sastore 86 1 nil) 1524 (define-opcode pop 87 1 -1) 1525 (define-opcode pop2 88 1 -2) 1526 (define-opcode dup 89 1 1) 1527 (define-opcode dup_x1 90 1 1) 1528 (define-opcode dup_x2 91 1 1) 1529 (define-opcode dup2 92 1 2) 1530 (define-opcode dup2_x1 93 1 2) 1531 (define-opcode dup2_x2 94 1 2) 1532 (define-opcode swap 95 1 0) 1533 (define-opcode iadd 96 1 -1) 1534 (define-opcode ladd 97 1 -2) 1535 (define-opcode fadd 98 1 -1) 1536 (define-opcode dadd 99 1 -2) 1537 (define-opcode isub 100 1 -1) 1538 (define-opcode lsub 101 1 -2) 1539 (define-opcode fsub 102 1 -1) 1540 (define-opcode dsub 103 1 -2) 1541 (define-opcode imul 104 1 -1) 1542 (define-opcode lmul 105 1 -2) 1543 (define-opcode fmul 106 1 -1) 1544 (define-opcode dmul 107 1 -2) 1545 (define-opcode idiv 108 1 nil) 1546 (define-opcode ldiv 109 1 nil) 1547 (define-opcode fdiv 110 1 nil) 1548 (define-opcode ddiv 111 1 nil) 1549 (define-opcode irem 112 1 nil) 1550 (define-opcode lrem 113 1 nil) 1551 (define-opcode frem 114 1 nil) 1552 (define-opcode drem 115 1 nil) 1553 (define-opcode ineg 116 1 0) 1554 (define-opcode lneg 117 1 0) 1555 (define-opcode fneg 118 1 0) 1556 (define-opcode dneg 119 1 0) 1557 (define-opcode ishl 120 1 -1) 1558 (define-opcode lshl 121 1 -1) 1559 (define-opcode ishr 122 1 -1) 1560 (define-opcode lshr 123 1 -1) 1561 (define-opcode iushr 124 1 nil) 1562 (define-opcode lushr 125 1 nil) 1563 (define-opcode iand 126 1 -1) 1564 (define-opcode land 127 1 -2) 1565 (define-opcode ior 128 1 -1) 1566 (define-opcode lor 129 1 -2) 1567 (define-opcode ixor 130 1 -1) 1568 (define-opcode lxor 131 1 -2) 1569 (define-opcode iinc 132 3 0) 1570 (define-opcode i2l 133 1 1) 1571 (define-opcode i2f 134 1 0) 1572 (define-opcode i2d 135 1 1) 1573 (define-opcode l2i 136 1 -1) 1574 (define-opcode l2f 137 1 -1) 1575 (define-opcode l2d 138 1 0) 1576 (define-opcode f2i 139 1 nil) 1577 (define-opcode f2l 140 1 nil) 1578 (define-opcode f2d 141 1 1) 1579 (define-opcode d2i 142 1 nil) 1580 (define-opcode d2l 143 1 nil) 1581 (define-opcode d2f 144 1 -1) 1582 (define-opcode i2b 145 1 nil) 1583 (define-opcode i2c 146 1 nil) 1584 (define-opcode i2s 147 1 nil) 1585 (define-opcode lcmp 148 1 -3) 1586 (define-opcode fcmpl 149 1 -1) 1587 (define-opcode fcmpg 150 1 -1) 1588 (define-opcode dcmpl 151 1 -3) 1589 (define-opcode dcmpg 152 1 -3) 1590 (define-opcode ifeq 153 3 -1) 1591 (define-opcode ifne 154 3 -1) 1592 (define-opcode iflt 155 3 -1) 1593 (define-opcode ifge 156 3 -1) 1594 (define-opcode ifgt 157 3 -1) 1595 (define-opcode ifle 158 3 -1) 1596 (define-opcode if_icmpeq 159 3 -2) 1597 (define-opcode if_icmpne 160 3 -2) 1598 (define-opcode if_icmplt 161 3 -2) 1599 (define-opcode if_icmpge 162 3 -2) 1600 (define-opcode if_icmpgt 163 3 -2) 1601 (define-opcode if_icmple 164 3 -2) 1602 (define-opcode if_acmpeq 165 3 -2) 1603 (define-opcode if_acmpne 166 3 -2) 1604 (define-opcode goto 167 3 0) 1605 ;;(define-opcode jsr 168 3 1) Don't use these 2 opcodes: deprecated 1606 ;;(define-opcode ret 169 2 0) their use results in JVM verifier errors 1607 (define-opcode tableswitch 170 0 nil) 1608 (define-opcode lookupswitch 171 0 nil) 1609 (define-opcode ireturn 172 1 nil) 1610 (define-opcode lreturn 173 1 nil) 1611 (define-opcode freturn 174 1 nil) 1612 (define-opcode dreturn 175 1 nil) 1613 (define-opcode areturn 176 1 -1) 1614 (define-opcode return 177 1 0) 1615 (define-opcode getstatic 178 3 1) 1616 (define-opcode putstatic 179 3 -1) 1617 (define-opcode getfield 180 3 0) 1618 (define-opcode putfield 181 3 -2) 1619 (define-opcode invokevirtual 182 3 nil) 1620 (define-opcode invokespecial 183 3 nil) 1621 (define-opcode invokestatic 184 3 nil) 1622 (define-opcode invokeinterface 185 5 nil) 1623 (define-opcode unused 186 0 nil) 1624 (define-opcode new 187 3 1) 1625 (define-opcode newarray 188 2 nil) 1626 (define-opcode anewarray 189 3 0) 1627 (define-opcode arraylength 190 1 0) 1628 (define-opcode athrow 191 1 0) 1629 (define-opcode checkcast 192 3 0) 1630 (define-opcode instanceof 193 3 0) 1631 (define-opcode monitorenter 194 1 -1) 1632 (define-opcode monitorexit 195 1 -1) 1633 (define-opcode wide 196 0 nil) 1634 (define-opcode multianewarray 197 4 nil) 1635 (define-opcode ifnull 198 3 -1) 1636 (define-opcode ifnonnull 199 3 nil) 1637 (define-opcode goto_w 200 5 nil) 1638 ;; (define-opcode jsr_w 201 5 nil) Don't use: deprecated 1639 (define-opcode label 202 0 0) ;; virtual: does not exist in the JVM 1640 ;; (define-opcode push-value 203 nil 1) 1641 ;; (define-opcode store-value 204 nil -1) 1642 (define-opcode clear-values 205 0 0) ;; virtual: does not exist in the JVM 1643 ;;(define-opcode var-ref 206 0 0)|# 1644 1276 1645 #| 1277 1646 -
branches/invokedynamic/abcl/src/org/armedbear/lisp/jvm-instructions.lisp
r12918 r12953 450 450 (inst 'aload (car (instruction-args instruction))) 451 451 (inst 'aconst_null) 452 (inst 'putfield (u2 (pool-field +lisp-thread+ "_values" 453 +lisp-object-array+))))) 452 (inst 'putfield (u2 (constant-index 453 (pool-field +lisp-thread+ "_values" 454 +lisp-object-array+)))))) 454 455 (vector-push-extend instruction vector))) 455 456 (t … … 655 656 (unless (= (length args) 1) 656 657 (error "Wrong number of args for LDC.")) 657 (if (> (car args) 255) 658 (inst 19 (u2 (car args))) ; LDC_W 659 (inst 18 args)))) 658 (let ((index (constant-index (car args)))) 659 (if (> index 255) 660 (inst 19 (u2 index)) ; LDC_W 661 (inst 18 args))))) 660 662 661 663 ;; ldc2_w … … 664 666 (unless (= (length args) 1) 665 667 (error "Wrong number of args for LDC2_W.")) 666 (inst 20 (u2 (c ar args)))))668 (inst 20 (u2 (constant-index (car args)))))) 667 669 668 670 ;; iinc … … 985 987 (setf (svref bytes index) (instruction-opcode instruction)) 986 988 (incf index) 987 (dolist (byte (instruction-args instruction)) 988 (setf (svref bytes index) byte) 989 (dolist (arg (instruction-args instruction)) 990 (setf (svref bytes index) 991 (if (constant-p arg) (constant-index arg) arg)) 989 992 (incf index))))) 990 993 (values bytes labels))))
Note: See TracChangeset
for help on using the changeset viewer.