1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14definitions: 15 - name: java 16 template: | 17 .language Java 18 .record R {} 19 .record E <java.extends=R> {} 20 .record A <java.annotation, java.annotation.type=runtime> {} 21 .record java.lang.String <external> 22 .record java.lang.Class <external> 23 .record java.lang.Object <external> 24 - name: pandasm 25 template: | 26 .record R {} 27 .record panda.String <external> 28 .record panda.Class <external> 29 .record panda.Object <external> 30 31tests: 32 - file-name: "newobj" 33 isa: 34 title: Create new object 35 description: | 36 Resolve class type from type_id, allocate memory for an object, initialize its fields with their 37 default values (i.e. 0 for primitives and null for objects) and put a reference to the newly created 38 object into register. The object should be initialized by calling initialization method before 39 further usage. 40 instructions: 41 - sig: newobj v:out:ref, type_id 42 acc: none 43 format: [op_v_8_id_16] 44 commands: 45 46 47 - file-name: "invalid_reg" 48 isa: 49 instructions: 50 - sig: newobj v:out:ref, type_id 51 acc: none 52 format: [op_v_8_id_16] 53 runner-options: [compile-failure] 54 description: Check 'newobj' instruction with invalid register. 55 header-template: [] 56 code-template: | 57 .record A {} 58 59 .function i32 main() { 60 newobj %s 61 check-type: exit-positive 62 cases: 63 - values: ['v255, A'] 64 runner-options: ['compile-only'] 65 - values: [''] 66 - values: ['A'] 67 - values: ['v256, A'] 68 - values: ['v65535, A'] 69 - values: ['v32767, A'] 70 - values: ['a0, A'] 71 - values: ['V0, A'] 72 - values: ['A, A'] 73 - values: ['}, A'] 74 - values: ['v0, v0'] 75 76 77 - file-name: "invalid_type" 78 isa: 79 verification: 80 - type_id_object 81 runner-options: [compile-failure] 82 description: Check 'newobj' instruction with invalid type id. 83 header-template: [] 84 code-template: | 85 .record A { 86 i32 f32 87 A fA 88 i32[] f32Array 89 A[] fAArray 90 } 91 .function void aFunc(A a0) { 92 return.void 93 } 94 .function void bFunc() <static> { 95 return.void 96 } 97 .function i32 main() { 98 begin: 99 newobj v0, %s 100 end: 101 check-type: exit-positive 102 cases: 103 - values: 104 - "" 105 - values: 106 - "label:" 107 - values: 108 - "begin" 109 - values: 110 - "{}" 111 - values: 112 - "}" 113 - values: 114 - "# comment" 115 - values: 116 - "null" 117 - values: 118 - "0" 119 - values: 120 - "v0" 121 - values: 122 - "i32" 123 - values: 124 - '"A"' 125 - values: 126 - "A.f32" 127 - values: 128 - "A.fA" 129 - values: 130 - "A.f32Array" 131 - values: 132 - "A.fAArray" 133 - values: 134 - "panda.Object[]" 135 - values: 136 - "aFunc" 137 - values: 138 - "A.aFunc" 139 - values: 140 - "bFunc" 141 - values: 142 - "main" 143 - values: 144 - "panda" 145 - values: 146 - "Object" 147 148 - file-name: "valid_type_p" 149 isa: 150 verification: 151 - type_id_object 152 runner-options: ['verifier-only', 'verifier-debug-config'] 153 tags: [verifier] 154 description: Check 'newobj' instruction with valid type id in PandaAssembly context. 155 header-template: [pandasm, main] 156 code-template: | 157 # 158 newobj v0, %s 159 check-type: exit-positive 160 cases: 161 - values: 162 - R 163 - values: 164 - panda.Class 165 - values: 166 - panda.Object 167 - values: 168 - panda.String 169 tags: ["tsan"] 170 171 - file-name: "valid_instance_p" 172 isa: 173 description: | 174 Resolve class type from type_id, allocate memory for an object, initialize its fields with their 175 default values (i.e. 0 for primitives and null for objects) and put a reference to the newly created 176 object into register. 177 description: Check type of object created by 'newobj' instruction with valid type in PandaAssembly context. 178 header-template: [pandasm, main] 179 code-template: | 180 # 181 lda.null 182 movi v2, 1 183 newobj v1, %s 184 lda.obj v1 185 isinstance %s 186 jeq v2, check2 187 ldai 1 188 return 189 check2: 190 lda.obj v1 191 isinstance panda.Object 192 jeq v2, ok 193 ldai 2 194 return 195 ok: 196 check-type: exit-positive 197 cases: 198 - values: 199 - R 200 - R 201 - values: 202 - panda.String 203 - panda.String 204 - values: 205 - panda.Class 206 - panda.Class 207 bugid: ["3540"] 208 ignore: true 209 - values: 210 - panda.Object 211 - panda.Object 212 tags: ["tsan"] 213 214 - file-name: "obj_ne_p" 215 isa: 216 description: | 217 Resolve class type from type_id, allocate memory for an object, initialize its fields with their 218 default values (i.e. 0 for primitives and null for objects) and put a reference to the newly created 219 object into register. 220 description: Check that two objects created by 'newobj' instructions are different in PandaAssembly context. 221 header-template: [pandasm, main] 222 code-template: | 223 # 224 newobj v1, %s 225 lda.null 226 newobj v0, %s 227 lda.obj v0 228 jne.obj v1, ok 229 ldai 1 230 return 231 ok: 232 check-type: exit-positive 233 cases: 234 - values: 235 - R 236 - R 237 - values: 238 - R 239 - panda.Object 240 - values: 241 - R 242 - panda.String 243 - values: 244 - R 245 - panda.Class 246 bugid: ["3540"] 247 ignore: true 248 - values: 249 - panda.Object 250 - panda.Object 251 tags: ["tsan"] 252 - values: 253 - panda.Object 254 - panda.String 255 tags: ["tsan"] 256 - values: 257 - panda.Object 258 - panda.Class 259 bugid: ["3540"] 260 ignore: true 261 - values: 262 - panda.String 263 - panda.String 264 - values: 265 - panda.String 266 - panda.Class 267 bugid: ["3540"] 268 ignore: true 269 - values: 270 - panda.Class 271 - panda.Class 272 bugid: ["3540"] 273 ignore: true 274 275 - file-name: "init_p" 276 isa: 277 description: | 278 Resolve class type from type_id, allocate memory for an object, initialize its fields with their 279 default values (i.e. 0 for primitives and null for objects) and put a reference to the newly created 280 object into register. 281 description: Check that objects fields are properly initialized in PandaAssembly context. 282 header-template: [pandasm] 283 tags: ["tsan"] 284 code-template: | 285 .record Z { 286 u1 fu1 287 u8 fu8 288 i8 fi8 289 u16 fu16 290 i16 fi16 291 u32 fu32 292 i32 fi32 293 u64 fu64 294 i64 fi64 295 f32 ff32 296 f64 ff64 297 298 u1[] fu1a 299 u8[] fu8a 300 i8[] fi8a 301 u16[] fu16a 302 i16[] fi16a 303 u32[] fu32a 304 i32[] fi32a 305 u64[] fu64a 306 i64[] fi64a 307 f32[] ff32a 308 f64[] ff64a 309 310 u1[][] fu1aa 311 u8[][] fu8aa 312 i8[][] fi8aa 313 u16[][] fu16aa 314 i16[][] fi16aa 315 u32[][] fu32aa 316 i32[][] fi32aa 317 u64[][] fu64aa 318 i64[][] fi64aa 319 f32[][] ff32aa 320 f64[][] ff64aa 321 322 R fR 323 R[] fRa 324 R[][] fRaa 325 326 panda.Object fO 327 panda.Object[] fOa 328 panda.Object[][] fOaa 329 330 panda.String fS 331 panda.String[] fSa 332 panda.String[][] fSaa 333 334 panda.Class fC 335 panda.Class[] fCa 336 panda.Class[][] fCaa 337 } 338 339 .function i32 main() { 340 newobj v1, Z 341 label_u1: 342 ldai 111 343 ldobj v1, Z.fu1 344 jeqz label_u8 345 ldai 1 346 return 347 label_u8: 348 ldai 111 349 ldobj v1, Z.fu8 350 jeqz label_i8 351 ldai 2 352 return 353 label_i8: 354 ldai 111 355 ldobj v1, Z.fi8 356 jeqz label_u16 357 ldai 3 358 return 359 label_u16: 360 ldai 111 361 ldobj v1, Z.fu16 362 jeqz label_i16 363 ldai 4 364 return 365 label_i16: 366 ldai 111 367 ldobj v1, Z.fi16 368 jeqz label_u32 369 ldai 5 370 return 371 label_u32: 372 ldai 111 373 ldobj v1, Z.fu32 374 jeqz label_i32 375 ldai 6 376 return 377 label_i32: 378 ldai 111 379 ldobj v1, Z.fi32 380 jeqz label_u64 381 ldai 7 382 return 383 label_u64: 384 ldai 111 385 ldobj.64 v1, Z.fu64 386 movi.64 v2, 0 387 ucmp.64 v2 388 jeqz label_i64 389 ldai 8 390 return 391 label_i64: 392 ldai 111 393 ldobj.64 v1, Z.fi64 394 movi.64 v2, 0 395 cmp.64 v2 396 jeqz label_f32 397 ldai 9 398 return 399 label_f32: 400 ldai 111 401 ldobj v1, Z.ff32 402 fmovi v2, 0.0 403 fcmpg v2 404 jeqz label_f64 405 ldai 10 406 return 407 label_f64: 408 ldai 111 409 ldobj.64 v1, Z.ff64 410 fmovi.64 v2, 0.0 411 fcmpg.64 v2 412 jeqz label_R 413 ldai 11 414 return 415 label_R: 416 ldai 111 417 ldobj.obj v1, Z.fR 418 jeqz.obj label_Ra 419 ldai 12 420 return 421 label_Ra: 422 ldai 111 423 ldobj.obj v1, Z.fRa 424 jeqz.obj label_Raa 425 ldai 13 426 return 427 label_Raa: 428 ldai 111 429 ldobj.obj v1, Z.fRaa 430 jeqz.obj label_O 431 ldai 14 432 return 433 label_O: 434 ldai 111 435 ldobj.obj v1, Z.fO 436 jeqz.obj label_Oa 437 ldai 15 438 return 439 label_Oa: 440 ldai 111 441 ldobj.obj v1, Z.fOa 442 jeqz.obj label_Oaa 443 ldai 16 444 return 445 label_Oaa: 446 ldai 111 447 ldobj.obj v1, Z.fOaa 448 jeqz.obj label_S 449 ldai 17 450 return 451 label_S: 452 ldai 111 453 ldobj.obj v1, Z.fS 454 jeqz.obj label_Sa 455 ldai 18 456 return 457 label_Sa: 458 ldai 111 459 ldobj.obj v1, Z.fSa 460 jeqz.obj label_Saa 461 ldai 19 462 return 463 label_Saa: 464 ldai 111 465 ldobj.obj v1, Z.fSaa 466 jeqz.obj label_C 467 ldai 20 468 return 469 label_C: 470 ldai 111 471 ldobj.obj v1, Z.fC 472 jeqz.obj label_Ca 473 ldai 21 474 return 475 label_Ca: 476 ldai 111 477 ldobj.obj v1, Z.fCa 478 jeqz.obj label_Caa 479 ldai 22 480 return 481 label_Caa: 482 ldai 111 483 ldobj.obj v1, Z.fCaa 484 jeqz.obj label_u1a 485 ldai 23 486 return 487 label_u1a: 488 ldai 111 489 ldobj.obj v1, Z.fu1a 490 jeqz.obj label_u8a 491 ldai 24 492 return 493 label_u8a: 494 ldai 111 495 ldobj.obj v1, Z.fu8a 496 jeqz.obj label_i8a 497 ldai 25 498 return 499 label_i8a: 500 ldai 111 501 ldobj.obj v1, Z.fi8a 502 jeqz.obj label_u16a 503 ldai 26 504 return 505 label_u16a: 506 ldai 111 507 ldobj.obj v1, Z.fu16a 508 jeqz.obj label_i16a 509 ldai 27 510 return 511 label_i16a: 512 ldai 111 513 ldobj.obj v1, Z.fi16a 514 jeqz.obj label_u32a 515 ldai 28 516 return 517 label_u32a: 518 ldai 111 519 ldobj.obj v1, Z.fu32a 520 jeqz.obj label_i32a 521 ldai 29 522 return 523 label_i32a: 524 ldai 111 525 ldobj.obj v1, Z.fi32a 526 jeqz.obj label_u64a 527 ldai 30 528 return 529 label_u64a: 530 ldai 111 531 ldobj.obj v1, Z.fu64a 532 jeqz.obj label_i64a 533 ldai 31 534 return 535 label_i64a: 536 ldai 111 537 ldobj.obj v1, Z.fi64a 538 jeqz.obj label_f32a 539 ldai 32 540 return 541 label_f32a: 542 ldai 111 543 ldobj.obj v1, Z.ff32a 544 jeqz.obj label_f64a 545 ldai 33 546 return 547 label_f64a: 548 ldai 111 549 ldobj.obj v1, Z.ff64a 550 jeqz.obj label_u1aa 551 ldai 34 552 return 553 label_u1aa: 554 ldai 111 555 ldobj.obj v1, Z.fu1aa 556 jeqz.obj label_u8aa 557 ldai 35 558 return 559 label_u8aa: 560 ldai 111 561 ldobj.obj v1, Z.fu8aa 562 jeqz.obj label_i8aa 563 ldai 36 564 return 565 label_i8aa: 566 ldai 111 567 ldobj.obj v1, Z.fi8aa 568 jeqz.obj label_u16aa 569 ldai 37 570 return 571 label_u16aa: 572 ldai 111 573 ldobj.obj v1, Z.fu16aa 574 jeqz.obj label_i16aa 575 ldai 38 576 return 577 label_i16aa: 578 ldai 111 579 ldobj.obj v1, Z.fi16aa 580 jeqz.obj label_u32aa 581 ldai 39 582 return 583 label_u32aa: 584 ldai 111 585 ldobj.obj v1, Z.fu32aa 586 jeqz.obj label_i32aa 587 ldai 40 588 return 589 label_i32aa: 590 ldai 111 591 ldobj.obj v1, Z.fi32aa 592 jeqz.obj label_u64aa 593 ldai 41 594 return 595 label_u64aa: 596 ldai 111 597 ldobj.obj v1, Z.fu64aa 598 jeqz.obj label_i64aa 599 ldai 42 600 return 601 label_i64aa: 602 ldai 111 603 ldobj.obj v1, Z.fi64aa 604 jeqz.obj label_f32aa 605 ldai 43 606 return 607 label_f32aa: 608 ldai 111 609 ldobj.obj v1, Z.ff32aa 610 jeqz.obj label_f64aa 611 ldai 44 612 return 613 label_f64aa: 614 ldai 111 615 ldobj.obj v1, Z.ff64aa 616 jeqz.obj ok 617 ldai 45 618 return 619 ok: 620 check-type: exit-positive 621 622 - file-name: "oome_p" 623 isa: 624 exceptions: 625 - x_oom 626 description: Create objects with newobj instruction until OutOfMemoryError in PandaAssembly context 627 header-template: [] 628 panda-options: "--heap-size-limit=67108864" 629 bugid: ["3578", "4170", "4171"] 630 ignore: true 631 code-template: | 632 .record panda.OutOfMemoryError <external> 633 .record Z { 634 %s 635 } 636 .function i32 main() { 637 movi v7, 50000 # array size 638 newarr v6, v7, Z[] # array ref 639 movi v1, 0 # index 640 begin: 641 newobj v0, Z 642 lda.obj v0 643 starr.obj v6, v1 644 inci v1, 1 645 lda v1 646 jlt v7, begin 647 end: 648 ldai 1 # Should not reach this line 649 return 650 651 catch_OOME: 652 ldai 0 # Expected panda.OutOfMemoryError 653 return 654 655 catch_all: 656 ldai 2 # Unexpected exception, test failed 657 return 658 659 .catch panda.OutOfMemoryError, begin, end, catch_OOME 660 .catchall begin, end, catch_all 661 check-type: none 662 cases: 663 - values: 664 - "#{[*1..500].map do |i| \" f64 f#{i}\\n\" end .join}" 665 tags: ["tsan"] 666 667