hotspot/src/share/vm/libadt/vectset.cpp
author coleenp
Mon, 14 Jan 2013 11:01:39 -0500
changeset 15194 a35093d73168
parent 13963 e5b53c306fb5
child 24425 53764d2358f9
permissions -rw-r--r--
8006005: Fix constant pool index validation and alignment trap for method parameter reflection Summary: This patch addresses an alignment trap due to the storage format of method parameters data in constMethod. It also adds code to validate constant pool indexes for method parameters data. Reviewed-by: jrose, dholmes Contributed-by: eric.mccorkle@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13195
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "libadt/vectset.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/allocation.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
// Vector Sets - An Abstract Data Type
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// %%%%% includes not needed with AVM framework - Ungar
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// #include "port.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//IMPLEMENTATION
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// #include "vectset.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// BitsInByte is a lookup table which tells the number of bits that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// are in the looked-up number.  It is very useful in VectorSet_Size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
uint8 bitsInByte[256] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//------------------------------VectorSet--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// Create a new, empty Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
VectorSet::VectorSet(Arena *arena) : Set(arena) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  size = 2;                     // Small initial size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  data = (uint32 *)_set_arena->Amalloc(size*sizeof(uint32));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  data[0] = 0;                  // No elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  data[1] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
//------------------------------Construct--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
Set &VectorSet_Construct(Arena *arena)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  return *(new VectorSet(arena));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
//------------------------------operator=--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
Set &VectorSet::operator = (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  if( &set == this ) return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  FREE_FAST(data);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  slamin(*(set.asVectorSet()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
//------------------------------slamin-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// Initialize one set with another.  No regard is made to the existing Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
void VectorSet::slamin(const VectorSet& s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  size = s.size;                // Use new size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  data = (uint32*)s._set_arena->Amalloc(size*sizeof(uint32)); // Make array of required size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  memcpy( data, s.data, size*sizeof(uint32) ); // Fill the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
//------------------------------grow-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// Expand the existing set to a bigger size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
void VectorSet::grow( uint newsize )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  newsize = (newsize+31) >> 5;  // Convert to longwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  uint x = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  while( x < newsize ) x <<= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  data = (uint32 *)_set_arena->Arealloc(data, size*sizeof(uint32), x*sizeof(uint32));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  memset((char *)(data + size), 0, (x - size)*sizeof(uint32));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  size = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
//------------------------------operator<<=------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
// Insert a member into an existing Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
Set &VectorSet::operator <<= (uint elem)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  register uint word = elem >> 5;            // Get the longword offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  register uint32 mask = 1L << (elem & 31);  // Get bit mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  if( word >= size )            // Need to grow set?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    grow(elem+1);               // Then grow it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  data[word] |= mask;           // Set new bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
//------------------------------operator>>=------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// Delete a member from an existing Set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
Set &VectorSet::operator >>= (uint elem)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  register uint word = elem >> 5; // Get the longword offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  if( word >= size )              // Beyond the last?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return *this;                 // Then it's clear & return clear
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  register uint32 mask = 1L << (elem & 31);     // Get bit mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  data[word] &= ~mask;            // Clear bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  return *this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
//------------------------------operator&=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// Intersect one set into another.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
VectorSet &VectorSet::operator &= (const VectorSet &s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // NOTE: The intersection is never any larger than the smallest set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  if( s.size < size ) size = s.size; // Get smaller size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  register uint32 *u1 = data;   // Pointer to the destination data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  register uint32 *u2 = s.data; // Pointer to the source data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  for( uint i=0; i<size; i++)   // For data in set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    *u1++ &= *u2++;             // Copy and AND longwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  return *this;                 // Return set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
//------------------------------operator&=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
Set &VectorSet::operator &= (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  return (*this) &= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
//------------------------------operator|=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
// Union one set into another.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
VectorSet &VectorSet::operator |= (const VectorSet &s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // This many words must be unioned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  register uint cnt = ((size<s.size)?size:s.size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  register uint32 *u1 = data;   // Pointer to the destination data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  register uint32 *u2 = s.data; // Pointer to the source data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  for( uint i=0; i<cnt; i++)    // Copy and OR the two sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    *u1++ |= *u2++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if( size < s.size ) {         // Is set 2 larger than set 1?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    // Extend result by larger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    grow(s.size*sizeof(uint32)*8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    memcpy(&data[cnt], u2, (s.size - cnt)*sizeof(uint32));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  return *this;                 // Return result set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
//------------------------------operator|=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
Set &VectorSet::operator |= (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  return (*this) |= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
//------------------------------operator-=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// Difference one set from another.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
VectorSet &VectorSet::operator -= (const VectorSet &s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // This many words must be unioned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  register uint cnt = ((size<s.size)?size:s.size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  register uint32 *u1 = data;   // Pointer to the destination data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  register uint32 *u2 = s.data; // Pointer to the source data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  for( uint i=0; i<cnt; i++ )   // For data in set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    *u1++ &= ~(*u2++);          // A <-- A & ~B  with longwords
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return *this;                 // Return new set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
//------------------------------operator-=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
Set &VectorSet::operator -= (const Set &set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  return (*this) -= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
//------------------------------compare----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// Compute 2 booleans: bits in A not B, bits in B not A.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
// Return X0 --  A is not a subset of B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
//        X1 --  A is a subset of B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
//        0X --  B is not a subset of A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
//        1X --  B is a subset of A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
int VectorSet::compare (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  register uint32 *u1 = data;   // Pointer to the destination data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  register uint32 *u2 = s.data; // Pointer to the source data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  register uint32 AnotB = 0, BnotA = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  // This many words must be unioned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  register uint cnt = ((size<s.size)?size:s.size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Get bits for both sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  uint i;                       // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  for( i=0; i<cnt; i++ ) {      // For data in BOTH sets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    register uint32 A = *u1++;  // Data from one guy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    register uint32 B = *u2++;  // Data from other guy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    AnotB |= (A & ~B);          // Compute bits in A not B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    BnotA |= (B & ~A);          // Compute bits in B not A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Get bits from bigger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  if( size < s.size ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    for( ; i<s.size; i++ )      // For data in larger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      BnotA |= *u2++;           // These bits are in B not A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    for( ; i<size; i++ )        // For data in larger set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      AnotB |= *u1++;           // These bits are in A not B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // Set & return boolean flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  return ((!BnotA)<<1) + (!AnotB);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
//------------------------------operator==-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
// Test for set equality
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
int VectorSet::operator == (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  return compare(s) == 3;       // TRUE if A and B are mutual subsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
//------------------------------operator==-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
int VectorSet::operator == (const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  return (*this) == *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
//------------------------------disjoint---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// Check for sets being disjoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
int VectorSet::disjoint(const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  const VectorSet &s = *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // NOTE: The intersection is never any larger than the smallest set.
7408
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   252
  register uint small_size = ((size<s.size)?size:s.size);
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   253
  register uint32 *u1 = data;        // Pointer to the destination data
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   254
  register uint32 *u2 = s.data;      // Pointer to the source data
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   255
  for( uint i=0; i<small_size; i++)  // For data in set
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   256
    if( *u1++ & *u2++ )              // If any elements in common
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   257
      return 0;                      // Then not disjoint
c04a5c989f26 7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents: 7397
diff changeset
   258
  return 1;                          // Else disjoint
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
//------------------------------operator<--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
// Test for strict subset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
int VectorSet::operator < (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  return compare(s) == 1;       // A subset B, B not subset A
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
//------------------------------operator<--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
int VectorSet::operator < (const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  return (*this) < *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
//------------------------------operator<=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
// Test for subset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
int VectorSet::operator <= (const VectorSet &s) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  return compare(s) & 1;        // A subset B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
//------------------------------operator<=-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
int VectorSet::operator <= (const Set &set) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // The cast is a virtual function that checks that "set" is a VectorSet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  return (*this) <= *(set.asVectorSet());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
//------------------------------operator[]-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
// Test for membership.  A Zero/Non-Zero value is returned!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
int VectorSet::operator[](uint elem) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  register uint word = elem >> 5; // Get the longword offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  if( word >= size )              // Beyond the last?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    return 0;                     // Then it's clear
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  register uint32 mask = 1L << (elem & 31);  // Get bit mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  return ((data[word] & mask))!=0;           // Return the sense of the bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
//------------------------------getelem----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
// Get any element from the set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
uint VectorSet::getelem(void) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  uint i;                       // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  for( i=0; i<size; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    if( data[i] )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  uint32 word = data[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  int j;                        // Exit value of loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  for( j= -1; word; j++, word>>=1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  return (i<<5)+j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
//------------------------------Clear------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
// Clear a set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
void VectorSet::Clear(void)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  if( size > 100 ) {            // Reclaim storage only if huge
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    FREE_RESOURCE_ARRAY(uint32,data,size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    size = 2;                   // Small initial size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    data = NEW_RESOURCE_ARRAY(uint32,size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  memset( data, 0, size*sizeof(uint32) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
//------------------------------Size-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
// Return number of elements in a Set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
uint VectorSet::Size(void) const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  uint sum = 0;                 // Cumulative size so far.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  uint8 *currByte = (uint8*)data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  for( uint32 i = 0; i < (size<<2); i++) // While have bytes to process
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    sum += bitsInByte[*currByte++];      // Add bits in current byte to size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  return sum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
//------------------------------Sort-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
// Sort the elements for the next forall statement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
void VectorSet::Sort(void)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
//------------------------------hash-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
int VectorSet::hash() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  uint32 _xor = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  uint lim = ((size<4)?size:4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  for( uint i = 0; i < lim; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    _xor ^= data[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  return (int)_xor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
10975
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   353
//------------------------------iterate----------------------------------------
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   354
// Used by Set::print().
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   355
class VSetI_ : public SetI_ {
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   356
  VectorSetI vsi;
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   357
public:
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   358
  VSetI_( const VectorSet *vset, uint &elem ) : vsi(vset) { elem = vsi.elem; }
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   359
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   360
  uint next(void) { ++vsi; return vsi.elem; }
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   361
  int  test(void) { return vsi.test(); }
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   362
};
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   363
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   364
SetI_ *VectorSet::iterate(uint &elem) const {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10975
diff changeset
   365
  return new(ResourceObj::C_HEAP, mtInternal) VSetI_(this, elem);
10975
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   366
}
446510be531a 7105611: Set::print() is broken
kvn
parents: 8319
diff changeset
   367
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
//------------------------------next-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
// Find and return the next element of a vector set, or return garbage and
8319
aedb3bd871bc 7013538: Java memory leak with escape analysis
kvn
parents: 7408
diff changeset
   371
// make "VectorSetI::test()" fail.
aedb3bd871bc 7013538: Java memory leak with escape analysis
kvn
parents: 7408
diff changeset
   372
uint VectorSetI::next(void)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  j++;                          // Next element in word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  mask = (mask & max_jint) << 1;// Next bit in word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  do {                          // Do While still have words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    while( mask ) {             // While have bits in word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      if( s->data[i] & mask ) { // If found a bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
        return (i<<5)+j;        // Return the bit address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      j++;                      // Skip to next bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      mask = (mask & max_jint) << 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    j = 0;                      // No more bits in word; setup for next word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    mask = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    for( i++; (i<s->size) && (!s->data[i]); i++ ); // Skip to non-zero word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  } while( i<s->size );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  return max_juint;             // No element, iterated them all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}