src/share/vm/shark/sharkBlock.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2047
d2ede61b7a12
child 4314
2cd5e15048e6
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

twisti@2047 1 /*
stefank@2314 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
twisti@2047 3 * Copyright 2008, 2009, 2010 Red Hat, Inc.
twisti@2047 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
twisti@2047 5 *
twisti@2047 6 * This code is free software; you can redistribute it and/or modify it
twisti@2047 7 * under the terms of the GNU General Public License version 2 only, as
twisti@2047 8 * published by the Free Software Foundation.
twisti@2047 9 *
twisti@2047 10 * This code is distributed in the hope that it will be useful, but WITHOUT
twisti@2047 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
twisti@2047 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
twisti@2047 13 * version 2 for more details (a copy is included in the LICENSE file that
twisti@2047 14 * accompanied this code).
twisti@2047 15 *
twisti@2047 16 * You should have received a copy of the GNU General Public License version
twisti@2047 17 * 2 along with this work; if not, write to the Free Software Foundation,
twisti@2047 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
twisti@2047 19 *
twisti@2047 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
twisti@2047 21 * or visit www.oracle.com if you need additional information or have any
twisti@2047 22 * questions.
twisti@2047 23 *
twisti@2047 24 */
twisti@2047 25
stefank@2314 26 #include "precompiled.hpp"
stefank@2314 27 #include "interpreter/bytecodes.hpp"
stefank@2314 28 #include "shark/llvmHeaders.hpp"
stefank@2314 29 #include "shark/llvmValue.hpp"
stefank@2314 30 #include "shark/sharkBlock.hpp"
stefank@2314 31 #include "shark/sharkBuilder.hpp"
stefank@2314 32 #include "shark/sharkConstant.hpp"
stefank@2314 33 #include "shark/sharkState.hpp"
stefank@2314 34 #include "shark/sharkValue.hpp"
stefank@2314 35 #include "shark/shark_globals.hpp"
stefank@2314 36 #include "utilities/debug.hpp"
twisti@2047 37
twisti@2047 38 using namespace llvm;
twisti@2047 39
twisti@2047 40 void SharkBlock::parse_bytecode(int start, int limit) {
twisti@2047 41 SharkValue *a, *b, *c, *d;
twisti@2047 42 int i;
twisti@2047 43
twisti@2047 44 // Ensure the current state is initialized before we emit any code,
twisti@2047 45 // so that any setup code for the state is at the start of the block
twisti@2047 46 current_state();
twisti@2047 47
twisti@2047 48 // Parse the bytecodes
twisti@2047 49 iter()->reset_to_bci(start);
twisti@2047 50 while (iter()->next_bci() < limit) {
twisti@2047 51 NOT_PRODUCT(a = b = c = d = NULL);
twisti@2047 52 iter()->next();
twisti@2047 53
twisti@2047 54 if (SharkTraceBytecodes)
twisti@2047 55 tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc()));
twisti@2047 56
twisti@2047 57 if (has_trap() && trap_bci() == bci()) {
twisti@2047 58 do_trap(trap_request());
twisti@2047 59 return;
twisti@2047 60 }
twisti@2047 61
twisti@2047 62 if (UseLoopSafepoints) {
twisti@2047 63 // XXX if a lcmp is followed by an if_?? then C2 maybe-inserts
twisti@2047 64 // the safepoint before the lcmp rather than before the if.
twisti@2047 65 // Maybe we should do this too. See parse2.cpp for details.
twisti@2047 66 switch (bc()) {
twisti@2047 67 case Bytecodes::_goto:
twisti@2047 68 case Bytecodes::_ifnull:
twisti@2047 69 case Bytecodes::_ifnonnull:
twisti@2047 70 case Bytecodes::_if_acmpeq:
twisti@2047 71 case Bytecodes::_if_acmpne:
twisti@2047 72 case Bytecodes::_ifeq:
twisti@2047 73 case Bytecodes::_ifne:
twisti@2047 74 case Bytecodes::_iflt:
twisti@2047 75 case Bytecodes::_ifle:
twisti@2047 76 case Bytecodes::_ifgt:
twisti@2047 77 case Bytecodes::_ifge:
twisti@2047 78 case Bytecodes::_if_icmpeq:
twisti@2047 79 case Bytecodes::_if_icmpne:
twisti@2047 80 case Bytecodes::_if_icmplt:
twisti@2047 81 case Bytecodes::_if_icmple:
twisti@2047 82 case Bytecodes::_if_icmpgt:
twisti@2047 83 case Bytecodes::_if_icmpge:
twisti@2047 84 if (iter()->get_dest() <= bci())
twisti@2047 85 maybe_add_backedge_safepoint();
twisti@2047 86 break;
twisti@2047 87
twisti@2047 88 case Bytecodes::_goto_w:
twisti@2047 89 if (iter()->get_far_dest() <= bci())
twisti@2047 90 maybe_add_backedge_safepoint();
twisti@2047 91 break;
twisti@2047 92
twisti@2047 93 case Bytecodes::_tableswitch:
twisti@2047 94 case Bytecodes::_lookupswitch:
twisti@2047 95 if (switch_default_dest() <= bci()) {
twisti@2047 96 maybe_add_backedge_safepoint();
twisti@2047 97 break;
twisti@2047 98 }
twisti@2047 99 int len = switch_table_length();
twisti@2047 100 for (int i = 0; i < len; i++) {
twisti@2047 101 if (switch_dest(i) <= bci()) {
twisti@2047 102 maybe_add_backedge_safepoint();
twisti@2047 103 break;
twisti@2047 104 }
twisti@2047 105 }
twisti@2047 106 break;
twisti@2047 107 }
twisti@2047 108 }
twisti@2047 109
twisti@2047 110 switch (bc()) {
twisti@2047 111 case Bytecodes::_nop:
twisti@2047 112 break;
twisti@2047 113
twisti@2047 114 case Bytecodes::_aconst_null:
twisti@2047 115 push(SharkValue::null());
twisti@2047 116 break;
twisti@2047 117
twisti@2047 118 case Bytecodes::_iconst_m1:
twisti@2047 119 push(SharkValue::jint_constant(-1));
twisti@2047 120 break;
twisti@2047 121 case Bytecodes::_iconst_0:
twisti@2047 122 push(SharkValue::jint_constant(0));
twisti@2047 123 break;
twisti@2047 124 case Bytecodes::_iconst_1:
twisti@2047 125 push(SharkValue::jint_constant(1));
twisti@2047 126 break;
twisti@2047 127 case Bytecodes::_iconst_2:
twisti@2047 128 push(SharkValue::jint_constant(2));
twisti@2047 129 break;
twisti@2047 130 case Bytecodes::_iconst_3:
twisti@2047 131 push(SharkValue::jint_constant(3));
twisti@2047 132 break;
twisti@2047 133 case Bytecodes::_iconst_4:
twisti@2047 134 push(SharkValue::jint_constant(4));
twisti@2047 135 break;
twisti@2047 136 case Bytecodes::_iconst_5:
twisti@2047 137 push(SharkValue::jint_constant(5));
twisti@2047 138 break;
twisti@2047 139
twisti@2047 140 case Bytecodes::_lconst_0:
twisti@2047 141 push(SharkValue::jlong_constant(0));
twisti@2047 142 break;
twisti@2047 143 case Bytecodes::_lconst_1:
twisti@2047 144 push(SharkValue::jlong_constant(1));
twisti@2047 145 break;
twisti@2047 146
twisti@2047 147 case Bytecodes::_fconst_0:
twisti@2047 148 push(SharkValue::jfloat_constant(0));
twisti@2047 149 break;
twisti@2047 150 case Bytecodes::_fconst_1:
twisti@2047 151 push(SharkValue::jfloat_constant(1));
twisti@2047 152 break;
twisti@2047 153 case Bytecodes::_fconst_2:
twisti@2047 154 push(SharkValue::jfloat_constant(2));
twisti@2047 155 break;
twisti@2047 156
twisti@2047 157 case Bytecodes::_dconst_0:
twisti@2047 158 push(SharkValue::jdouble_constant(0));
twisti@2047 159 break;
twisti@2047 160 case Bytecodes::_dconst_1:
twisti@2047 161 push(SharkValue::jdouble_constant(1));
twisti@2047 162 break;
twisti@2047 163
twisti@2047 164 case Bytecodes::_bipush:
twisti@2047 165 push(SharkValue::jint_constant(iter()->get_constant_u1()));
twisti@2047 166 break;
twisti@2047 167 case Bytecodes::_sipush:
twisti@2047 168 push(SharkValue::jint_constant(iter()->get_constant_u2()));
twisti@2047 169 break;
twisti@2047 170
twisti@2047 171 case Bytecodes::_ldc:
twisti@2047 172 case Bytecodes::_ldc_w:
twisti@2047 173 case Bytecodes::_ldc2_w:
twisti@2047 174 push(SharkConstant::for_ldc(iter())->value(builder()));
twisti@2047 175 break;
twisti@2047 176
twisti@2047 177 case Bytecodes::_iload_0:
twisti@2047 178 case Bytecodes::_lload_0:
twisti@2047 179 case Bytecodes::_fload_0:
twisti@2047 180 case Bytecodes::_dload_0:
twisti@2047 181 case Bytecodes::_aload_0:
twisti@2047 182 push(local(0));
twisti@2047 183 break;
twisti@2047 184 case Bytecodes::_iload_1:
twisti@2047 185 case Bytecodes::_lload_1:
twisti@2047 186 case Bytecodes::_fload_1:
twisti@2047 187 case Bytecodes::_dload_1:
twisti@2047 188 case Bytecodes::_aload_1:
twisti@2047 189 push(local(1));
twisti@2047 190 break;
twisti@2047 191 case Bytecodes::_iload_2:
twisti@2047 192 case Bytecodes::_lload_2:
twisti@2047 193 case Bytecodes::_fload_2:
twisti@2047 194 case Bytecodes::_dload_2:
twisti@2047 195 case Bytecodes::_aload_2:
twisti@2047 196 push(local(2));
twisti@2047 197 break;
twisti@2047 198 case Bytecodes::_iload_3:
twisti@2047 199 case Bytecodes::_lload_3:
twisti@2047 200 case Bytecodes::_fload_3:
twisti@2047 201 case Bytecodes::_dload_3:
twisti@2047 202 case Bytecodes::_aload_3:
twisti@2047 203 push(local(3));
twisti@2047 204 break;
twisti@2047 205 case Bytecodes::_iload:
twisti@2047 206 case Bytecodes::_lload:
twisti@2047 207 case Bytecodes::_fload:
twisti@2047 208 case Bytecodes::_dload:
twisti@2047 209 case Bytecodes::_aload:
twisti@2047 210 push(local(iter()->get_index()));
twisti@2047 211 break;
twisti@2047 212
twisti@2047 213 case Bytecodes::_baload:
twisti@2047 214 do_aload(T_BYTE);
twisti@2047 215 break;
twisti@2047 216 case Bytecodes::_caload:
twisti@2047 217 do_aload(T_CHAR);
twisti@2047 218 break;
twisti@2047 219 case Bytecodes::_saload:
twisti@2047 220 do_aload(T_SHORT);
twisti@2047 221 break;
twisti@2047 222 case Bytecodes::_iaload:
twisti@2047 223 do_aload(T_INT);
twisti@2047 224 break;
twisti@2047 225 case Bytecodes::_laload:
twisti@2047 226 do_aload(T_LONG);
twisti@2047 227 break;
twisti@2047 228 case Bytecodes::_faload:
twisti@2047 229 do_aload(T_FLOAT);
twisti@2047 230 break;
twisti@2047 231 case Bytecodes::_daload:
twisti@2047 232 do_aload(T_DOUBLE);
twisti@2047 233 break;
twisti@2047 234 case Bytecodes::_aaload:
twisti@2047 235 do_aload(T_OBJECT);
twisti@2047 236 break;
twisti@2047 237
twisti@2047 238 case Bytecodes::_istore_0:
twisti@2047 239 case Bytecodes::_lstore_0:
twisti@2047 240 case Bytecodes::_fstore_0:
twisti@2047 241 case Bytecodes::_dstore_0:
twisti@2047 242 case Bytecodes::_astore_0:
twisti@2047 243 set_local(0, pop());
twisti@2047 244 break;
twisti@2047 245 case Bytecodes::_istore_1:
twisti@2047 246 case Bytecodes::_lstore_1:
twisti@2047 247 case Bytecodes::_fstore_1:
twisti@2047 248 case Bytecodes::_dstore_1:
twisti@2047 249 case Bytecodes::_astore_1:
twisti@2047 250 set_local(1, pop());
twisti@2047 251 break;
twisti@2047 252 case Bytecodes::_istore_2:
twisti@2047 253 case Bytecodes::_lstore_2:
twisti@2047 254 case Bytecodes::_fstore_2:
twisti@2047 255 case Bytecodes::_dstore_2:
twisti@2047 256 case Bytecodes::_astore_2:
twisti@2047 257 set_local(2, pop());
twisti@2047 258 break;
twisti@2047 259 case Bytecodes::_istore_3:
twisti@2047 260 case Bytecodes::_lstore_3:
twisti@2047 261 case Bytecodes::_fstore_3:
twisti@2047 262 case Bytecodes::_dstore_3:
twisti@2047 263 case Bytecodes::_astore_3:
twisti@2047 264 set_local(3, pop());
twisti@2047 265 break;
twisti@2047 266 case Bytecodes::_istore:
twisti@2047 267 case Bytecodes::_lstore:
twisti@2047 268 case Bytecodes::_fstore:
twisti@2047 269 case Bytecodes::_dstore:
twisti@2047 270 case Bytecodes::_astore:
twisti@2047 271 set_local(iter()->get_index(), pop());
twisti@2047 272 break;
twisti@2047 273
twisti@2047 274 case Bytecodes::_bastore:
twisti@2047 275 do_astore(T_BYTE);
twisti@2047 276 break;
twisti@2047 277 case Bytecodes::_castore:
twisti@2047 278 do_astore(T_CHAR);
twisti@2047 279 break;
twisti@2047 280 case Bytecodes::_sastore:
twisti@2047 281 do_astore(T_SHORT);
twisti@2047 282 break;
twisti@2047 283 case Bytecodes::_iastore:
twisti@2047 284 do_astore(T_INT);
twisti@2047 285 break;
twisti@2047 286 case Bytecodes::_lastore:
twisti@2047 287 do_astore(T_LONG);
twisti@2047 288 break;
twisti@2047 289 case Bytecodes::_fastore:
twisti@2047 290 do_astore(T_FLOAT);
twisti@2047 291 break;
twisti@2047 292 case Bytecodes::_dastore:
twisti@2047 293 do_astore(T_DOUBLE);
twisti@2047 294 break;
twisti@2047 295 case Bytecodes::_aastore:
twisti@2047 296 do_astore(T_OBJECT);
twisti@2047 297 break;
twisti@2047 298
twisti@2047 299 case Bytecodes::_pop:
twisti@2047 300 xpop();
twisti@2047 301 break;
twisti@2047 302 case Bytecodes::_pop2:
twisti@2047 303 xpop();
twisti@2047 304 xpop();
twisti@2047 305 break;
twisti@2047 306 case Bytecodes::_swap:
twisti@2047 307 a = xpop();
twisti@2047 308 b = xpop();
twisti@2047 309 xpush(a);
twisti@2047 310 xpush(b);
twisti@2047 311 break;
twisti@2047 312 case Bytecodes::_dup:
twisti@2047 313 a = xpop();
twisti@2047 314 xpush(a);
twisti@2047 315 xpush(a);
twisti@2047 316 break;
twisti@2047 317 case Bytecodes::_dup_x1:
twisti@2047 318 a = xpop();
twisti@2047 319 b = xpop();
twisti@2047 320 xpush(a);
twisti@2047 321 xpush(b);
twisti@2047 322 xpush(a);
twisti@2047 323 break;
twisti@2047 324 case Bytecodes::_dup_x2:
twisti@2047 325 a = xpop();
twisti@2047 326 b = xpop();
twisti@2047 327 c = xpop();
twisti@2047 328 xpush(a);
twisti@2047 329 xpush(c);
twisti@2047 330 xpush(b);
twisti@2047 331 xpush(a);
twisti@2047 332 break;
twisti@2047 333 case Bytecodes::_dup2:
twisti@2047 334 a = xpop();
twisti@2047 335 b = xpop();
twisti@2047 336 xpush(b);
twisti@2047 337 xpush(a);
twisti@2047 338 xpush(b);
twisti@2047 339 xpush(a);
twisti@2047 340 break;
twisti@2047 341 case Bytecodes::_dup2_x1:
twisti@2047 342 a = xpop();
twisti@2047 343 b = xpop();
twisti@2047 344 c = xpop();
twisti@2047 345 xpush(b);
twisti@2047 346 xpush(a);
twisti@2047 347 xpush(c);
twisti@2047 348 xpush(b);
twisti@2047 349 xpush(a);
twisti@2047 350 break;
twisti@2047 351 case Bytecodes::_dup2_x2:
twisti@2047 352 a = xpop();
twisti@2047 353 b = xpop();
twisti@2047 354 c = xpop();
twisti@2047 355 d = xpop();
twisti@2047 356 xpush(b);
twisti@2047 357 xpush(a);
twisti@2047 358 xpush(d);
twisti@2047 359 xpush(c);
twisti@2047 360 xpush(b);
twisti@2047 361 xpush(a);
twisti@2047 362 break;
twisti@2047 363
twisti@2047 364 case Bytecodes::_arraylength:
twisti@2047 365 do_arraylength();
twisti@2047 366 break;
twisti@2047 367
twisti@2047 368 case Bytecodes::_getfield:
twisti@2047 369 do_getfield();
twisti@2047 370 break;
twisti@2047 371 case Bytecodes::_getstatic:
twisti@2047 372 do_getstatic();
twisti@2047 373 break;
twisti@2047 374 case Bytecodes::_putfield:
twisti@2047 375 do_putfield();
twisti@2047 376 break;
twisti@2047 377 case Bytecodes::_putstatic:
twisti@2047 378 do_putstatic();
twisti@2047 379 break;
twisti@2047 380
twisti@2047 381 case Bytecodes::_iadd:
twisti@2047 382 b = pop();
twisti@2047 383 a = pop();
twisti@2047 384 push(SharkValue::create_jint(
twisti@2047 385 builder()->CreateAdd(a->jint_value(), b->jint_value()), false));
twisti@2047 386 break;
twisti@2047 387 case Bytecodes::_isub:
twisti@2047 388 b = pop();
twisti@2047 389 a = pop();
twisti@2047 390 push(SharkValue::create_jint(
twisti@2047 391 builder()->CreateSub(a->jint_value(), b->jint_value()), false));
twisti@2047 392 break;
twisti@2047 393 case Bytecodes::_imul:
twisti@2047 394 b = pop();
twisti@2047 395 a = pop();
twisti@2047 396 push(SharkValue::create_jint(
twisti@2047 397 builder()->CreateMul(a->jint_value(), b->jint_value()), false));
twisti@2047 398 break;
twisti@2047 399 case Bytecodes::_idiv:
twisti@2047 400 do_idiv();
twisti@2047 401 break;
twisti@2047 402 case Bytecodes::_irem:
twisti@2047 403 do_irem();
twisti@2047 404 break;
twisti@2047 405 case Bytecodes::_ineg:
twisti@2047 406 a = pop();
twisti@2047 407 push(SharkValue::create_jint(
twisti@2047 408 builder()->CreateNeg(a->jint_value()), a->zero_checked()));
twisti@2047 409 break;
twisti@2047 410 case Bytecodes::_ishl:
twisti@2047 411 b = pop();
twisti@2047 412 a = pop();
twisti@2047 413 push(SharkValue::create_jint(
twisti@2047 414 builder()->CreateShl(
twisti@2047 415 a->jint_value(),
twisti@2047 416 builder()->CreateAnd(
twisti@2047 417 b->jint_value(), LLVMValue::jint_constant(0x1f))), false));
twisti@2047 418 break;
twisti@2047 419 case Bytecodes::_ishr:
twisti@2047 420 b = pop();
twisti@2047 421 a = pop();
twisti@2047 422 push(SharkValue::create_jint(
twisti@2047 423 builder()->CreateAShr(
twisti@2047 424 a->jint_value(),
twisti@2047 425 builder()->CreateAnd(
twisti@2047 426 b->jint_value(), LLVMValue::jint_constant(0x1f))), false));
twisti@2047 427 break;
twisti@2047 428 case Bytecodes::_iushr:
twisti@2047 429 b = pop();
twisti@2047 430 a = pop();
twisti@2047 431 push(SharkValue::create_jint(
twisti@2047 432 builder()->CreateLShr(
twisti@2047 433 a->jint_value(),
twisti@2047 434 builder()->CreateAnd(
twisti@2047 435 b->jint_value(), LLVMValue::jint_constant(0x1f))), false));
twisti@2047 436 break;
twisti@2047 437 case Bytecodes::_iand:
twisti@2047 438 b = pop();
twisti@2047 439 a = pop();
twisti@2047 440 push(SharkValue::create_jint(
twisti@2047 441 builder()->CreateAnd(a->jint_value(), b->jint_value()), false));
twisti@2047 442 break;
twisti@2047 443 case Bytecodes::_ior:
twisti@2047 444 b = pop();
twisti@2047 445 a = pop();
twisti@2047 446 push(SharkValue::create_jint(
twisti@2047 447 builder()->CreateOr(a->jint_value(), b->jint_value()),
twisti@2047 448 a->zero_checked() && b->zero_checked()));
twisti@2047 449 break;
twisti@2047 450 case Bytecodes::_ixor:
twisti@2047 451 b = pop();
twisti@2047 452 a = pop();
twisti@2047 453 push(SharkValue::create_jint(
twisti@2047 454 builder()->CreateXor(a->jint_value(), b->jint_value()), false));
twisti@2047 455 break;
twisti@2047 456
twisti@2047 457 case Bytecodes::_ladd:
twisti@2047 458 b = pop();
twisti@2047 459 a = pop();
twisti@2047 460 push(SharkValue::create_jlong(
twisti@2047 461 builder()->CreateAdd(a->jlong_value(), b->jlong_value()), false));
twisti@2047 462 break;
twisti@2047 463 case Bytecodes::_lsub:
twisti@2047 464 b = pop();
twisti@2047 465 a = pop();
twisti@2047 466 push(SharkValue::create_jlong(
twisti@2047 467 builder()->CreateSub(a->jlong_value(), b->jlong_value()), false));
twisti@2047 468 break;
twisti@2047 469 case Bytecodes::_lmul:
twisti@2047 470 b = pop();
twisti@2047 471 a = pop();
twisti@2047 472 push(SharkValue::create_jlong(
twisti@2047 473 builder()->CreateMul(a->jlong_value(), b->jlong_value()), false));
twisti@2047 474 break;
twisti@2047 475 case Bytecodes::_ldiv:
twisti@2047 476 do_ldiv();
twisti@2047 477 break;
twisti@2047 478 case Bytecodes::_lrem:
twisti@2047 479 do_lrem();
twisti@2047 480 break;
twisti@2047 481 case Bytecodes::_lneg:
twisti@2047 482 a = pop();
twisti@2047 483 push(SharkValue::create_jlong(
twisti@2047 484 builder()->CreateNeg(a->jlong_value()), a->zero_checked()));
twisti@2047 485 break;
twisti@2047 486 case Bytecodes::_lshl:
twisti@2047 487 b = pop();
twisti@2047 488 a = pop();
twisti@2047 489 push(SharkValue::create_jlong(
twisti@2047 490 builder()->CreateShl(
twisti@2047 491 a->jlong_value(),
twisti@2047 492 builder()->CreateIntCast(
twisti@2047 493 builder()->CreateAnd(
twisti@2047 494 b->jint_value(), LLVMValue::jint_constant(0x3f)),
twisti@2047 495 SharkType::jlong_type(), true)), false));
twisti@2047 496 break;
twisti@2047 497 case Bytecodes::_lshr:
twisti@2047 498 b = pop();
twisti@2047 499 a = pop();
twisti@2047 500 push(SharkValue::create_jlong(
twisti@2047 501 builder()->CreateAShr(
twisti@2047 502 a->jlong_value(),
twisti@2047 503 builder()->CreateIntCast(
twisti@2047 504 builder()->CreateAnd(
twisti@2047 505 b->jint_value(), LLVMValue::jint_constant(0x3f)),
twisti@2047 506 SharkType::jlong_type(), true)), false));
twisti@2047 507 break;
twisti@2047 508 case Bytecodes::_lushr:
twisti@2047 509 b = pop();
twisti@2047 510 a = pop();
twisti@2047 511 push(SharkValue::create_jlong(
twisti@2047 512 builder()->CreateLShr(
twisti@2047 513 a->jlong_value(),
twisti@2047 514 builder()->CreateIntCast(
twisti@2047 515 builder()->CreateAnd(
twisti@2047 516 b->jint_value(), LLVMValue::jint_constant(0x3f)),
twisti@2047 517 SharkType::jlong_type(), true)), false));
twisti@2047 518 break;
twisti@2047 519 case Bytecodes::_land:
twisti@2047 520 b = pop();
twisti@2047 521 a = pop();
twisti@2047 522 push(SharkValue::create_jlong(
twisti@2047 523 builder()->CreateAnd(a->jlong_value(), b->jlong_value()), false));
twisti@2047 524 break;
twisti@2047 525 case Bytecodes::_lor:
twisti@2047 526 b = pop();
twisti@2047 527 a = pop();
twisti@2047 528 push(SharkValue::create_jlong(
twisti@2047 529 builder()->CreateOr(a->jlong_value(), b->jlong_value()),
twisti@2047 530 a->zero_checked() && b->zero_checked()));
twisti@2047 531 break;
twisti@2047 532 case Bytecodes::_lxor:
twisti@2047 533 b = pop();
twisti@2047 534 a = pop();
twisti@2047 535 push(SharkValue::create_jlong(
twisti@2047 536 builder()->CreateXor(a->jlong_value(), b->jlong_value()), false));
twisti@2047 537 break;
twisti@2047 538
twisti@2047 539 case Bytecodes::_fadd:
twisti@2047 540 b = pop();
twisti@2047 541 a = pop();
twisti@2047 542 push(SharkValue::create_jfloat(
twisti@2047 543 builder()->CreateFAdd(a->jfloat_value(), b->jfloat_value())));
twisti@2047 544 break;
twisti@2047 545 case Bytecodes::_fsub:
twisti@2047 546 b = pop();
twisti@2047 547 a = pop();
twisti@2047 548 push(SharkValue::create_jfloat(
twisti@2047 549 builder()->CreateFSub(a->jfloat_value(), b->jfloat_value())));
twisti@2047 550 break;
twisti@2047 551 case Bytecodes::_fmul:
twisti@2047 552 b = pop();
twisti@2047 553 a = pop();
twisti@2047 554 push(SharkValue::create_jfloat(
twisti@2047 555 builder()->CreateFMul(a->jfloat_value(), b->jfloat_value())));
twisti@2047 556 break;
twisti@2047 557 case Bytecodes::_fdiv:
twisti@2047 558 b = pop();
twisti@2047 559 a = pop();
twisti@2047 560 push(SharkValue::create_jfloat(
twisti@2047 561 builder()->CreateFDiv(a->jfloat_value(), b->jfloat_value())));
twisti@2047 562 break;
twisti@2047 563 case Bytecodes::_frem:
twisti@2047 564 b = pop();
twisti@2047 565 a = pop();
twisti@2047 566 push(SharkValue::create_jfloat(
twisti@2047 567 builder()->CreateFRem(a->jfloat_value(), b->jfloat_value())));
twisti@2047 568 break;
twisti@2047 569 case Bytecodes::_fneg:
twisti@2047 570 a = pop();
twisti@2047 571 push(SharkValue::create_jfloat(
twisti@2047 572 builder()->CreateFNeg(a->jfloat_value())));
twisti@2047 573 break;
twisti@2047 574
twisti@2047 575 case Bytecodes::_dadd:
twisti@2047 576 b = pop();
twisti@2047 577 a = pop();
twisti@2047 578 push(SharkValue::create_jdouble(
twisti@2047 579 builder()->CreateFAdd(a->jdouble_value(), b->jdouble_value())));
twisti@2047 580 break;
twisti@2047 581 case Bytecodes::_dsub:
twisti@2047 582 b = pop();
twisti@2047 583 a = pop();
twisti@2047 584 push(SharkValue::create_jdouble(
twisti@2047 585 builder()->CreateFSub(a->jdouble_value(), b->jdouble_value())));
twisti@2047 586 break;
twisti@2047 587 case Bytecodes::_dmul:
twisti@2047 588 b = pop();
twisti@2047 589 a = pop();
twisti@2047 590 push(SharkValue::create_jdouble(
twisti@2047 591 builder()->CreateFMul(a->jdouble_value(), b->jdouble_value())));
twisti@2047 592 break;
twisti@2047 593 case Bytecodes::_ddiv:
twisti@2047 594 b = pop();
twisti@2047 595 a = pop();
twisti@2047 596 push(SharkValue::create_jdouble(
twisti@2047 597 builder()->CreateFDiv(a->jdouble_value(), b->jdouble_value())));
twisti@2047 598 break;
twisti@2047 599 case Bytecodes::_drem:
twisti@2047 600 b = pop();
twisti@2047 601 a = pop();
twisti@2047 602 push(SharkValue::create_jdouble(
twisti@2047 603 builder()->CreateFRem(a->jdouble_value(), b->jdouble_value())));
twisti@2047 604 break;
twisti@2047 605 case Bytecodes::_dneg:
twisti@2047 606 a = pop();
twisti@2047 607 push(SharkValue::create_jdouble(
twisti@2047 608 builder()->CreateFNeg(a->jdouble_value())));
twisti@2047 609 break;
twisti@2047 610
twisti@2047 611 case Bytecodes::_iinc:
twisti@2047 612 i = iter()->get_index();
twisti@2047 613 set_local(
twisti@2047 614 i,
twisti@2047 615 SharkValue::create_jint(
twisti@2047 616 builder()->CreateAdd(
twisti@2047 617 LLVMValue::jint_constant(iter()->get_iinc_con()),
twisti@2047 618 local(i)->jint_value()), false));
twisti@2047 619 break;
twisti@2047 620
twisti@2047 621 case Bytecodes::_lcmp:
twisti@2047 622 do_lcmp();
twisti@2047 623 break;
twisti@2047 624
twisti@2047 625 case Bytecodes::_fcmpl:
twisti@2047 626 do_fcmp(false, false);
twisti@2047 627 break;
twisti@2047 628 case Bytecodes::_fcmpg:
twisti@2047 629 do_fcmp(false, true);
twisti@2047 630 break;
twisti@2047 631 case Bytecodes::_dcmpl:
twisti@2047 632 do_fcmp(true, false);
twisti@2047 633 break;
twisti@2047 634 case Bytecodes::_dcmpg:
twisti@2047 635 do_fcmp(true, true);
twisti@2047 636 break;
twisti@2047 637
twisti@2047 638 case Bytecodes::_i2l:
twisti@2047 639 a = pop();
twisti@2047 640 push(SharkValue::create_jlong(
twisti@2047 641 builder()->CreateIntCast(
twisti@2047 642 a->jint_value(), SharkType::jlong_type(), true), a->zero_checked()));
twisti@2047 643 break;
twisti@2047 644 case Bytecodes::_i2f:
twisti@2047 645 push(SharkValue::create_jfloat(
twisti@2047 646 builder()->CreateSIToFP(
twisti@2047 647 pop()->jint_value(), SharkType::jfloat_type())));
twisti@2047 648 break;
twisti@2047 649 case Bytecodes::_i2d:
twisti@2047 650 push(SharkValue::create_jdouble(
twisti@2047 651 builder()->CreateSIToFP(
twisti@2047 652 pop()->jint_value(), SharkType::jdouble_type())));
twisti@2047 653 break;
twisti@2047 654
twisti@2047 655 case Bytecodes::_l2i:
twisti@2047 656 push(SharkValue::create_jint(
twisti@2047 657 builder()->CreateIntCast(
twisti@2047 658 pop()->jlong_value(), SharkType::jint_type(), true), false));
twisti@2047 659 break;
twisti@2047 660 case Bytecodes::_l2f:
twisti@2047 661 push(SharkValue::create_jfloat(
twisti@2047 662 builder()->CreateSIToFP(
twisti@2047 663 pop()->jlong_value(), SharkType::jfloat_type())));
twisti@2047 664 break;
twisti@2047 665 case Bytecodes::_l2d:
twisti@2047 666 push(SharkValue::create_jdouble(
twisti@2047 667 builder()->CreateSIToFP(
twisti@2047 668 pop()->jlong_value(), SharkType::jdouble_type())));
twisti@2047 669 break;
twisti@2047 670
twisti@2047 671 case Bytecodes::_f2i:
twisti@2047 672 push(SharkValue::create_jint(
twisti@2047 673 builder()->CreateCall(
twisti@2047 674 builder()->f2i(), pop()->jfloat_value()), false));
twisti@2047 675 break;
twisti@2047 676 case Bytecodes::_f2l:
twisti@2047 677 push(SharkValue::create_jlong(
twisti@2047 678 builder()->CreateCall(
twisti@2047 679 builder()->f2l(), pop()->jfloat_value()), false));
twisti@2047 680 break;
twisti@2047 681 case Bytecodes::_f2d:
twisti@2047 682 push(SharkValue::create_jdouble(
twisti@2047 683 builder()->CreateFPExt(
twisti@2047 684 pop()->jfloat_value(), SharkType::jdouble_type())));
twisti@2047 685 break;
twisti@2047 686
twisti@2047 687 case Bytecodes::_d2i:
twisti@2047 688 push(SharkValue::create_jint(
twisti@2047 689 builder()->CreateCall(
twisti@2047 690 builder()->d2i(), pop()->jdouble_value()), false));
twisti@2047 691 break;
twisti@2047 692 case Bytecodes::_d2l:
twisti@2047 693 push(SharkValue::create_jlong(
twisti@2047 694 builder()->CreateCall(
twisti@2047 695 builder()->d2l(), pop()->jdouble_value()), false));
twisti@2047 696 break;
twisti@2047 697 case Bytecodes::_d2f:
twisti@2047 698 push(SharkValue::create_jfloat(
twisti@2047 699 builder()->CreateFPTrunc(
twisti@2047 700 pop()->jdouble_value(), SharkType::jfloat_type())));
twisti@2047 701 break;
twisti@2047 702
twisti@2047 703 case Bytecodes::_i2b:
twisti@2047 704 push(SharkValue::create_jint(
twisti@2047 705 builder()->CreateAShr(
twisti@2047 706 builder()->CreateShl(
twisti@2047 707 pop()->jint_value(),
twisti@2047 708 LLVMValue::jint_constant(24)),
twisti@2047 709 LLVMValue::jint_constant(24)), false));
twisti@2047 710 break;
twisti@2047 711 case Bytecodes::_i2c:
twisti@2047 712 push(SharkValue::create_jint(
twisti@2047 713 builder()->CreateAnd(
twisti@2047 714 pop()->jint_value(),
twisti@2047 715 LLVMValue::jint_constant(0xffff)), false));
twisti@2047 716 break;
twisti@2047 717 case Bytecodes::_i2s:
twisti@2047 718 push(SharkValue::create_jint(
twisti@2047 719 builder()->CreateAShr(
twisti@2047 720 builder()->CreateShl(
twisti@2047 721 pop()->jint_value(),
twisti@2047 722 LLVMValue::jint_constant(16)),
twisti@2047 723 LLVMValue::jint_constant(16)), false));
twisti@2047 724 break;
twisti@2047 725
twisti@2047 726 case Bytecodes::_return:
twisti@2047 727 do_return(T_VOID);
twisti@2047 728 break;
twisti@2047 729 case Bytecodes::_ireturn:
twisti@2047 730 do_return(T_INT);
twisti@2047 731 break;
twisti@2047 732 case Bytecodes::_lreturn:
twisti@2047 733 do_return(T_LONG);
twisti@2047 734 break;
twisti@2047 735 case Bytecodes::_freturn:
twisti@2047 736 do_return(T_FLOAT);
twisti@2047 737 break;
twisti@2047 738 case Bytecodes::_dreturn:
twisti@2047 739 do_return(T_DOUBLE);
twisti@2047 740 break;
twisti@2047 741 case Bytecodes::_areturn:
twisti@2047 742 do_return(T_OBJECT);
twisti@2047 743 break;
twisti@2047 744
twisti@2047 745 case Bytecodes::_athrow:
twisti@2047 746 do_athrow();
twisti@2047 747 break;
twisti@2047 748
twisti@2047 749 case Bytecodes::_goto:
twisti@2047 750 case Bytecodes::_goto_w:
twisti@2047 751 do_goto();
twisti@2047 752 break;
twisti@2047 753
twisti@2047 754 case Bytecodes::_jsr:
twisti@2047 755 case Bytecodes::_jsr_w:
twisti@2047 756 do_jsr();
twisti@2047 757 break;
twisti@2047 758
twisti@2047 759 case Bytecodes::_ret:
twisti@2047 760 do_ret();
twisti@2047 761 break;
twisti@2047 762
twisti@2047 763 case Bytecodes::_ifnull:
twisti@2047 764 do_if(ICmpInst::ICMP_EQ, SharkValue::null(), pop());
twisti@2047 765 break;
twisti@2047 766 case Bytecodes::_ifnonnull:
twisti@2047 767 do_if(ICmpInst::ICMP_NE, SharkValue::null(), pop());
twisti@2047 768 break;
twisti@2047 769 case Bytecodes::_if_acmpeq:
twisti@2047 770 b = pop();
twisti@2047 771 a = pop();
twisti@2047 772 do_if(ICmpInst::ICMP_EQ, b, a);
twisti@2047 773 break;
twisti@2047 774 case Bytecodes::_if_acmpne:
twisti@2047 775 b = pop();
twisti@2047 776 a = pop();
twisti@2047 777 do_if(ICmpInst::ICMP_NE, b, a);
twisti@2047 778 break;
twisti@2047 779 case Bytecodes::_ifeq:
twisti@2047 780 do_if(ICmpInst::ICMP_EQ, SharkValue::jint_constant(0), pop());
twisti@2047 781 break;
twisti@2047 782 case Bytecodes::_ifne:
twisti@2047 783 do_if(ICmpInst::ICMP_NE, SharkValue::jint_constant(0), pop());
twisti@2047 784 break;
twisti@2047 785 case Bytecodes::_iflt:
twisti@2047 786 do_if(ICmpInst::ICMP_SLT, SharkValue::jint_constant(0), pop());
twisti@2047 787 break;
twisti@2047 788 case Bytecodes::_ifle:
twisti@2047 789 do_if(ICmpInst::ICMP_SLE, SharkValue::jint_constant(0), pop());
twisti@2047 790 break;
twisti@2047 791 case Bytecodes::_ifgt:
twisti@2047 792 do_if(ICmpInst::ICMP_SGT, SharkValue::jint_constant(0), pop());
twisti@2047 793 break;
twisti@2047 794 case Bytecodes::_ifge:
twisti@2047 795 do_if(ICmpInst::ICMP_SGE, SharkValue::jint_constant(0), pop());
twisti@2047 796 break;
twisti@2047 797 case Bytecodes::_if_icmpeq:
twisti@2047 798 b = pop();
twisti@2047 799 a = pop();
twisti@2047 800 do_if(ICmpInst::ICMP_EQ, b, a);
twisti@2047 801 break;
twisti@2047 802 case Bytecodes::_if_icmpne:
twisti@2047 803 b = pop();
twisti@2047 804 a = pop();
twisti@2047 805 do_if(ICmpInst::ICMP_NE, b, a);
twisti@2047 806 break;
twisti@2047 807 case Bytecodes::_if_icmplt:
twisti@2047 808 b = pop();
twisti@2047 809 a = pop();
twisti@2047 810 do_if(ICmpInst::ICMP_SLT, b, a);
twisti@2047 811 break;
twisti@2047 812 case Bytecodes::_if_icmple:
twisti@2047 813 b = pop();
twisti@2047 814 a = pop();
twisti@2047 815 do_if(ICmpInst::ICMP_SLE, b, a);
twisti@2047 816 break;
twisti@2047 817 case Bytecodes::_if_icmpgt:
twisti@2047 818 b = pop();
twisti@2047 819 a = pop();
twisti@2047 820 do_if(ICmpInst::ICMP_SGT, b, a);
twisti@2047 821 break;
twisti@2047 822 case Bytecodes::_if_icmpge:
twisti@2047 823 b = pop();
twisti@2047 824 a = pop();
twisti@2047 825 do_if(ICmpInst::ICMP_SGE, b, a);
twisti@2047 826 break;
twisti@2047 827
twisti@2047 828 case Bytecodes::_tableswitch:
twisti@2047 829 case Bytecodes::_lookupswitch:
twisti@2047 830 do_switch();
twisti@2047 831 break;
twisti@2047 832
twisti@2047 833 case Bytecodes::_invokestatic:
twisti@2047 834 case Bytecodes::_invokespecial:
twisti@2047 835 case Bytecodes::_invokevirtual:
twisti@2047 836 case Bytecodes::_invokeinterface:
twisti@2047 837 do_call();
twisti@2047 838 break;
twisti@2047 839
twisti@2047 840 case Bytecodes::_instanceof:
twisti@2047 841 // This is a very common construct:
twisti@2047 842 //
twisti@2047 843 // if (object instanceof Klass) {
twisti@2047 844 // something = (Klass) object;
twisti@2047 845 // ...
twisti@2047 846 // }
twisti@2047 847 //
twisti@2047 848 // which gets compiled to something like this:
twisti@2047 849 //
twisti@2047 850 // 28: aload 9
twisti@2047 851 // 30: instanceof <Class Klass>
twisti@2047 852 // 33: ifeq 52
twisti@2047 853 // 36: aload 9
twisti@2047 854 // 38: checkcast <Class Klass>
twisti@2047 855 //
twisti@2047 856 // Handling both bytecodes at once allows us
twisti@2047 857 // to eliminate the checkcast.
twisti@2047 858 if (iter()->next_bci() < limit &&
twisti@2047 859 (iter()->next_bc() == Bytecodes::_ifeq ||
twisti@2047 860 iter()->next_bc() == Bytecodes::_ifne) &&
twisti@2047 861 (!UseLoopSafepoints ||
twisti@2047 862 iter()->next_get_dest() > iter()->next_bci())) {
twisti@2047 863 if (maybe_do_instanceof_if()) {
twisti@2047 864 iter()->next();
twisti@2047 865 if (SharkTraceBytecodes)
twisti@2047 866 tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc()));
twisti@2047 867 break;
twisti@2047 868 }
twisti@2047 869 }
twisti@2047 870 // fall through
twisti@2047 871 case Bytecodes::_checkcast:
twisti@2047 872 do_instance_check();
twisti@2047 873 break;
twisti@2047 874
twisti@2047 875 case Bytecodes::_new:
twisti@2047 876 do_new();
twisti@2047 877 break;
twisti@2047 878 case Bytecodes::_newarray:
twisti@2047 879 do_newarray();
twisti@2047 880 break;
twisti@2047 881 case Bytecodes::_anewarray:
twisti@2047 882 do_anewarray();
twisti@2047 883 break;
twisti@2047 884 case Bytecodes::_multianewarray:
twisti@2047 885 do_multianewarray();
twisti@2047 886 break;
twisti@2047 887
twisti@2047 888 case Bytecodes::_monitorenter:
twisti@2047 889 do_monitorenter();
twisti@2047 890 break;
twisti@2047 891 case Bytecodes::_monitorexit:
twisti@2047 892 do_monitorexit();
twisti@2047 893 break;
twisti@2047 894
twisti@2047 895 default:
twisti@2047 896 ShouldNotReachHere();
twisti@2047 897 }
twisti@2047 898 }
twisti@2047 899 }
twisti@2047 900
twisti@2047 901 SharkState* SharkBlock::initial_current_state() {
twisti@2047 902 return entry_state()->copy();
twisti@2047 903 }
twisti@2047 904
twisti@2047 905 int SharkBlock::switch_default_dest() {
twisti@2047 906 return iter()->get_dest_table(0);
twisti@2047 907 }
twisti@2047 908
twisti@2047 909 int SharkBlock::switch_table_length() {
twisti@2047 910 switch(bc()) {
twisti@2047 911 case Bytecodes::_tableswitch:
twisti@2047 912 return iter()->get_int_table(2) - iter()->get_int_table(1) + 1;
twisti@2047 913
twisti@2047 914 case Bytecodes::_lookupswitch:
twisti@2047 915 return iter()->get_int_table(1);
twisti@2047 916
twisti@2047 917 default:
twisti@2047 918 ShouldNotReachHere();
twisti@2047 919 }
twisti@2047 920 }
twisti@2047 921
twisti@2047 922 int SharkBlock::switch_key(int i) {
twisti@2047 923 switch(bc()) {
twisti@2047 924 case Bytecodes::_tableswitch:
twisti@2047 925 return iter()->get_int_table(1) + i;
twisti@2047 926
twisti@2047 927 case Bytecodes::_lookupswitch:
twisti@2047 928 return iter()->get_int_table(2 + 2 * i);
twisti@2047 929
twisti@2047 930 default:
twisti@2047 931 ShouldNotReachHere();
twisti@2047 932 }
twisti@2047 933 }
twisti@2047 934
twisti@2047 935 int SharkBlock::switch_dest(int i) {
twisti@2047 936 switch(bc()) {
twisti@2047 937 case Bytecodes::_tableswitch:
twisti@2047 938 return iter()->get_dest_table(i + 3);
twisti@2047 939
twisti@2047 940 case Bytecodes::_lookupswitch:
twisti@2047 941 return iter()->get_dest_table(2 + 2 * i + 1);
twisti@2047 942
twisti@2047 943 default:
twisti@2047 944 ShouldNotReachHere();
twisti@2047 945 }
twisti@2047 946 }
twisti@2047 947
twisti@2047 948 void SharkBlock::do_div_or_rem(bool is_long, bool is_rem) {
twisti@2047 949 SharkValue *sb = pop();
twisti@2047 950 SharkValue *sa = pop();
twisti@2047 951
twisti@2047 952 check_divide_by_zero(sb);
twisti@2047 953
twisti@2047 954 Value *a, *b, *p, *q;
twisti@2047 955 if (is_long) {
twisti@2047 956 a = sa->jlong_value();
twisti@2047 957 b = sb->jlong_value();
twisti@2047 958 p = LLVMValue::jlong_constant(0x8000000000000000LL);
twisti@2047 959 q = LLVMValue::jlong_constant(-1);
twisti@2047 960 }
twisti@2047 961 else {
twisti@2047 962 a = sa->jint_value();
twisti@2047 963 b = sb->jint_value();
twisti@2047 964 p = LLVMValue::jint_constant(0x80000000);
twisti@2047 965 q = LLVMValue::jint_constant(-1);
twisti@2047 966 }
twisti@2047 967
twisti@2047 968 BasicBlock *ip = builder()->GetBlockInsertionPoint();
twisti@2047 969 BasicBlock *special_case = builder()->CreateBlock(ip, "special_case");
twisti@2047 970 BasicBlock *general_case = builder()->CreateBlock(ip, "general_case");
twisti@2047 971 BasicBlock *done = builder()->CreateBlock(ip, "done");
twisti@2047 972
twisti@2047 973 builder()->CreateCondBr(
twisti@2047 974 builder()->CreateAnd(
twisti@2047 975 builder()->CreateICmpEQ(a, p),
twisti@2047 976 builder()->CreateICmpEQ(b, q)),
twisti@2047 977 special_case, general_case);
twisti@2047 978
twisti@2047 979 builder()->SetInsertPoint(special_case);
twisti@2047 980 Value *special_result;
twisti@2047 981 if (is_rem) {
twisti@2047 982 if (is_long)
twisti@2047 983 special_result = LLVMValue::jlong_constant(0);
twisti@2047 984 else
twisti@2047 985 special_result = LLVMValue::jint_constant(0);
twisti@2047 986 }
twisti@2047 987 else {
twisti@2047 988 special_result = a;
twisti@2047 989 }
twisti@2047 990 builder()->CreateBr(done);
twisti@2047 991
twisti@2047 992 builder()->SetInsertPoint(general_case);
twisti@2047 993 Value *general_result;
twisti@2047 994 if (is_rem)
twisti@2047 995 general_result = builder()->CreateSRem(a, b);
twisti@2047 996 else
twisti@2047 997 general_result = builder()->CreateSDiv(a, b);
twisti@2047 998 builder()->CreateBr(done);
twisti@2047 999
twisti@2047 1000 builder()->SetInsertPoint(done);
twisti@2047 1001 PHINode *result;
twisti@2047 1002 if (is_long)
twisti@2047 1003 result = builder()->CreatePHI(SharkType::jlong_type(), "result");
twisti@2047 1004 else
twisti@2047 1005 result = builder()->CreatePHI(SharkType::jint_type(), "result");
twisti@2047 1006 result->addIncoming(special_result, special_case);
twisti@2047 1007 result->addIncoming(general_result, general_case);
twisti@2047 1008
twisti@2047 1009 if (is_long)
twisti@2047 1010 push(SharkValue::create_jlong(result, false));
twisti@2047 1011 else
twisti@2047 1012 push(SharkValue::create_jint(result, false));
twisti@2047 1013 }
twisti@2047 1014
twisti@2047 1015 void SharkBlock::do_field_access(bool is_get, bool is_field) {
twisti@2047 1016 bool will_link;
twisti@2047 1017 ciField *field = iter()->get_field(will_link);
twisti@2047 1018 assert(will_link, "typeflow responsibility");
twisti@2047 1019 assert(is_field != field->is_static(), "mismatch");
twisti@2047 1020
twisti@2047 1021 // Pop the value off the stack where necessary
twisti@2047 1022 SharkValue *value = NULL;
twisti@2047 1023 if (!is_get)
twisti@2047 1024 value = pop();
twisti@2047 1025
twisti@2047 1026 // Find the object we're accessing, if necessary
twisti@2047 1027 Value *object = NULL;
twisti@2047 1028 if (is_field) {
twisti@2047 1029 SharkValue *value = pop();
twisti@2047 1030 check_null(value);
twisti@2047 1031 object = value->generic_value();
twisti@2047 1032 }
twisti@2047 1033 if (is_get && field->is_constant()) {
twisti@2047 1034 SharkConstant *constant = SharkConstant::for_field(iter());
twisti@2047 1035 if (constant->is_loaded())
twisti@2047 1036 value = constant->value(builder());
twisti@2047 1037 }
twisti@2047 1038 if (!is_get || value == NULL) {
twisti@2047 1039 if (!is_field)
twisti@2047 1040 object = builder()->CreateInlineOop(field->holder());
twisti@2047 1041
twisti@2047 1042 BasicType basic_type = field->type()->basic_type();
twisti@2047 1043 const Type *stack_type = SharkType::to_stackType(basic_type);
twisti@2047 1044 const Type *field_type = SharkType::to_arrayType(basic_type);
twisti@2047 1045
twisti@2047 1046 Value *addr = builder()->CreateAddressOfStructEntry(
twisti@2047 1047 object, in_ByteSize(field->offset_in_bytes()),
twisti@2047 1048 PointerType::getUnqual(field_type),
twisti@2047 1049 "addr");
twisti@2047 1050
twisti@2047 1051 // Do the access
twisti@2047 1052 if (is_get) {
twisti@2047 1053 Value *field_value = builder()->CreateLoad(addr);
twisti@2047 1054
twisti@2047 1055 if (field_type != stack_type) {
twisti@2047 1056 field_value = builder()->CreateIntCast(
twisti@2047 1057 field_value, stack_type, basic_type != T_CHAR);
twisti@2047 1058 }
twisti@2047 1059
twisti@2047 1060 value = SharkValue::create_generic(field->type(), field_value, false);
twisti@2047 1061 }
twisti@2047 1062 else {
twisti@2047 1063 Value *field_value = value->generic_value();
twisti@2047 1064
twisti@2047 1065 if (field_type != stack_type) {
twisti@2047 1066 field_value = builder()->CreateIntCast(
twisti@2047 1067 field_value, field_type, basic_type != T_CHAR);
twisti@2047 1068 }
twisti@2047 1069
twisti@2047 1070 builder()->CreateStore(field_value, addr);
twisti@2047 1071
twisti@2047 1072 if (!field->type()->is_primitive_type())
twisti@2047 1073 builder()->CreateUpdateBarrierSet(oopDesc::bs(), addr);
twisti@2047 1074
twisti@2047 1075 if (field->is_volatile())
twisti@2047 1076 builder()->CreateMemoryBarrier(SharkBuilder::BARRIER_STORELOAD);
twisti@2047 1077 }
twisti@2047 1078 }
twisti@2047 1079
twisti@2047 1080 // Push the value onto the stack where necessary
twisti@2047 1081 if (is_get)
twisti@2047 1082 push(value);
twisti@2047 1083 }
twisti@2047 1084
twisti@2047 1085 void SharkBlock::do_lcmp() {
twisti@2047 1086 Value *b = pop()->jlong_value();
twisti@2047 1087 Value *a = pop()->jlong_value();
twisti@2047 1088
twisti@2047 1089 BasicBlock *ip = builder()->GetBlockInsertionPoint();
twisti@2047 1090 BasicBlock *ne = builder()->CreateBlock(ip, "lcmp_ne");
twisti@2047 1091 BasicBlock *lt = builder()->CreateBlock(ip, "lcmp_lt");
twisti@2047 1092 BasicBlock *gt = builder()->CreateBlock(ip, "lcmp_gt");
twisti@2047 1093 BasicBlock *done = builder()->CreateBlock(ip, "done");
twisti@2047 1094
twisti@2047 1095 BasicBlock *eq = builder()->GetInsertBlock();
twisti@2047 1096 builder()->CreateCondBr(builder()->CreateICmpEQ(a, b), done, ne);
twisti@2047 1097
twisti@2047 1098 builder()->SetInsertPoint(ne);
twisti@2047 1099 builder()->CreateCondBr(builder()->CreateICmpSLT(a, b), lt, gt);
twisti@2047 1100
twisti@2047 1101 builder()->SetInsertPoint(lt);
twisti@2047 1102 builder()->CreateBr(done);
twisti@2047 1103
twisti@2047 1104 builder()->SetInsertPoint(gt);
twisti@2047 1105 builder()->CreateBr(done);
twisti@2047 1106
twisti@2047 1107 builder()->SetInsertPoint(done);
twisti@2047 1108 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), "result");
twisti@2047 1109 result->addIncoming(LLVMValue::jint_constant(-1), lt);
twisti@2047 1110 result->addIncoming(LLVMValue::jint_constant(0), eq);
twisti@2047 1111 result->addIncoming(LLVMValue::jint_constant(1), gt);
twisti@2047 1112
twisti@2047 1113 push(SharkValue::create_jint(result, false));
twisti@2047 1114 }
twisti@2047 1115
twisti@2047 1116 void SharkBlock::do_fcmp(bool is_double, bool unordered_is_greater) {
twisti@2047 1117 Value *a, *b;
twisti@2047 1118 if (is_double) {
twisti@2047 1119 b = pop()->jdouble_value();
twisti@2047 1120 a = pop()->jdouble_value();
twisti@2047 1121 }
twisti@2047 1122 else {
twisti@2047 1123 b = pop()->jfloat_value();
twisti@2047 1124 a = pop()->jfloat_value();
twisti@2047 1125 }
twisti@2047 1126
twisti@2047 1127 BasicBlock *ip = builder()->GetBlockInsertionPoint();
twisti@2047 1128 BasicBlock *ordered = builder()->CreateBlock(ip, "ordered");
twisti@2047 1129 BasicBlock *ge = builder()->CreateBlock(ip, "fcmp_ge");
twisti@2047 1130 BasicBlock *lt = builder()->CreateBlock(ip, "fcmp_lt");
twisti@2047 1131 BasicBlock *eq = builder()->CreateBlock(ip, "fcmp_eq");
twisti@2047 1132 BasicBlock *gt = builder()->CreateBlock(ip, "fcmp_gt");
twisti@2047 1133 BasicBlock *done = builder()->CreateBlock(ip, "done");
twisti@2047 1134
twisti@2047 1135 builder()->CreateCondBr(
twisti@2047 1136 builder()->CreateFCmpUNO(a, b),
twisti@2047 1137 unordered_is_greater ? gt : lt, ordered);
twisti@2047 1138
twisti@2047 1139 builder()->SetInsertPoint(ordered);
twisti@2047 1140 builder()->CreateCondBr(builder()->CreateFCmpULT(a, b), lt, ge);
twisti@2047 1141
twisti@2047 1142 builder()->SetInsertPoint(ge);
twisti@2047 1143 builder()->CreateCondBr(builder()->CreateFCmpUGT(a, b), gt, eq);
twisti@2047 1144
twisti@2047 1145 builder()->SetInsertPoint(lt);
twisti@2047 1146 builder()->CreateBr(done);
twisti@2047 1147
twisti@2047 1148 builder()->SetInsertPoint(gt);
twisti@2047 1149 builder()->CreateBr(done);
twisti@2047 1150
twisti@2047 1151 builder()->SetInsertPoint(eq);
twisti@2047 1152 builder()->CreateBr(done);
twisti@2047 1153
twisti@2047 1154 builder()->SetInsertPoint(done);
twisti@2047 1155 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), "result");
twisti@2047 1156 result->addIncoming(LLVMValue::jint_constant(-1), lt);
twisti@2047 1157 result->addIncoming(LLVMValue::jint_constant(0), eq);
twisti@2047 1158 result->addIncoming(LLVMValue::jint_constant(1), gt);
twisti@2047 1159
twisti@2047 1160 push(SharkValue::create_jint(result, false));
twisti@2047 1161 }
twisti@2047 1162
twisti@2047 1163 void SharkBlock::emit_IR() {
twisti@2047 1164 ShouldNotCallThis();
twisti@2047 1165 }
twisti@2047 1166
twisti@2047 1167 SharkState* SharkBlock::entry_state() {
twisti@2047 1168 ShouldNotCallThis();
twisti@2047 1169 }
twisti@2047 1170
twisti@2047 1171 void SharkBlock::do_zero_check(SharkValue* value) {
twisti@2047 1172 ShouldNotCallThis();
twisti@2047 1173 }
twisti@2047 1174
twisti@2047 1175 void SharkBlock::maybe_add_backedge_safepoint() {
twisti@2047 1176 ShouldNotCallThis();
twisti@2047 1177 }
twisti@2047 1178
twisti@2047 1179 bool SharkBlock::has_trap() {
twisti@2047 1180 return false;
twisti@2047 1181 }
twisti@2047 1182
twisti@2047 1183 int SharkBlock::trap_request() {
twisti@2047 1184 ShouldNotCallThis();
twisti@2047 1185 }
twisti@2047 1186
twisti@2047 1187 int SharkBlock::trap_bci() {
twisti@2047 1188 ShouldNotCallThis();
twisti@2047 1189 }
twisti@2047 1190
twisti@2047 1191 void SharkBlock::do_trap(int trap_request) {
twisti@2047 1192 ShouldNotCallThis();
twisti@2047 1193 }
twisti@2047 1194
twisti@2047 1195 void SharkBlock::do_arraylength() {
twisti@2047 1196 ShouldNotCallThis();
twisti@2047 1197 }
twisti@2047 1198
twisti@2047 1199 void SharkBlock::do_aload(BasicType basic_type) {
twisti@2047 1200 ShouldNotCallThis();
twisti@2047 1201 }
twisti@2047 1202
twisti@2047 1203 void SharkBlock::do_astore(BasicType basic_type) {
twisti@2047 1204 ShouldNotCallThis();
twisti@2047 1205 }
twisti@2047 1206
twisti@2047 1207 void SharkBlock::do_return(BasicType type) {
twisti@2047 1208 ShouldNotCallThis();
twisti@2047 1209 }
twisti@2047 1210
twisti@2047 1211 void SharkBlock::do_athrow() {
twisti@2047 1212 ShouldNotCallThis();
twisti@2047 1213 }
twisti@2047 1214
twisti@2047 1215 void SharkBlock::do_goto() {
twisti@2047 1216 ShouldNotCallThis();
twisti@2047 1217 }
twisti@2047 1218
twisti@2047 1219 void SharkBlock::do_jsr() {
twisti@2047 1220 ShouldNotCallThis();
twisti@2047 1221 }
twisti@2047 1222
twisti@2047 1223 void SharkBlock::do_ret() {
twisti@2047 1224 ShouldNotCallThis();
twisti@2047 1225 }
twisti@2047 1226
twisti@2047 1227 void SharkBlock::do_if(ICmpInst::Predicate p, SharkValue* b, SharkValue* a) {
twisti@2047 1228 ShouldNotCallThis();
twisti@2047 1229 }
twisti@2047 1230
twisti@2047 1231 void SharkBlock::do_switch() {
twisti@2047 1232 ShouldNotCallThis();
twisti@2047 1233 }
twisti@2047 1234
twisti@2047 1235 void SharkBlock::do_call() {
twisti@2047 1236 ShouldNotCallThis();
twisti@2047 1237 }
twisti@2047 1238
twisti@2047 1239 void SharkBlock::do_instance_check() {
twisti@2047 1240 ShouldNotCallThis();
twisti@2047 1241 }
twisti@2047 1242
twisti@2047 1243 bool SharkBlock::maybe_do_instanceof_if() {
twisti@2047 1244 ShouldNotCallThis();
twisti@2047 1245 }
twisti@2047 1246
twisti@2047 1247 void SharkBlock::do_new() {
twisti@2047 1248 ShouldNotCallThis();
twisti@2047 1249 }
twisti@2047 1250
twisti@2047 1251 void SharkBlock::do_newarray() {
twisti@2047 1252 ShouldNotCallThis();
twisti@2047 1253 }
twisti@2047 1254
twisti@2047 1255 void SharkBlock::do_anewarray() {
twisti@2047 1256 ShouldNotCallThis();
twisti@2047 1257 }
twisti@2047 1258
twisti@2047 1259 void SharkBlock::do_multianewarray() {
twisti@2047 1260 ShouldNotCallThis();
twisti@2047 1261 }
twisti@2047 1262
twisti@2047 1263 void SharkBlock::do_monitorenter() {
twisti@2047 1264 ShouldNotCallThis();
twisti@2047 1265 }
twisti@2047 1266
twisti@2047 1267 void SharkBlock::do_monitorexit() {
twisti@2047 1268 ShouldNotCallThis();
twisti@2047 1269 }

mercurial