hotspot/src/share/vm/classfile/compactHashtable.inline.hpp
author alanb
Thu, 17 Mar 2016 19:04:01 +0000
changeset 36508 5f9eee6b383b
parent 34659 3a7071043457
child 37995 92aec042a43b
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, harold.seigel@oracle.com, lois.foltan@oracle.com, calvin.cheung@oracle.com, christian.tornqvist@oracle.com, erik.joelsson@oracle.com, george.triantafillou@oracle.com, igor.ignatyev@oracle.com, ioi.lam@oracle.com, james.laskey@oracle.com, jean-francois.denise@oracle.com, jiangli.zhou@oracle.com, markus.gronlund@oracle.com, serguei.spitsyn@oracle.com, staffan.larsen@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34659
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     1
/*
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     4
 *
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     8
 *
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    13
 * accompanied this code).
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    14
 *
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    18
 *
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    21
 * questions.
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    22
 *
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    23
 */
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    24
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_COMPACTHASHTABLE_INLINE_HPP
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_COMPACTHASHTABLE_INLINE_HPP
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    27
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    28
#include "classfile/compactHashtable.hpp"
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    29
#include "memory/allocation.inline.hpp"
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    30
#include "oops/oop.inline.hpp"
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    31
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    32
template <class T, class N>
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    33
inline Symbol* CompactHashtable<T, N>::lookup_entry(CompactHashtable<Symbol*, char>* const t,
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    34
                                             juint* addr, const char* name, int len) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    35
  Symbol* sym = (Symbol*)((void*)(_base_address + *addr));
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    36
  if (sym->equals(name, len)) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    37
    assert(sym->refcount() == -1, "must be shared");
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    38
    return sym;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    39
  }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    40
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    41
  return NULL;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    42
}
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    43
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    44
template <class T, class N>
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    45
inline oop CompactHashtable<T, N>::lookup_entry(CompactHashtable<oop, char>* const t,
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    46
                                                juint* addr, const char* name, int len) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    47
  narrowOop obj = (narrowOop)(*addr);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    48
  oop string = oopDesc::decode_heap_oop(obj);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    49
  if (java_lang_String::equals(string, (jchar*)name, len)) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    50
    return string;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    51
  }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    52
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    53
  return NULL;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    54
}
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    55
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    56
template <class T, class N>
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    57
inline T CompactHashtable<T,N>::lookup(const N* name, unsigned int hash, int len) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    58
  if (_entry_count > 0) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    59
    assert(!DumpSharedSpaces, "run-time only");
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    60
    int index = hash % _bucket_count;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    61
    juint bucket_info = _buckets[index];
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    62
    juint bucket_offset = BUCKET_OFFSET(bucket_info);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    63
    int   bucket_type = BUCKET_TYPE(bucket_info);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    64
    juint* bucket = _buckets + bucket_offset;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    65
    juint* bucket_end = _buckets;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    66
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    67
    if (bucket_type == COMPACT_BUCKET_TYPE) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    68
      // the compact bucket has one entry with entry offset only
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    69
      T res = lookup_entry(this, &bucket[0], name, len);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    70
      if (res != NULL) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    71
        return res;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    72
      }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    73
    } else {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    74
      // This is a regular bucket, which has more than one
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    75
      // entries. Each entry is a pair of entry (hash, offset).
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    76
      // Seek until the end of the bucket.
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    77
      bucket_end += BUCKET_OFFSET(_buckets[index + 1]);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    78
      while (bucket < bucket_end) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    79
        unsigned int h = (unsigned int)(bucket[0]);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    80
        if (h == hash) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    81
          T res = lookup_entry(this, &bucket[1], name, len);
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    82
          if (res != NULL) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    83
            return res;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    84
          }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    85
        }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    86
        bucket += 2;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    87
      }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    88
    }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    89
  }
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    90
  return NULL;
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    91
}
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    92
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    93
inline void CompactHashtableWriter::add(unsigned int hash, Symbol* symbol) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    94
  add(hash, new Entry(hash, symbol));
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    95
}
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    96
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    97
inline void CompactHashtableWriter::add(unsigned int hash, oop string) {
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    98
  add(hash, new Entry(hash, string));
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
    99
}
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
   100
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
   101
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents:
diff changeset
   102
#endif // SHARE_VM_CLASSFILE_COMPACTHASHTABLE_INLINE_HPP