comparison src/share/vm/opto/regmask.cpp @ 8044:2c673161698a

8007402: Code cleanup to remove Parfait false positive Summary: add array access range check Reviewed-by: kvn
author drchase
date Sat, 09 Feb 2013 12:55:09 -0800
parents a7114d3d712e
children d2907f74462e
comparison
equal deleted inserted replaced
8043:309460dcedf7 8044:2c673161698a
1 /* 1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
239 if( (bit | (bit<<1)) != _A[i] ) 239 if( (bit | (bit<<1)) != _A[i] )
240 return false; // Require adjacent bit pair and no more bits 240 return false; // Require adjacent bit pair and no more bits
241 } else { // Else its a split-pair case 241 } else { // Else its a split-pair case
242 if( bit != _A[i] ) return false; // Found many bits, so fail 242 if( bit != _A[i] ) return false; // Found many bits, so fail
243 i++; // Skip iteration forward 243 i++; // Skip iteration forward
244 if( _A[i] != 1 ) return false; // Require 1 lo bit in next word 244 if( i >= RM_SIZE || _A[i] != 1 )
245 return false; // Require 1 lo bit in next word
245 } 246 }
246 } 247 }
247 } 248 }
248 // True for both the empty mask and for a bit pair 249 // True for both the empty mask and for a bit pair
249 return true; 250 return true;
252 static int low_bits[3] = { 0x55555555, 0x11111111, 0x01010101 }; 253 static int low_bits[3] = { 0x55555555, 0x11111111, 0x01010101 };
253 //------------------------------find_first_set--------------------------------- 254 //------------------------------find_first_set---------------------------------
254 // Find the lowest-numbered register set in the mask. Return the 255 // Find the lowest-numbered register set in the mask. Return the
255 // HIGHEST register number in the set, or BAD if no sets. 256 // HIGHEST register number in the set, or BAD if no sets.
256 // Works also for size 1. 257 // Works also for size 1.
257 OptoReg::Name RegMask::find_first_set(int size) const { 258 OptoReg::Name RegMask::find_first_set(const int size) const {
258 verify_sets(size); 259 verify_sets(size);
259 for (int i = 0; i < RM_SIZE; i++) { 260 for (int i = 0; i < RM_SIZE; i++) {
260 if (_A[i]) { // Found some bits 261 if (_A[i]) { // Found some bits
261 int bit = _A[i] & -_A[i]; // Extract low bit 262 int bit = _A[i] & -_A[i]; // Extract low bit
262 // Convert to bit number, return hi bit in pair 263 // Convert to bit number, return hi bit in pair
266 return OptoReg::Bad; 267 return OptoReg::Bad;
267 } 268 }
268 269
269 //------------------------------clear_to_sets---------------------------------- 270 //------------------------------clear_to_sets----------------------------------
270 // Clear out partial bits; leave only aligned adjacent bit pairs 271 // Clear out partial bits; leave only aligned adjacent bit pairs
271 void RegMask::clear_to_sets(int size) { 272 void RegMask::clear_to_sets(const int size) {
272 if (size == 1) return; 273 if (size == 1) return;
273 assert(2 <= size && size <= 8, "update low bits table"); 274 assert(2 <= size && size <= 8, "update low bits table");
274 assert(is_power_of_2(size), "sanity"); 275 assert(is_power_of_2(size), "sanity");
275 int low_bits_mask = low_bits[size>>2]; 276 int low_bits_mask = low_bits[size>>2];
276 for (int i = 0; i < RM_SIZE; i++) { 277 for (int i = 0; i < RM_SIZE; i++) {
291 verify_sets(size); 292 verify_sets(size);
292 } 293 }
293 294
294 //------------------------------smear_to_sets---------------------------------- 295 //------------------------------smear_to_sets----------------------------------
295 // Smear out partial bits to aligned adjacent bit sets 296 // Smear out partial bits to aligned adjacent bit sets
296 void RegMask::smear_to_sets(int size) { 297 void RegMask::smear_to_sets(const int size) {
297 if (size == 1) return; 298 if (size == 1) return;
298 assert(2 <= size && size <= 8, "update low bits table"); 299 assert(2 <= size && size <= 8, "update low bits table");
299 assert(is_power_of_2(size), "sanity"); 300 assert(is_power_of_2(size), "sanity");
300 int low_bits_mask = low_bits[size>>2]; 301 int low_bits_mask = low_bits[size>>2];
301 for (int i = 0; i < RM_SIZE; i++) { 302 for (int i = 0; i < RM_SIZE; i++) {
316 } 317 }
317 verify_sets(size); 318 verify_sets(size);
318 } 319 }
319 320
320 //------------------------------is_aligned_set-------------------------------- 321 //------------------------------is_aligned_set--------------------------------
321 bool RegMask::is_aligned_sets(int size) const { 322 bool RegMask::is_aligned_sets(const int size) const {
322 if (size == 1) return true; 323 if (size == 1) return true;
323 assert(2 <= size && size <= 8, "update low bits table"); 324 assert(2 <= size && size <= 8, "update low bits table");
324 assert(is_power_of_2(size), "sanity"); 325 assert(is_power_of_2(size), "sanity");
325 int low_bits_mask = low_bits[size>>2]; 326 int low_bits_mask = low_bits[size>>2];
326 // Assert that the register mask contains only bit sets. 327 // Assert that the register mask contains only bit sets.
342 } 343 }
343 344
344 //------------------------------is_bound_set----------------------------------- 345 //------------------------------is_bound_set-----------------------------------
345 // Return TRUE if the mask contains one adjacent set of bits and no other bits. 346 // Return TRUE if the mask contains one adjacent set of bits and no other bits.
346 // Works also for size 1. 347 // Works also for size 1.
347 int RegMask::is_bound_set(int size) const { 348 int RegMask::is_bound_set(const int size) const {
348 if( is_AllStack() ) return false; 349 if( is_AllStack() ) return false;
349 assert(1 <= size && size <= 8, "update low bits table"); 350 assert(1 <= size && size <= 8, "update low bits table");
350 int bit = -1; // Set to hold the one bit allowed 351 int bit = -1; // Set to hold the one bit allowed
351 for (int i = 0; i < RM_SIZE; i++) { 352 for (int i = 0; i < RM_SIZE; i++) {
352 if (_A[i] ) { // Found some bits 353 if (_A[i] ) { // Found some bits
353 if (bit != -1) 354 if (bit != -1)
354 return false; // Already had bits, so fail 355 return false; // Already had bits, so fail
355 bit = _A[i] & -_A[i]; // Extract 1 bit from mask 356 bit = _A[i] & -_A[i]; // Extract low bit from mask
356 int hi_bit = bit << (size-1); // high bit 357 int hi_bit = bit << (size-1); // high bit
357 if (hi_bit != 0) { // Bit set stays in same word? 358 if (hi_bit != 0) { // Bit set stays in same word?
358 int set = hi_bit + ((hi_bit-1) & ~(bit-1)); 359 int set = hi_bit + ((hi_bit-1) & ~(bit-1));
359 if (set != _A[i]) 360 if (set != _A[i])
360 return false; // Require adjacent bit set and no more bits 361 return false; // Require adjacent bit set and no more bits
361 } else { // Else its a split-set case 362 } else { // Else its a split-set case
362 if (((-1) & ~(bit-1)) != _A[i]) 363 if (((-1) & ~(bit-1)) != _A[i])
363 return false; // Found many bits, so fail 364 return false; // Found many bits, so fail
364 i++; // Skip iteration forward and check high part 365 i++; // Skip iteration forward and check high part
365 assert(size <= 8, "update next code");
366 // The lower 24 bits should be 0 since it is split case and size <= 8. 366 // The lower 24 bits should be 0 since it is split case and size <= 8.
367 int set = bit>>24; 367 int set = bit>>24;
368 set = set & -set; // Remove sign extension. 368 set = set & -set; // Remove sign extension.
369 set = (((set << size) - 1) >> 8); 369 set = (((set << size) - 1) >> 8);
370 if (_A[i] != set) return false; // Require 1 lo bit in next word 370 if (i >= RM_SIZE || _A[i] != set)
371 return false; // Require expected low bits in next word
371 } 372 }
372 } 373 }
373 } 374 }
374 // True for both the empty mask and for a bit set 375 // True for both the empty mask and for a bit set
375 return true; 376 return true;