--- old/src/hotspot/share/oops/array.hpp 2018-08-06 13:58:49.374951635 -0700 +++ new/src/hotspot/share/oops/array.hpp 2018-08-06 13:58:49.026938517 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -132,7 +132,7 @@ return (int)words; } - int size() { + int size() const { return size(_length); } @@ -153,6 +153,25 @@ } void print() { print(tty); } #endif // PRODUCT + + // Returns a "const" Array of S, where S is a supertype of T. + // + // Array* ta = ... ; + // Array* sa = ta->as_array_of(); + // Klass* k = sa->at(0); /// OK to read + // Klass* ak = k->array_klass(2); + // sa->at_put(0, ak); /// NOT OK to write into it, or else + // /// ta would contain something unexpected. + // + // If you get a C compilation error, DO NOT simply cast the 'const' away! + template const Array* as_const_array_of() { +#ifndef PRODUCT + T dummy = NULL; + S super_dummy = dummy; // must be down-castable + assert(sizeof(T) == sizeof(S), "must be"); +#endif + return static_cast*>((void*)this); + } };